]> Savannah Git Hosting - gnulib.git/commitdiff
gnulib-tool.py: Make regex uses more straightforward.
authorBruno Haible <bruno@clisp.org>
Sun, 7 Aug 2022 11:29:59 +0000 (13:29 +0200)
committerBruno Haible <bruno@clisp.org>
Sun, 7 Aug 2022 21:04:07 +0000 (23:04 +0200)
* pygnulib/GLModuleSystem.py: Don't use flag re.S on regular expressions
that are meant to match a single line only, and remove the use of the
"minimal matching" *? construct whose only purpose was to neutralize the
re.S flag.
* pygnulib/GLEmiter.py: Likewise.
* pygnulib/GLImport.py: Likewise.
* pygnulib/GLTestDir.py: Likewise.

ChangeLog
pygnulib/GLEmiter.py
pygnulib/GLImport.py
pygnulib/GLModuleSystem.py
pygnulib/GLTestDir.py

index bcaedf98e402c52441e1d1576f8e2ba015044f7e..0e162e8d0a0d02cf4de433544d0a21a88b6fa1e5 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,14 @@
 2022-08-07  Bruno Haible  <bruno@clisp.org>
 
+       gnulib-tool.py: Make regex uses more straightforward.
+       * pygnulib/GLModuleSystem.py: Don't use flag re.S on regular expressions
+       that are meant to match a single line only, and remove the use of the
+       "minimal matching" *? construct whose only purpose was to neutralize the
+       re.S flag.
+       * pygnulib/GLEmiter.py: Likewise.
+       * pygnulib/GLImport.py: Likewise.
+       * pygnulib/GLTestDir.py: Likewise.
+
        gnulib-tool.py: Make regex uses more straightforward.
        * pygnulib/GLEmiter.py: Don't use flag re.S on regular expressions on
        regular expressions with no '.'.
index f85ef30d52442e3d5788e079a392795b937e652a..02fa6654e725e65e6fb91619f03cf045f05b0e3d 100644 (file)
@@ -153,7 +153,7 @@ class GLEmiter(object):
                       if line.strip() ]
             snippet = '%s\n' % '\n'.join(lines)
             transformer = fileassistant.transformers.get('aux', '')
-            pattern = re.compile('(^.*?$)', re.S | re.M)
+            pattern = re.compile('^(.*)$', re.M)
             snippet = pattern.sub('%s\\1' % indentation, snippet)
             if transformer:
                 args = ['sed', '-e', transformer]
@@ -182,9 +182,9 @@ class GLEmiter(object):
                 emit += 'changequote([, ])dnl\n'
                 emit += 'AC_SUBST([LTALLOCA])'
         if replace_auxdir:
-            regex = 'AC_CONFIG_FILES\\(\\[(.*?)\\:build-aux/(.*?)\\]\\)'
+            regex = 'AC_CONFIG_FILES\\(\\[(.*)\\:build-aux/(.*)\\]\\)'
             repl = 'AC_CONFIG_FILES([\\1:%s/\\2])' % auxdir
-            pattern = re.compile(regex, re.S | re.M)
+            pattern = re.compile(regex, re.M)
             emit = pattern.sub(repl, emit)
         lines = [ line
                   for line in emit.split('\n')
@@ -688,9 +688,9 @@ AC_DEFUN([%V1%_LIBSOURCES], [
                 amsnippet1 = amsnippet1.replace('lib_LIBRARIES', 'lib%_LIBRARIES')
                 amsnippet1 = amsnippet1.replace('lib_LTLIBRARIES', 'lib%_LTLIBRARIES')
                 if LD_flags:
-                    pattern = re.compile('lib_LDFLAGS[\t ]*\\+=(.*?)$', re.S | re.M)
+                    pattern = re.compile('lib_LDFLAGS[\t ]*\\+=(.*)$', re.M)
                     amsnippet1 = pattern.sub('', amsnippet1)
-                pattern = re.compile('lib_([A-Z][A-Z](?:.*?))', re.S | re.M)
+                pattern = re.compile('lib_([A-Z][A-Z](?:.*))', re.M)
                 amsnippet1 = pattern.sub('%s_%s_\\1' % (libname, libext),
                                          amsnippet1)
                 amsnippet1 = amsnippet1.replace('$(GNULIB_', '$(' + module_indicator_prefix + '_GNULIB_')
@@ -708,7 +708,7 @@ AC_DEFUN([%V1%_LIBSOURCES], [
 
                 # Get unconditional snippet, edit it and save to amsnippet2.
                 amsnippet2 = module.getAutomakeSnippet_Unconditional()
-                pattern = re.compile('lib_([A-Z][A-Z](?:.*?))', re.S | re.M)
+                pattern = re.compile('lib_([A-Z][A-Z](?:.*))', re.M)
                 amsnippet2 = pattern.sub('%s_%s_\\1' % (libname, libext),
                                          amsnippet2)
                 amsnippet2 = amsnippet2.replace('$(GNULIB_',
@@ -802,7 +802,7 @@ AC_DEFUN([%V1%_LIBSOURCES], [
         insnippets = False
         inmakefile = False
         regex = '^[a-zA-Z0-9_]*_%sLIBRARIES *\\+{0,1}= *%s.%s' % (perhapsLT, libname, libext)
-        pattern = re.compile(regex, re.S | re.M)
+        pattern = re.compile(regex, re.M)
         insnippets = bool(pattern.findall(allsnippets))
         # Then test if $sourcebase/Makefile.am (if it exists) specifies it.
         path = joinpath(sourcebase, 'Makefile.am')
@@ -955,9 +955,9 @@ AC_DEFUN([%V1%_LIBSOURCES], [
                 snippet = snippet.replace('lib_LIBRARIES', 'lib%_LIBRARIES')
                 snippet = snippet.replace('lib_LTLIBRARIES', 'lib%_LTLIBRARIES')
                 if LD_flags:
-                    pattern = re.compile('lib_LDFLAGS[\t ]*\\+=(.*?)$', re.S | re.M)
+                    pattern = re.compile('lib_LDFLAGS[\t ]*\\+=(.*)$', re.M)
                     snippet = pattern.sub('', snippet)
-                pattern = re.compile('lib_([A-Z][A-Z](?:.*?))', re.S | re.M)
+                pattern = re.compile('lib_([A-Z][A-Z](?:.*))', re.M)
                 snippet = pattern.sub('libtests_a_\\1', snippet)
                 snippet = snippet.replace('$(GNULIB_', '$(' + module_indicator_prefix + '_GNULIB_')
                 snippet = snippet.replace('lib%_LIBRARIES', 'lib_LIBRARIES')
index 7a6312ec399f7e6565a96446db182b123608e5a2..818f3d57c09ea38712ce04d2fb3d429c26ec685f 100644 (file)
@@ -95,7 +95,7 @@ class GLImport(object):
         self.config.setAutoconfFile(path)
         with codecs.open(path, 'rb', 'UTF-8') as file:
             data = file.read()
-        pattern = re.compile(r'^AC_CONFIG_AUX_DIR\((.*?)\)$', re.S | re.M)
+        pattern = re.compile(r'^AC_CONFIG_AUX_DIR\((.*)\)$', re.M)
         match = pattern.findall(data)
         if match:
             result = cleaner(match)[0]
@@ -106,7 +106,7 @@ class GLImport(object):
             self.config.setAuxDir(self.cache['auxdir'])
 
         # Guess autoconf version.
-        pattern = re.compile(r'.*AC_PREREQ\((.*?)\)', re.S | re.M)
+        pattern = re.compile(r'.*AC_PREREQ\((.*)\)', re.M)
         versions = cleaner(pattern.findall(data))
         if versions:
             version = sorted(set([ float(version)
index 6b8f20e54f230bc2c0271ca5a9af0043874d3a5c..afc7a472cf94d5f625ebd0387b28eff7ebe3a9c4 100644 (file)
@@ -705,7 +705,7 @@ Include:|Link:|License:|Maintainer:)'
                 # TODO: unconditional automake snippet for nontests modules
                 snippet = self.getAutomakeSnippet_Conditional()
                 snippet = constants.combine_lines(snippet)
-                pattern = re.compile('^lib_SOURCES[\t ]*\\+=[\t ]*(.*?)$', re.S | re.M)
+                pattern = re.compile('^lib_SOURCES[\t ]*\\+=[\t ]*(.*)$', re.M)
                 mentioned_files = pattern.findall(snippet)
                 if mentioned_files != list():
                     mentioned_files = mentioned_files[-1].split(' ')
@@ -780,7 +780,7 @@ Include:|Link:|License:|Maintainer:)'
                     parts += [line]
                 result = ''.join(parts)
             result = result.strip()
-            pattern = re.compile('^(["<].*?[>"])', re.S | re.M)
+            pattern = re.compile('^(["<].*[>"])', re.M)
             result = pattern.sub('#include \\1', result)
             self.cache['include'] = result
         return self.cache['include']
@@ -1164,7 +1164,7 @@ class GLModuleTable(object):
                 raise TypeError('each module must be a GLModule instance')
             snippet = module.getAutomakeSnippet()
             snippet = constants.remove_backslash_newline(snippet)
-            pattern = re.compile('^lib_SOURCES[\t ]*\\+=[\t ]*(.*?)$', re.S | re.M)
+            pattern = re.compile('^lib_SOURCES[\t ]*\\+=[\t ]*(.*)$', re.M)
             files = pattern.findall(snippet)
             if files:  # if source files were found
                 files = files[-1].split(' ')
index 757c4940113838b2dc5c9646b5f658531815bf87..f8d9910ab74951736e7130a1ba85c471f887a5b8 100644 (file)
@@ -299,7 +299,7 @@ class GLTestDir(object):
                 notice = module.getNotice()
                 if notice:
                     print('Notice from module %s:' % str(module))
-                    pattern = re.compile('^(.*?)$', re.S | re.M)
+                    pattern = re.compile('^(.*)$', re.M)
                     notice = pattern.sub('  \\1', notice)
                     print(notice)
         else:  # if not single_configure
@@ -307,7 +307,7 @@ class GLTestDir(object):
                 notice = module.getNotice()
                 if notice:
                     print('Notice from module %s:' % str(module))
-                    pattern = re.compile('^(.*?)$', re.S | re.M)
+                    pattern = re.compile('^(.*)$', re.M)
                     notice = pattern.sub('  \\1', notice)
                     print(notice)
 
@@ -461,7 +461,7 @@ class GLTestDir(object):
                                   for line in snippet.split('\n')
                                   if line.strip() ]
                         snippet = '\n'.join(lines)
-                        pattern = re.compile('AC_REQUIRE\\(\\[([^()].*?)\\]\\)', re.S | re.M)
+                        pattern = re.compile('AC_REQUIRE\\(\\[([^()].*)\\]\\)', re.M)
                         snippet = pattern.sub('\\1', snippet)
                         snippet = snippet.strip()
                         snippets += [snippet]
@@ -578,7 +578,7 @@ class GLTestDir(object):
                           for line in snippet.split('\n')
                           if line.strip() ]
                 snippet = '\n'.join(lines)
-                pattern = re.compile('AC_REQUIRE\\(\\[([^()].*?)\\]\\)', re.S | re.M)
+                pattern = re.compile('AC_REQUIRE\\(\\[([^()].*)\\]\\)', re.M)
                 snippet = pattern.sub('\\1', snippet)
                 snippet = snippet.strip()
                 snippets += [snippet]
@@ -749,9 +749,9 @@ class GLTestDir(object):
 
         # Extract the value of "CLEANFILES += ..." and "MOSTLYCLEANFILES += ...".
         regex_find = list()
-        pattern = re.compile('^CLEANFILES[\t ]*\\+=(.*?)$', re.S | re.M)
+        pattern = re.compile('^CLEANFILES[\t ]*\\+=(.*)$', re.M)
         regex_find += pattern.findall(snippet)
-        pattern = re.compile('^MOSTLYCLEANFILES[\t ]*\\+=(.*?)$', re.S | re.M)
+        pattern = re.compile('^MOSTLYCLEANFILES[\t ]*\\+=(.*)$', re.M)
         regex_find += pattern.findall(snippet)
         regex_find = [ line.strip()
                        for line in regex_find
@@ -765,7 +765,7 @@ class GLTestDir(object):
         # Extract the value of "BUILT_SOURCES += ...". Remove variable references
         # such $(FOO_H) because they don't refer to distributed files.
         regex_find = list()
-        pattern = re.compile('^BUILT_SOURCES[\t ]*\\+=(.*?)$', re.S | re.M)
+        pattern = re.compile('^BUILT_SOURCES[\t ]*\\+=(.*)$', re.M)
         regex_find += pattern.findall(snippet)
         regex_find = [ line.strip()
                        for line in regex_find
@@ -791,9 +791,9 @@ class GLTestDir(object):
 
             # Extract the value of "CLEANFILES += ..." and "MOSTLYCLEANFILES += ...".
             regex_find = list()
-            pattern = re.compile('^CLEANFILES[\t ]*\\+=(.*?)$', re.S | re.M)
+            pattern = re.compile('^CLEANFILES[\t ]*\\+=(.*)$', re.M)
             regex_find += pattern.findall(snippet)
-            pattern = re.compile('^MOSTLYCLEANFILES[\t ]*\\+=(.*?)$', re.S | re.M)
+            pattern = re.compile('^MOSTLYCLEANFILES[\t ]*\\+=(.*)$', re.M)
             regex_find += pattern.findall(snippet)
             regex_find = [ line.strip()
                            for line in regex_find
@@ -808,7 +808,7 @@ class GLTestDir(object):
             # such $(FOO_H) because they don't refer to distributed files.
             regex_find = list()
             tests_built_sources = list()
-            pattern = re.compile('^BUILT_SOURCES[\t ]*\\+=(.*?)$', re.S | re.M)
+            pattern = re.compile('^BUILT_SOURCES[\t ]*\\+=(.*)$', re.M)
             regex_find += pattern.findall(snippet)
             regex_find = [ line.strip()
                            for line in regex_find