public inbox for newlib@sourceware.org
 help / color / mirror / Atom feed
From: Jon Turney <jon.turney@dronecode.org.uk>
To: newlib@sourceware.org
Cc: Jon Turney <jon.turney@dronecode.org.uk>
Subject: [PATCH 1/5] makedocbook: Use raw strings for regexes
Date: Fri,  4 Nov 2022 13:49:42 +0000	[thread overview]
Message-ID: <20221104134946.13443-2-jon.turney@dronecode.org.uk> (raw)
In-Reply-To: <20221104134946.13443-1-jon.turney@dronecode.org.uk>

Use raw strings for regexes. This is best practice, and fixes a number
of "W605 invalid escape sequence" flakes.
---
 newlib/doc/makedocbook.py | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/newlib/doc/makedocbook.py b/newlib/doc/makedocbook.py
index 4e83ab63a..5e46082df 100755
--- a/newlib/doc/makedocbook.py
+++ b/newlib/doc/makedocbook.py
@@ -107,7 +107,7 @@ def remove_noncomments(src):
 
 # A command is a single word of at least 3 characters, all uppercase, and alone on a line
 def iscommand(l):
-    if re.match('^[A-Z_]{3,}\s*$', l):
+    if re.match(r'^[A-Z_]{3,}\s*$', l):
 
         return True
     return False
@@ -198,7 +198,7 @@ def function(c, l):
     descr = line_markup_convert(', '.join(descrlist))
 
     # fpclassify includes an 'and' we need to discard
-    namelist = map(lambda v: re.sub('^and ', '', v.strip(), 1), namelist)
+    namelist = map(lambda v: re.sub(r'^and ', r'', v.strip(), 1), namelist)
     # strip off << >> surrounding name
     namelist = map(lambda v: v.strip().lstrip('<').rstrip('>'), namelist)
     # instantiate list to make it subscriptable
@@ -297,11 +297,11 @@ def synopsis(c, t):
 
     s = ''
     for l in t.splitlines():
-        if re.match('\s*(#|\[|struct)', l):
+        if re.match(r'\s*(#|\[|struct)', l):
             # preprocessor # directives, structs, comments in square brackets
             funcsynopsisinfo = lxml.etree.SubElement(funcsynopsis, 'funcsynopsisinfo')
             funcsynopsisinfo.text = l.strip() + '\n'
-        elif re.match('[Ll]ink with', l):
+        elif re.match(r'[Ll]ink with', l):
             pass
         else:
             s = s + l
@@ -348,7 +348,7 @@ def synopsis_for_prototype(funcsynopsis, s):
                 void = lxml.etree.SubElement(funcprototype, 'void')
             else:
                 # Split parameters on ',' except if it is inside ()
-                for p in re.split(',(?![^()]*\))', match.group(3)):
+                for p in re.split(r',(?![^()]*\))', match.group(3)):
                     p = p.strip()
 
                     if verbose:
@@ -361,7 +361,7 @@ def synopsis_for_prototype(funcsynopsis, s):
                         parameter = lxml.etree.SubElement(paramdef, 'parameter')
 
                         # <[ ]> enclose the parameter name
-                        match2 = re.match('(.*)<\[(.*)\]>(.*)', p)
+                        match2 = re.match(r'(.*)<\[(.*)\]>(.*)', p)
 
                         if verbose:
                             print(match2.groups(), file=sys.stderr)
@@ -472,16 +472,16 @@ def line_markup_convert(p):
 
     # also convert some simple texinfo markup
     # convert @emph{foo} to <emphasis>foo</emphasis>
-    s = re.sub('@emph{(.*?)}', '<emphasis>\\1</emphasis>', s)
+    s = re.sub(r'@emph{(.*?)}', r'<emphasis>\1</emphasis>', s)
     # convert @strong{foo} to <emphasis role=strong>foo</emphasis>
-    s = re.sub('@strong{(.*?)}', '<emphasis role="strong">\\1</emphasis>', s)
+    s = re.sub(r'@strong{(.*?)}', r'<emphasis role="strong">\1</emphasis>', s)
     # convert @minus{} to U+2212 MINUS SIGN
     s = s.replace('@minus{}', '&#x2212;')
     # convert @dots{} to U+2026 HORIZONTAL ELLIPSIS
     s = s.replace('@dots{}', '&#x2026;')
 
     # convert xref and pxref
-    s = re.sub('@xref{(.*?)}', "See <xref linkend='\\1'/>", s)
+    s = re.sub(r'@xref{(.*?)}', r"See <xref linkend='\1'/>", s)
 
     # very hacky way of dealing with @* to force a newline
     s = s.replace('@*', '</para><para>')
@@ -562,7 +562,7 @@ def t_TABLEEND(t):
 
 def t_ITEM(t):
     r'o\s.*\n'
-    t.value = re.sub('o\s', '', lexer.lexmatch.group(0), 1)
+    t.value = re.sub(r'o\s', r'', lexer.lexmatch.group(0), 1)
     t.value = line_markup_convert(t.value)
     return t
 
@@ -828,7 +828,7 @@ def main(file):
     print(s)
 
     # warn about texinfo commands which didn't get processed
-    match = re.search('@[a-z*]+', s)
+    match = re.search(r'@[a-z*]+', s)
     if match:
         print('texinfo command %s remains in output' % match.group(), file=sys.stderr)
 
-- 
2.38.1


  reply	other threads:[~2022-11-04 13:50 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-04 13:49 [PATCH 0/5] makedocbook improvements (v2) Jon Turney
2022-11-04 13:49 ` Jon Turney [this message]
2022-11-04 13:49 ` [PATCH 2/5] makedocbook: Use sys.exit() Jon Turney
2022-11-04 14:52   ` Torbjorn SVENSSON
2022-11-05 14:28     ` Mike Frysinger
2022-11-04 13:49 ` [PATCH 3/5] makedocbook: Drop stray semicolons Jon Turney
2022-11-04 13:49 ` [PATCH 4/5] makedocbook: Adjust inline whitespace to fix flake8 warnings Jon Turney
2022-11-04 13:49 ` [PATCH 5/5] makedocbook: Fix false report of unhandled texinfo command Jon Turney
2022-11-05 14:28 ` [PATCH 0/5] makedocbook improvements (v2) Mike Frysinger
2022-11-07  8:48   ` Corinna Vinschen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221104134946.13443-2-jon.turney@dronecode.org.uk \
    --to=jon.turney@dronecode.org.uk \
    --cc=newlib@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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 read-only IMAP folder(s) and NNTP newsgroup(s).