Skip to content

Commit df31175

Browse files
bonziniJonathan Corbet
authored andcommitted
kernel-doc: make highlights more homogenous for the various backends
$type_struct_full and friends are only used by the restructuredText backend, because it needs to separate enum/struct/typedef/union from the name of the type. However, $type_struct is *also* used by the rST backend. This is confusing. This patch replaces $type_struct's use in the rST backend with a new $type_fallback; it modifies $type_struct so that it can be used in the rST backend; and creates regular expressions like $type_struct for enum/typedef/union, for use in all backends. Note that, compared to $type_*_full, in the new regexes $1 includes both the "kind" and the name (before, $1 was pretty much a constant). Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Acked-by: Jani Nikula <jani.nikula@intel.com> Signed-off-by: Jonathan Corbet <corbet@lwn.net>
1 parent 5267dd3 commit df31175

1 file changed

Lines changed: 50 additions & 18 deletions

File tree

scripts/kernel-doc

Lines changed: 50 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -214,15 +214,19 @@ my $type_constant = '\%([-_\w]+)';
214214
my $type_func = '(\w+)\(\)';
215215
my $type_param = '\@(\w+(\.\.\.)?)';
216216
my $type_fp_param = '\@(\w+)\(\)'; # Special RST handling for func ptr params
217-
my $type_struct = '\&((struct\s*)*[_\w]+)';
218-
my $type_struct_xml = '\\&amp;((struct\s*)*[_\w]+)';
219217
my $type_env = '(\$\w+)';
220-
my $type_enum_full = '\&(enum)\s*([_\w]+)';
221-
my $type_struct_full = '\&(struct)\s*([_\w]+)';
222-
my $type_typedef_full = '\&(typedef)\s*([_\w]+)';
223-
my $type_union_full = '\&(union)\s*([_\w]+)';
218+
my $type_enum = '\&(enum\s*([_\w]+))';
219+
my $type_struct = '\&(struct\s*([_\w]+))';
220+
my $type_typedef = '\&(typedef\s*([_\w]+))';
221+
my $type_union = '\&(union\s*([_\w]+))';
224222
my $type_member = '\&([_\w]+)(\.|->)([_\w]+)';
223+
my $type_fallback = '\&([_\w]+)';
224+
my $type_enum_xml = '\&amp;(enum\s*([_\w]+))';
225+
my $type_struct_xml = '\&amp;(struct\s*([_\w]+))';
226+
my $type_typedef_xml = '\&amp;(typedef\s*([_\w]+))';
227+
my $type_union_xml = '\&amp;(union\s*([_\w]+))';
225228
my $type_member_xml = '\&amp;([_\w]+)(\.|-\&gt;)([_\w]+)';
229+
my $type_fallback_xml = '\&amp([_\w]+)';
226230
my $type_member_func = $type_member . '\(\)';
227231

228232
# Output conversion substitutions.
@@ -232,10 +236,14 @@ my $type_member_func = $type_member . '\(\)';
232236
my @highlights_html = (
233237
[$type_constant, "<i>\$1</i>"],
234238
[$type_func, "<b>\$1</b>"],
239+
[$type_enum_xml, "<i>\$1</i>"],
235240
[$type_struct_xml, "<i>\$1</i>"],
241+
[$type_typedef_xml, "<i>\$1</i>"],
242+
[$type_union_xml, "<i>\$1</i>"],
236243
[$type_env, "<b><i>\$1</i></b>"],
237244
[$type_param, "<tt><b>\$1</b></tt>"],
238-
[$type_member_xml, "<tt><i>\$1</i>\$2\$3</tt>"]
245+
[$type_member_xml, "<tt><i>\$1</i>\$2\$3</tt>"],
246+
[$type_fallback_xml, "<i>\$1</i>"]
239247
);
240248
my $local_lt = "\\\\\\\\lt:";
241249
my $local_gt = "\\\\\\\\gt:";
@@ -245,53 +253,73 @@ my $blankline_html = $local_lt . "p" . $local_gt; # was "<p>"
245253
my @highlights_html5 = (
246254
[$type_constant, "<span class=\"const\">\$1</span>"],
247255
[$type_func, "<span class=\"func\">\$1</span>"],
256+
[$type_enum_xml, "<span class=\"enum\">\$1</span>"],
248257
[$type_struct_xml, "<span class=\"struct\">\$1</span>"],
258+
[$type_typedef_xml, "<span class=\"typedef\">\$1</span>"],
259+
[$type_union_xml, "<span class=\"union\">\$1</span>"],
249260
[$type_env, "<span class=\"env\">\$1</span>"],
250261
[$type_param, "<span class=\"param\">\$1</span>]"],
251-
[$type_member_xml, "<span class=\"literal\"><span class=\"struct\">\$1</span>\$2<span class=\"member\">\$3</span></span>"]
262+
[$type_member_xml, "<span class=\"literal\"><span class=\"struct\">\$1</span>\$2<span class=\"member\">\$3</span></span>"],
263+
[$type_fallback_xml, "<span class=\"struct\">\$1</span>"]
252264
);
253265
my $blankline_html5 = $local_lt . "br /" . $local_gt;
254266

