Mercurial > hg
comparison contrib/check-config.py @ 32847:e5a6a540ae63
check-config: use compiled regexp
And split the regexp across multiple lines to make it easier to read.
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Thu, 15 Jun 2017 10:36:23 -0700 |
parents | a92ee4d8a574 |
children | 485b8e87e244 |
comparison
equal
deleted
inserted
replaced
32846:7c11869cf23a | 32847:e5a6a540ae63 |
---|---|
12 import sys | 12 import sys |
13 | 13 |
14 foundopts = {} | 14 foundopts = {} |
15 documented = {} | 15 documented = {} |
16 | 16 |
17 configre = (r"""ui\.config(|int|bool|list)\(['"](\S+)['"],\s*""" | 17 configre = re.compile(r''' |
18 r"""['"](\S+)['"](,\s+(?:default=)?(\S+?))?\)""") | 18 # Function call |
19 ui\.config(|int|bool|list)\( | |
20 # First argument. | |
21 ['"](\S+)['"],\s* | |
22 # Second argument | |
23 ['"](\S+)['"](,\s+ | |
24 (?:default=)?(\S+?))? | |
25 \)''', re.VERBOSE | re.MULTILINE) | |
26 | |
19 configpartialre = (r"""ui\.config""") | 27 configpartialre = (r"""ui\.config""") |
20 | 28 |
21 def main(args): | 29 def main(args): |
22 for f in args: | 30 for f in args: |
23 sect = '' | 31 sect = '' |
69 if m: | 77 if m: |
70 documented[m.group(1)] = 1 | 78 documented[m.group(1)] = 1 |
71 | 79 |
72 # look for code-like bits | 80 # look for code-like bits |
73 line = carryover + l | 81 line = carryover + l |
74 m = re.search(configre, line, re.MULTILINE) | 82 m = configre.search(line) |
75 if m: | 83 if m: |
76 ctype = m.group(1) | 84 ctype = m.group(1) |
77 if not ctype: | 85 if not ctype: |
78 ctype = 'str' | 86 ctype = 'str' |
79 name = m.group(2) + "." + m.group(3) | 87 name = m.group(2) + "." + m.group(3) |