check-config: use named groups in regexp
authorGregory Szorc <gregory.szorc@gmail.com>
Thu, 15 Jun 2017 10:38:19 -0700
changeset 32848 485b8e87e244
parent 32847 e5a6a540ae63
child 32849 e9fc5550be46
check-config: use named groups in regexp In preparation for making this regexp a bit more complicated.
contrib/check-config.py
--- a/contrib/check-config.py	Thu Jun 15 10:36:23 2017 -0700
+++ b/contrib/check-config.py	Thu Jun 15 10:38:19 2017 -0700
@@ -16,12 +16,12 @@
 
 configre = re.compile(r'''
     # Function call
-    ui\.config(|int|bool|list)\(
+    ui\.config(?P<ctype>|int|bool|list)\(
         # First argument.
-        ['"](\S+)['"],\s*
+        ['"](?P<section>\S+)['"],\s*
         # Second argument
-        ['"](\S+)['"](,\s+
-        (?:default=)?(\S+?))?
+        ['"](?P<option>\S+)['"](,\s+
+        (?:default=)?(?P<default>\S+?))?
     \)''', re.VERBOSE | re.MULTILINE)
 
 configpartialre = (r"""ui\.config""")
@@ -81,11 +81,11 @@
             line = carryover + l
             m = configre.search(line)
             if m:
-                ctype = m.group(1)
+                ctype = m.group('ctype')
                 if not ctype:
                     ctype = 'str'
-                name = m.group(2) + "." + m.group(3)
-                default = m.group(5)
+                name = m.group('section') + "." + m.group('option')
+                default = m.group('default')
                 if default in (None, 'False', 'None', '0', '[]', '""', "''"):
                     default = ''
                 if re.match('[a-z.]+$', default):