Patchwork [3,of,6] check-config: use named groups in regexp

login
register
mail settings
Submitter Gregory Szorc
Date June 15, 2017, 6:18 p.m.
Message ID <5fc91a88bb357f8ab5a1.1497550693@ubuntu-vm-main>
Download mbox | patch
Permalink /patch/21396/
State Accepted
Headers show

Comments

Gregory Szorc - June 15, 2017, 6:18 p.m.
# HG changeset patch
# User Gregory Szorc <gregory.szorc@gmail.com>
# Date 1497548299 25200
#      Thu Jun 15 10:38:19 2017 -0700
# Node ID 5fc91a88bb357f8ab5a15f57f765156badb1c48f
# Parent  6db20292ccb7a2dd0408c472bf9bf2ed77bab610
check-config: use named groups in regexp

In preparation for making this regexp a bit more complicated.

Patch

diff --git a/contrib/check-config.py b/contrib/check-config.py
--- a/contrib/check-config.py
+++ b/contrib/check-config.py
@@ -16,12 +16,12 @@  documented = {}
 
 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 @@  def main(args):
             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):