Mercurial > hg
comparison mercurial/revset.py @ 12408:78a97859b90d
revset: support raw string literals
This adds support for r'...' and r"..." as string literals. Strings
with the "r" prefix will not have their escape characters interpreted.
This is especially useful for grep(), where, with regular string
literals, \number is interpreted as an octal escape code, and \b is
interpreted as the backspace character (\x08).
author | Brodie Rao <brodie@bitheap.org> |
---|---|
date | Fri, 24 Sep 2010 15:36:53 -0500 |
parents | 4cdaf1adafc8 |
children | 64db820c66a2 |
comparison
equal
deleted
inserted
replaced
12407:5bfab61c2fee | 12408:78a97859b90d |
---|---|
46 elif c == '.' and program[pos:pos + 2] == '..': # look ahead carefully | 46 elif c == '.' and program[pos:pos + 2] == '..': # look ahead carefully |
47 yield ('..', None, pos) | 47 yield ('..', None, pos) |
48 pos += 1 # skip ahead | 48 pos += 1 # skip ahead |
49 elif c in "():,-|&+!": # handle simple operators | 49 elif c in "():,-|&+!": # handle simple operators |
50 yield (c, None, pos) | 50 yield (c, None, pos) |
51 elif c in '"\'': # handle quoted strings | 51 elif (c in '"\'' or c == 'r' and |
52 program[pos:pos + 2] in ("r'", 'r"')): # handle quoted strings | |
53 if c == 'r': | |
54 pos += 1 | |
55 c = program[pos] | |
56 decode = lambda x: x | |
57 else: | |
58 decode = lambda x: x.decode('string-escape') | |
52 pos += 1 | 59 pos += 1 |
53 s = pos | 60 s = pos |
54 while pos < l: # find closing quote | 61 while pos < l: # find closing quote |
55 d = program[pos] | 62 d = program[pos] |
56 if d == '\\': # skip over escaped characters | 63 if d == '\\': # skip over escaped characters |
57 pos += 2 | 64 pos += 2 |
58 continue | 65 continue |
59 if d == c: | 66 if d == c: |
60 yield ('string', program[s:pos].decode('string-escape'), s) | 67 yield ('string', decode(program[s:pos]), s) |
61 break | 68 break |
62 pos += 1 | 69 pos += 1 |
63 else: | 70 else: |
64 raise error.ParseError(_("unterminated string"), s) | 71 raise error.ParseError(_("unterminated string"), s) |
65 elif c.isalnum() or c in '._' or ord(c) > 127: # gather up a symbol/keyword | 72 elif c.isalnum() or c in '._' or ord(c) > 127: # gather up a symbol/keyword |