I decided to try PyCharm again since I remember liking it when I used
it ~1 year ago. It seems that it has pretty good warnings for regular
expressions.
Patch 0001 changes simplifies '[A-Z][A-Z]*' to '[A-Z]+'. I'm not sure
if this was intentional to match gnulib-tool.sh better though:
's,lib_\([A-Z][A-Z]*\),'"${libname}_${libext}"'_\1,g' \
Patch 0002 removes some redundant backslashing. I am pretty sure most
of these were introduced by me. We don't need to backslash ']' when it
is the first character in the '[...]' set. And in the set the special
characters have their special meaning dropped, so there is no need to
backslash them.
Collin
From 5069a4633590a6f165c2ec650682c26d8db578b0 Mon Sep 17 00:00:00 2001
From: Collin Funk <collin.fu...@gmail.com>
Date: Thu, 11 Apr 2024 11:00:47 -0700
Subject: [PATCH 1/2] gnulib-tool.py: Simplify regular expressions.
* pygnulib/GLEmiter.py (GLEmiter.lib_Makefile_am)
(GLEmiter.tests_Makefile_am): Change occurrences of '[A-Z][A-Z]*' to
'[A-Z]+'.
---
ChangeLog | 7 +++++++
pygnulib/GLEmiter.py | 8 ++++----
2 files changed, 11 insertions(+), 4 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index eb3d8acd68..553533499b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2024-04-11 Collin Funk <collin.fu...@gmail.com>
+
+ gnulib-tool.py: Simplify regular expressions.
+ * pygnulib/GLEmiter.py (GLEmiter.lib_Makefile_am)
+ (GLEmiter.tests_Makefile_am): Change occurrences of '[A-Z][A-Z]*' to
+ '[A-Z]+'.
+
2024-04-11 Bruno Haible <br...@clisp.org>
users.txt: Correct some entries.
diff --git a/pygnulib/GLEmiter.py b/pygnulib/GLEmiter.py
index 6d82657e7c..ad164515dc 100644
--- a/pygnulib/GLEmiter.py
+++ b/pygnulib/GLEmiter.py
@@ -750,7 +750,7 @@ AC_DEFUN([%V1%_LIBSOURCES], [
# Replace NMD, so as to remove redundant "$(MKDIR_P) '.'" invocations.
# The logic is similar to how we define gl_source_base_prefix.
amsnippet1 = _eliminate_NMD(amsnippet1, automake_subdir)
- pattern = re.compile(r'lib_([A-Z][A-Z]*)', re.M)
+ pattern = re.compile(r'lib_([A-Z]+)', re.M)
amsnippet1 = pattern.sub(r'%s_%s_\1' % (libname, libext),
amsnippet1)
amsnippet1 = amsnippet1.replace('$(GNULIB_', '$(' + module_indicator_prefix + '_GNULIB_')
@@ -768,7 +768,7 @@ AC_DEFUN([%V1%_LIBSOURCES], [
# Get unconditional snippet, edit it and save to amsnippet2.
amsnippet2 = module.getAutomakeSnippet_Unconditional()
- pattern = re.compile(r'lib_([A-Z][A-Z]*)', re.M)
+ pattern = re.compile(r'lib_([A-Z]+)', re.M)
amsnippet2 = pattern.sub(r'%s_%s_\1' % (libname, libext),
amsnippet2)
amsnippet2 = amsnippet2.replace('$(GNULIB_',
@@ -1045,7 +1045,7 @@ AC_DEFUN([%V1%_LIBSOURCES], [
# Replace NMD, so as to remove redundant "$(MKDIR_P) '.'" invocations.
# The logic is similar to how we define gl_source_base_prefix.
amsnippet1 = _eliminate_NMD(amsnippet1, False)
- pattern = re.compile(r'lib_([A-Z][A-Z]*)', re.M)
+ pattern = re.compile(r'lib_([A-Z]+)', re.M)
amsnippet1 = pattern.sub(r'libtests_a_\1', amsnippet1)
amsnippet1 = amsnippet1.replace('$(GNULIB_', '$(' + module_indicator_prefix + '_GNULIB_')
amsnippet1 = amsnippet1.replace('lib%_LIBRARIES', 'lib_LIBRARIES')
@@ -1064,7 +1064,7 @@ AC_DEFUN([%V1%_LIBSOURCES], [
# Get unconditional snippet, edit it and save to amsnippet2.
amsnippet2 = module.getAutomakeSnippet_Unconditional()
- pattern = re.compile(r'lib_([A-Z][A-Z]*)', re.M)
+ pattern = re.compile(r'lib_([A-Z]+)', re.M)
amsnippet2 = pattern.sub(r'libtests_a_\1', amsnippet2)
amsnippet2 = amsnippet2.replace('$(GNULIB_',
'$(' + module_indicator_prefix + '_GNULIB_')
--
2.44.0
From e2a109bebfb8c292bebd70d5e0990200db1d329e Mon Sep 17 00:00:00 2001
From: Collin Funk <collin.fu...@gmail.com>
Date: Thu, 11 Apr 2024 11:27:34 -0700
Subject: [PATCH 2/2] gnulib-tool.py: Remove redundant backslashes from
regexps.
* pygnulib/GLTestDir.py (GLTestDir.execute): Don't backslash ']' when it
is outside of a set.
* pygnulib/GLImport.py (GLImport.__init__): Don't use a backslash when
']' is at the start of a '[...]' set. Don't backslash special characters
in a '[...]' set since they have their meaning dropped.
* pygnulib/main.py (main): Likewise.
---
ChangeLog | 10 ++++++++++
pygnulib/GLImport.py | 4 ++--
pygnulib/GLTestDir.py | 4 ++--
pygnulib/main.py | 4 ++--
4 files changed, 16 insertions(+), 6 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 553533499b..f416f5c8f1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2024-04-11 Collin Funk <collin.fu...@gmail.com>
+
+ gnulib-tool.py: Remove redundant backslashes from regexps.
+ * pygnulib/GLTestDir.py (GLTestDir.execute): Don't backslash ']' when it
+ is outside of a set.
+ * pygnulib/GLImport.py (GLImport.__init__): Don't use a backslash when
+ ']' is at the start of a '[...]' set. Don't backslash special characters
+ in a '[...]' set since they have their meaning dropped.
+ * pygnulib/main.py (main): Likewise.
+
2024-04-11 Collin Funk <collin.fu...@gmail.com>
gnulib-tool.py: Simplify regular expressions.
diff --git a/pygnulib/GLImport.py b/pygnulib/GLImport.py
index 46beb7e2a6..b200c7b250 100644
--- a/pygnulib/GLImport.py
+++ b/pygnulib/GLImport.py
@@ -93,7 +93,7 @@ class GLImport:
self.cache.setAuxDir('.')
with codecs.open(self.config.getAutoconfFile(), 'rb', 'UTF-8') as file:
data = file.read()
- pattern = re.compile(r'^AC_CONFIG_AUX_DIR\([\[ ]*([^\]"\$`\\\)]+).*?$', re.MULTILINE)
+ pattern = re.compile(r'^AC_CONFIG_AUX_DIR\([\[ ]*([^]"$`\\)]+).*?$', re.MULTILINE)
match = pattern.search(data)
if match:
self.cache.setAuxDir(match.group(1))
@@ -261,7 +261,7 @@ class GLImport:
if self.config['destdir']:
with open(self.config['configure_ac'], encoding='utf-8') as file:
data = file.read()
- pattern = re.compile(r'^.*AM_INIT_AUTOMAKE\([\[ ]*([^\]\)]*).*$', re.MULTILINE)
+ pattern = re.compile(r'^.*AM_INIT_AUTOMAKE\([\[ ]*([^])]*).*$', re.MULTILINE)
configure_ac_automake_options = pattern.findall(data)
if configure_ac_automake_options:
automake_options = { x
diff --git a/pygnulib/GLTestDir.py b/pygnulib/GLTestDir.py
index f6ab4f9d2e..5fd4197e52 100644
--- a/pygnulib/GLTestDir.py
+++ b/pygnulib/GLTestDir.py
@@ -463,7 +463,7 @@ class GLTestDir:
for line in snippet.split('\n')
if line.strip() ]
snippet = lines_to_multiline(lines)
- pattern = re.compile(r'AC_REQUIRE\(\[([^()]*)\]\)', re.M)
+ pattern = re.compile(r'AC_REQUIRE\(\[([^()]*)]\)', re.M)
snippet = pattern.sub(r'\1', snippet)
snippet = snippet.strip()
snippets.append(snippet)
@@ -577,7 +577,7 @@ class GLTestDir:
for line in snippet.split('\n')
if line.strip() ]
snippet = lines_to_multiline(lines)
- pattern = re.compile(r'AC_REQUIRE\(\[([^()]*)\]\)', re.M)
+ pattern = re.compile(r'AC_REQUIRE\(\[([^()]*)]\)', re.M)
snippet = pattern.sub(r'\1', snippet)
snippet = snippet.strip()
snippets.append(snippet)
diff --git a/pygnulib/main.py b/pygnulib/main.py
index f8d082705d..5fec0ccc4a 100644
--- a/pygnulib/main.py
+++ b/pygnulib/main.py
@@ -927,7 +927,7 @@ def main() -> None:
configure_ac_data = file.read()
guessed_m4dirs = []
- pattern = re.compile(r'^.*AC_CONFIG_MACRO_DIRS?\([\[ ]*([^\]"\$`\\\)]*).*$', re.MULTILINE)
+ pattern = re.compile(r'^.*AC_CONFIG_MACRO_DIRS?\([\[ ]*([^]"$`\\)]*).*$', re.MULTILINE)
match = pattern.findall(configure_ac_data)
# Append the match to guessed_m4dirs.
if match:
@@ -1015,7 +1015,7 @@ def main() -> None:
# No Makefile.am! Oh well. Look at the last generated aclocal.m4.
filepath = joinpath(destdir, 'aclocal.m4')
if isfile(filepath):
- pattern = re.compile(r'm4_include\(\[(.*?)\]\)')
+ pattern = re.compile(r'm4_include\(\[(.*?)]\)')
with codecs.open(filepath, 'rb', 'UTF-8') as file:
m4dirs = pattern.findall(file.read())
m4dirs = [ os.path.dirname(m4dir)
--
2.44.0