linux-doc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] kernel-doc: Let backtick and backslash escape percent sign
@ 2019-04-05 21:18 Sean Christopherson
  2019-04-05 23:10 ` Matthew Wilcox
  2019-04-08 22:03 ` Jonathan Corbet
  0 siblings, 2 replies; 5+ messages in thread
From: Sean Christopherson @ 2019-04-05 21:18 UTC (permalink / raw)
  To: Jonathan Corbet; +Cc: linux-doc, linux-kernel

There are a handful of instances where kernel doc comments want an
actual '%' in the final output, e.g. vsnprintf() wants to display "%n"
and "%p" to document format specifiers, and assembly functions that use
a custom call ABI may want to document their register usage, e.g. %eax.

Because kernel-doc unconditionally interprets '%' followed by a word
character as a constant definition, i.e. %CONST, it's impossible to get
an actual '%\w' when kernel-doc is used to translate comments into rst
format.  Treat backtick and backlash as escaping '%', the former to
handle '%' in a ``LITERAL``, and the latter to allow '%' when using
standard formatting.

An alternative option would be to define a fancier set of rules for
interpreting '%' so that explicit escaping would not be required.  For
example, require "%CONST" to be preceded by a recognized set of
characters, e.g. whitespace, opening parenthesis, etc...  But the list
of recognized characters is quite large even in the current code base,
and using '\' to escape is more common and intuitive, i.e. most people
will naturally try doing "\%..." to get the desired formatting, whereas
losing %CONST formatting because of an unrecognized character is likely
to cause confusion.

Except for the aforementioned vsnprintf(), all .html output files from
`make htmldocs` are identical before and after this change.

Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
---
 scripts/kernel-doc | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/scripts/kernel-doc b/scripts/kernel-doc
index 3350e498b4ce..1890deb16725 100755
--- a/scripts/kernel-doc
+++ b/scripts/kernel-doc
@@ -210,7 +210,7 @@ my $anon_struct_union = 0;
 
 # match expressions used to find embedded type information
 my $type_constant = '\b``([^\`]+)``\b';
-my $type_constant2 = '\%([-_\w]+)';
+my $type_constant2 = '(^|[^\`\\\])\%([-_\w]+)';
 my $type_func = '(\w+)\(\)';
 my $type_param = '\@(\w*((\.\w+)|(->\w+))*(\.\.\.)?)';
 my $type_fp_param = '\@(\w+)\(\)';  # Special RST handling for func ptr params
@@ -229,7 +229,7 @@ my $type_member_func = $type_member . '\(\)';
 # these are pretty rough
 my @highlights_man = (
                       [$type_constant, "\$1"],
-                      [$type_constant2, "\$1"],
+                      [$type_constant2, "\$1\$2"],
                       [$type_func, "\\\\fB\$1\\\\fP"],
                       [$type_enum, "\\\\fI\$1\\\\fP"],
                       [$type_struct, "\\\\fI\$1\\\\fP"],
@@ -244,7 +244,7 @@ my $blankline_man = "";
 # rst-mode
 my @highlights_rst = (
                        [$type_constant, "``\$1``"],
-                       [$type_constant2, "``\$1``"],
+                       [$type_constant2, "\$1``\$2``"],
                        # Note: need to escape () to avoid func matching later
                        [$type_member_func, "\\:c\\:type\\:`\$1\$2\$3\\\\(\\\\) <\$1>`"],
                        [$type_member, "\\:c\\:type\\:`\$1\$2\$3 <\$1>`"],
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2019-04-09 14:39 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-04-05 21:18 [PATCH] kernel-doc: Let backtick and backslash escape percent sign Sean Christopherson
2019-04-05 23:10 ` Matthew Wilcox
2019-04-08  9:58   ` Jani Nikula
2019-04-08 22:03 ` Jonathan Corbet
2019-04-09 14:39   ` Sean Christopherson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).