Show More
@@ -7,8 +7,11 b' operators. Parenthesis can be used for g' | |||
|
7 | 7 | Identifiers such as branch names must be quoted with single or double |
|
8 | 8 | quotes if they contain characters outside of |
|
9 | 9 | ``[._a-zA-Z0-9\x80-\xff]`` or if they match one of the predefined |
|
10 | predicates. Special characters can be used in quoted identifiers by | |
|
11 | escaping them, e.g., ``\n`` is interpreted as a newline. | |
|
10 | predicates. | |
|
11 | ||
|
12 | Special characters can be used in quoted identifiers by escaping them, | |
|
13 | e.g., ``\n`` is interpreted as a newline. To prevent them from being | |
|
14 | interpreted, strings can be prefixed with ``r``, e.g. ``r'...'``. | |
|
12 | 15 | |
|
13 | 16 | There is a single prefix operator: |
|
14 | 17 | |
@@ -82,7 +85,8 b' The following predicates are supported:' | |||
|
82 | 85 | An alias for ``::.`` (ancestors of the working copy's first parent). |
|
83 | 86 | |
|
84 | 87 | ``grep(regex)`` |
|
85 | Like ``keyword(string)`` but accepts a regex. | |
|
88 | Like ``keyword(string)`` but accepts a regex. Use ``grep(r'...')`` | |
|
89 | to ensure special escape characters are handled correctly. | |
|
86 | 90 | |
|
87 | 91 | ``head()`` |
|
88 | 92 | Changeset is a head. |
@@ -48,7 +48,14 b' def tokenize(program):' | |||
|
48 | 48 | pos += 1 # skip ahead |
|
49 | 49 | elif c in "():,-|&+!": # handle simple operators |
|
50 | 50 | yield (c, None, pos) |
|
51 |
elif c in '"\'' |
|
|
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 | 59 | pos += 1 |
|
53 | 60 | s = pos |
|
54 | 61 | while pos < l: # find closing quote |
@@ -57,7 +64,7 b' def tokenize(program):' | |||
|
57 | 64 | pos += 2 |
|
58 | 65 | continue |
|
59 | 66 | if d == c: |
|
60 |
yield ('string', program[s:pos] |
|
|
67 | yield ('string', decode(program[s:pos]), s) | |
|
61 | 68 | break |
|
62 | 69 | pos += 1 |
|
63 | 70 | else: |
@@ -215,6 +215,14 b' quoting needed' | |||
|
215 | 215 | ('func', ('symbol', 'grep'), ('string', '(')) |
|
216 | 216 | hg: parse error: invalid match pattern: unbalanced parenthesis |
|
217 | 217 | [255] |
|
218 | $ try 'grep("\bissue\d+")' | |
|
219 | ('func', ('symbol', 'grep'), ('string', '\x08issue\\d+')) | |
|
220 | $ try 'grep(r"\bissue\d+")' | |
|
221 | ('func', ('symbol', 'grep'), ('string', '\\bissue\\d+')) | |
|
222 | 6 | |
|
223 | $ try 'grep(r"\")' | |
|
224 | hg: parse error at 7: unterminated string | |
|
225 | [255] | |
|
218 | 226 | $ log 'head()' |
|
219 | 227 | 0 |
|
220 | 228 | 1 |
General Comments 0
You need to be logged in to leave comments.
Login now