Mercurial > hg
changeset 19310:30ea54660d14
check-code: introduce function for using re2 when available
Do it similar as in mercurial.util. For simplicity only support flag
multiline which is the only one used.
author | Simon Heimberg <simohe@besonet.ch> |
---|---|
date | Sat, 08 Jun 2013 20:20:14 +0200 |
parents | 7d77fa1cd537 |
children | ad16e5c7a429 |
files | contrib/check-code.py |
diffstat | 1 files changed, 14 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/contrib/check-code.py Sat Jun 08 20:20:14 2013 +0200 +++ b/contrib/check-code.py Sat Jun 08 20:20:14 2013 +0200 @@ -10,6 +10,20 @@ import re, glob, os, sys import keyword import optparse +try: + import re2 +except ImportError: + re2 = None + +def compilere(pat, multiline=False): + if multiline: + pat = '(?m)' + pat + if re2: + try: + return re2.compile(pat) + except re2.error: + pass + return re.compile(pat) def repquote(m): t = re.sub(r"\w", "x", m.group('text'))