Revision 10348
Added by Aaron Marcuse-Kubitza over 11 years ago
bin/repl | ||
---|---|---|
14 | 14 |
import opts |
15 | 15 |
import strings |
16 | 16 |
|
17 |
quote_re = '[\'"`]' |
|
18 |
|
|
17 | 19 |
def unescape_html(str_): return HTMLParser.HTMLParser().unescape(str_) |
18 | 20 |
|
19 | 21 |
def repl_unescape_html(match): return unescape_html(match.group(0)) |
... | ... | |
41 | 43 |
for row in reader: |
42 | 44 |
in_, out = row[:2] |
43 | 45 |
if in_ != '': |
44 |
if text or re.match(r'^\w+$', in_): # match word |
|
45 |
in_ = (r'(?:^|(?<=[\s,"])|^:|(?<=[\s,"]):)'+re.escape(in_) |
|
46 |
+r'(?![a-zA-Z0-9])') |
|
46 |
is_word = re.match(r'^\w+$', in_) |
|
47 |
if text or is_word: # match as whole-word text (like SQL identifier) |
|
48 |
in_str_re = re.escape(in_) |
|
49 |
q = quote_re |
|
50 |
in_ = '(?<='+q+')'+in_str_re+'(?='+q+')' # require quotes |
|
51 |
if is_word: # also match without quotes |
|
52 |
in_word_re = '(?<!'+q+r')\b'+in_str_re+r'\b(?!'+q+')' |
|
53 |
# don't match as partial part of quoted string |
|
54 |
in_ = '(?:'+in_+'|'+in_word_re+')' |
|
47 | 55 |
repls.append((r'(?m)'+in_, out)) |
48 | 56 |
stream.close() |
49 | 57 |
def repl_all(str_): |
Also available in: Unified diff
bugfix: bin/repl: text mode: repurpose this to match SQL identifiers, for use by inputs/input.Makefile %/postprocess.sql. %/postprocess.sql is the only place currently using this mode, so this will not affect other scripts.