Mercurial > public > mercurial-scm > hg-stable
diff contrib/check-code.py @ 10722:c4fb2103e734
check-code: improve quote detection regexp, add tests
author | Benoit Boissinot <benoit.boissinot@ens-lyon.org> |
---|---|
date | Wed, 17 Mar 2010 14:15:33 +0100 |
parents | fbcccf9ec58f |
children | 8ea152e94484 |
line wrap: on
line diff
--- a/contrib/check-code.py Wed Mar 17 10:55:28 2010 +0100 +++ b/contrib/check-code.py Wed Mar 17 14:15:33 2010 +0100 @@ -10,9 +10,9 @@ import sys, re, glob def repquote(m): - t = re.sub(r"\w", "x", m.group(2)) + t = re.sub(r"\w", "x", m.group('text')) t = re.sub(r"[^\sx]", "o", t) - return m.group(1) + t + m.group(1) + return m.group('quote') + t + m.group('quote') def repcomment(m): return m.group(1) + "#" * len(m.group(2)) @@ -96,10 +96,9 @@ ] pyfilters = [ - (r'''(?<!")(")(([^"\n]|\\")+)"(?!")''', repquote), - (r"""(?<!')(')(([^'\n]|\\')+)'(?!')""", repquote), - (r"""(''')(([^']|\\'|'{1,2}(?!'))*)'''""", repquote), - (r'''(""")(([^"]|\\"|"{1,2}(?!"))*)"""''', repquote), + (r"""(?msx)(?P<quote>('''|\"\"\"|(?<!')'(?!')|(?<!")"(?!"))) + (?P<text>(.*?)) + (?<!\\)(?P=quote)""", repquote), (r"( *)(#([^\n]*\S)?)", repcomment), ] @@ -123,7 +122,7 @@ cfilters = [ (r'(/\*)(((\*(?!/))|[^*])*)\*/', repccomment), - (r'''(?<!")(")(([^"]|\\")+"(?!"))''', repquote), + (r'''(?P<quote>(?<!")")(?P<text>([^"]|\\")+)"(?!")''', repquote), (r'''(#\s*include\s+<)([^>]+)>''', repinclude), (r'(\()([^)]+\))', repcallspaces), ]