255267
# XML, docbook format
256268
my @highlights_xml = (
257269
["([^=])\\\"([^\\\"<]+)\\\"", "\$1<quote>\$2</quote>"],
258270
[$type_constant, "<constant>\$1</constant>"],
271+
[$type_enum_xml, "<type>\$1</type>"],
259272
[$type_struct_xml, "<structname>\$1</structname>"],
273+
[$type_typedef_xml, "<type>\$1</type>"],
274+
[$type_union_xml, "<structname>\$1</structname>"],
260275
[$type_param, "<parameter>\$1</parameter>"],
261276
[$type_func, "<function>\$1</function>"],
262277
[$type_env, "<envar>\$1</envar>"],
263-
[$type_member_xml, "<literal><structname>\$1</structname>\$2<structfield>\$3</structfield></literal>"]
278+
[$type_member_xml, "<literal><structname>\$1</structname>\$2<structfield>\$3</structfield></literal>"],
279+
[$type_fallback_xml, "<structname>\$1</structname>"]
264280
);
265281
my $blankline_xml = $local_lt . "/para" . $local_gt . $local_lt . "para" . $local_gt . "\n";
266282

267283
# gnome, docbook format
268284
my @highlights_gnome = (
269285
[$type_constant, "<replaceable class=\"option\">\$1</replaceable>"],
270286
[$type_func, "<function>\$1</function>"],
287+
[$type_enum, "<type>\$1</type>"],
271288
[$type_struct, "<structname>\$1</structname>"],
289+
[$type_typedef, "<type>\$1</type>"],
290+
[$type_union, "<structname>\$1</structname>"],
272291
[$type_env, "<envar>\$1</envar>"],
273292
[$type_param, "<parameter>\$1</parameter>" ],
274-
[$type_member, "<literal><structname>\$1</structname>\$2<structfield>\$3</structfield></literal>"]
293+
[$type_member, "<literal><structname>\$1</structname>\$2<structfield>\$3</structfield></literal>"],
294+
[$type_fallback, "<structname>\$1</structname>"]
275295
);
276296
my $blankline_gnome = "</para><para>\n";
277297

278298
# these are pretty rough
279299
my @highlights_man = (
280300
[$type_constant, "\$1"],
281301
[$type_func, "\\\\fB\$1\\\\fP"],
302+
[$type_enum, "\\\\fI\$1\\\\fP"],
282303
[$type_struct, "\\\\fI\$1\\\\fP"],
304+
[$type_typedef, "\\\\fI\$1\\\\fP"],
305+
[$type_union, "\\\\fI\$1\\\\fP"],
283306
[$type_param, "\\\\fI\$1\\\\fP"],
284-
[$type_member, "\\\\fI\$1\$2\$3\\\\fP"]
307+
[$type_member, "\\\\fI\$1\$2\$3\\\\fP"],
308+
[$type_fallback, "\\\\fI\$1\\\\fP"]
285309
);
286310
my $blankline_man = "";
287311

288312
# text-mode
289313
my @highlights_text = (
290314
[$type_constant, "\$1"],
291315
[$type_func, "\$1"],
316+
[$type_enum, "\$1"],
292317
[$type_struct, "\$1"],
318+
[$type_typedef, "\$1"],
319+
[$type_union, "\$1"],
293320
[$type_param, "\$1"],
294-
[$type_member, "\$1\$2\$3"]
321+
[$type_member, "\$1\$2\$3"],
322+
[$type_fallback, "\$1"]
295323
);
296324
my $blankline_text = "";
297325

@@ -303,12 +331,12 @@ my @highlights_rst = (
303331
[$type_member, "\\:c\\:type\\:`\$1\$2\$3 <\$1>`"],
304332
[$type_fp_param, "**\$1\\\\(\\\\)**"],
305333
[$type_func, "\\:c\\:func\\:`\$1()`"],
306-
[$type_struct_full, "\\:c\\:type\\:`\$1 \$2 <\$2>`"],
307-
[$type_enum_full, "\\:c\\:type\\:`\$1 \$2 <\$2>`"],
308-
[$type_typedef_full, "\\:c\\:type\\:`\$1 \$2 <\$2>`"],
309-
[$type_union_full, "\\:c\\:type\\:`\$1 \$2 <\$2>`"],
334+
[$type_enum, "\\:c\\:type\\:`\$1 <\$2>`"],
335+
[$type_struct, "\\:c\\:type\\:`\$1 <\$2>`"],
336+
[$type_typedef, "\\:c\\:type\\:`\$1 <\$2>`"],
337+
[$type_union, "\\:c\\:type\\:`\$1 <\$2>`"],
310338
# in rst this can refer to any type
311-
[$type_struct, "\\:c\\:type\\:`\$1`"],
339+
[$type_fallback, "\\:c\\:type\\:`\$1`"],
312340
[$type_param, "**\$1**"]
313341
);
314342
my $blankline_rst = "\n";
@@ -317,9 +345,13 @@ my $blankline_rst = "\n";
317345
my @highlights_list = (
318346
[$type_constant, "\$1"],
319347
[$type_func, "\$1"],
348+
[$type_enum, "\$1"],
320349
[$type_struct, "\$1"],
350+
[$type_typedef, "\$1"],
351+
[$type_union, "\$1"],
321352
[$type_param, "\$1"],
322-
[$type_member, "\$1"]
353+
[$type_member, "\$1"],
354+
[$type_fallback, "\$1"]
323355
);
324356
my $blankline_list = "";
325357

0 commit comments

Comments
 (0)