Mercurial > hg
comparison mercurial/revset.py @ 29072:f86fa7168059
revset: inline _tokenizealias() into _parsealias()
This helps factoring out common part between _parsealias() and parse().
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sun, 17 Apr 2016 12:57:27 +0900 |
parents | ea794f2eb19d |
children | 81bac118f9e2 |
comparison
equal
deleted
inserted
replaced
29071:2f58975eb2cb | 29072:f86fa7168059 |
---|---|
2215 # the set of valid characters for the initial letter of symbols in | 2215 # the set of valid characters for the initial letter of symbols in |
2216 # alias declarations and definitions | 2216 # alias declarations and definitions |
2217 _aliassyminitletters = set(c for c in [chr(i) for i in xrange(256)] | 2217 _aliassyminitletters = set(c for c in [chr(i) for i in xrange(256)] |
2218 if c.isalnum() or c in '._@$' or ord(c) > 127) | 2218 if c.isalnum() or c in '._@$' or ord(c) > 127) |
2219 | 2219 |
2220 def _tokenizealias(program, lookup=None): | 2220 def _parsealias(spec): |
2221 """Parse alias declaration/definition into a stream of tokens | 2221 """Parse alias declaration/definition ``spec`` |
2222 | 2222 |
2223 This allows symbol names to use also ``$`` as an initial letter | 2223 This allows symbol names to use also ``$`` as an initial letter |
2224 (for backward compatibility), and callers of this function should | 2224 (for backward compatibility), and callers of this function should |
2225 examine whether ``$`` is used also for unexpected symbols or not. | 2225 examine whether ``$`` is used also for unexpected symbols or not. |
2226 """ | |
2227 return tokenize(program, lookup=lookup, | |
2228 syminitletters=_aliassyminitletters) | |
2229 | |
2230 def _parsealias(spec): | |
2231 """Parse alias declaration/definition ``spec`` | |
2232 | 2226 |
2233 >>> _parsealias('foo($1)') | 2227 >>> _parsealias('foo($1)') |
2234 ('func', ('symbol', 'foo'), ('symbol', '$1')) | 2228 ('func', ('symbol', 'foo'), ('symbol', '$1')) |
2235 >>> _parsealias('foo bar') | 2229 >>> _parsealias('foo bar') |
2236 Traceback (most recent call last): | 2230 Traceback (most recent call last): |
2237 ... | 2231 ... |
2238 ParseError: ('invalid token', 4) | 2232 ParseError: ('invalid token', 4) |
2239 """ | 2233 """ |
2240 p = parser.parser(elements) | 2234 p = parser.parser(elements) |
2241 tree, pos = p.parse(_tokenizealias(spec)) | 2235 tree, pos = p.parse(tokenize(spec, syminitletters=_aliassyminitletters)) |
2242 if pos != len(spec): | 2236 if pos != len(spec): |
2243 raise error.ParseError(_('invalid token'), pos) | 2237 raise error.ParseError(_('invalid token'), pos) |
2244 return parser.simplifyinfixops(tree, ('list', 'or')) | 2238 return parser.simplifyinfixops(tree, ('list', 'or')) |
2245 | 2239 |
2246 class _aliasrules(parser.basealiasrules): | 2240 class _aliasrules(parser.basealiasrules): |