##// END OF EJS Templates
revset: support raw string literals...
Brodie Rao -
r12408:78a97859 default
parent child Browse files
Show More
@@ -7,8 +7,11 b' operators. Parenthesis can be used for g'
7 Identifiers such as branch names must be quoted with single or double
7 Identifiers such as branch names must be quoted with single or double
8 quotes if they contain characters outside of
8 quotes if they contain characters outside of
9 ``[._a-zA-Z0-9\x80-\xff]`` or if they match one of the predefined
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
10 predicates.
11 escaping them, e.g., ``\n`` is interpreted as a newline.
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 There is a single prefix operator:
16 There is a single prefix operator:
14
17
@@ -82,7 +85,8 b' The following predicates are supported:'
82 An alias for ``::.`` (ancestors of the working copy's first parent).
85 An alias for ``::.`` (ancestors of the working copy's first parent).
83
86
84 ``grep(regex)``
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 ``head()``
91 ``head()``
88 Changeset is a head.
92 Changeset is a head.
@@ -48,7 +48,14 b' def tokenize(program):'
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
@@ -57,7 +64,7 b' def tokenize(program):'
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:
@@ -215,6 +215,14 b' quoting needed'
215 ('func', ('symbol', 'grep'), ('string', '('))
215 ('func', ('symbol', 'grep'), ('string', '('))
216 hg: parse error: invalid match pattern: unbalanced parenthesis
216 hg: parse error: invalid match pattern: unbalanced parenthesis
217 [255]
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 $ log 'head()'
226 $ log 'head()'
219 0
227 0
220 1
228 1
General Comments 0
You need to be logged in to leave comments. Login now