Patchwork [2,of,6] check-config: use compiled regexp

login
register
mail settings
Submitter Gregory Szorc
Date June 15, 2017, 6:18 p.m.
Message ID <6db20292ccb7a2dd0408.1497550692@ubuntu-vm-main>
Download mbox | patch
Permalink /patch/21395/
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 1497548183 25200
#      Thu Jun 15 10:36:23 2017 -0700
# Node ID 6db20292ccb7a2dd0408c472bf9bf2ed77bab610
# Parent  e3ea064b4065c6b1a047b0ba88c61278e62a967b
check-config: use compiled regexp

And split the regexp across multiple lines to make it easier to read.

Patch

diff --git a/contrib/check-config.py b/contrib/check-config.py
--- a/contrib/check-config.py
+++ b/contrib/check-config.py
@@ -14,8 +14,16 @@  import sys
 foundopts = {}
 documented = {}
 
-configre = (r"""ui\.config(|int|bool|list)\(['"](\S+)['"],\s*"""
-            r"""['"](\S+)['"](,\s+(?:default=)?(\S+?))?\)""")
+configre = re.compile(r'''
+    # Function call
+    ui\.config(|int|bool|list)\(
+        # First argument.
+        ['"](\S+)['"],\s*
+        # Second argument
+        ['"](\S+)['"](,\s+
+        (?:default=)?(\S+?))?
+    \)''', re.VERBOSE | re.MULTILINE)
+
 configpartialre = (r"""ui\.config""")
 
 def main(args):
@@ -71,7 +79,7 @@  def main(args):
 
             # look for code-like bits
             line = carryover + l
-            m = re.search(configre, line, re.MULTILINE)
+            m = configre.search(line)
             if m:
                 ctype = m.group(1)
                 if not ctype: