##// END OF EJS Templates
revset: factor out common parsing function
Yuya Nishihara -
r29073:81bac118 default
parent child Browse files
Show More
@@ -2217,25 +2217,35 def optimize(x, small):
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 _parsewith(spec, lookup=None, syminitletters=None):
2221 """Generate a parse tree of given spec with given tokenizing options
2222
2223 >>> _parsewith('foo($1)', syminitletters=_aliassyminitletters)
2224 ('func', ('symbol', 'foo'), ('symbol', '$1'))
2225 >>> _parsewith('$1')
2226 Traceback (most recent call last):
2227 ...
2228 ParseError: ("syntax error in revset '$1'", 0)
2229 >>> _parsewith('foo bar')
2230 Traceback (most recent call last):
2231 ...
2232 ParseError: ('invalid token', 4)
2233 """
2234 p = parser.parser(elements)
2235 tree, pos = p.parse(tokenize(spec, lookup=lookup,
2236 syminitletters=syminitletters))
2237 if pos != len(spec):
2238 raise error.ParseError(_('invalid token'), pos)
2239 return parser.simplifyinfixops(tree, ('list', 'or'))
2240
2220 def _parsealias(spec):
2241 def _parsealias(spec):
2221 """Parse alias declaration/definition ``spec``
2242 """Parse alias declaration/definition ``spec``
2222
2243
2223 This allows symbol names to use also ``$`` as an initial letter
2244 This allows symbol names to use also ``$`` as an initial letter
2224 (for backward compatibility), and callers of this function should
2245 (for backward compatibility), and callers of this function should
2225 examine whether ``$`` is used also for unexpected symbols or not.
2246 examine whether ``$`` is used also for unexpected symbols or not.
2226
2227 >>> _parsealias('foo($1)')
2228 ('func', ('symbol', 'foo'), ('symbol', '$1'))
2229 >>> _parsealias('foo bar')
2230 Traceback (most recent call last):
2231 ...
2232 ParseError: ('invalid token', 4)
2233 """
2247 """
2234 p = parser.parser(elements)
2248 return _parsewith(spec, syminitletters=_aliassyminitletters)
2235 tree, pos = p.parse(tokenize(spec, syminitletters=_aliassyminitletters))
2236 if pos != len(spec):
2237 raise error.ParseError(_('invalid token'), pos)
2238 return parser.simplifyinfixops(tree, ('list', 'or'))
2239
2249
2240 class _aliasrules(parser.basealiasrules):
2250 class _aliasrules(parser.basealiasrules):
2241 """Parsing and expansion rule set of revset aliases"""
2251 """Parsing and expansion rule set of revset aliases"""
@@ -2280,11 +2290,7 def foldconcat(tree):
2280 return tuple(foldconcat(t) for t in tree)
2290 return tuple(foldconcat(t) for t in tree)
2281
2291
2282 def parse(spec, lookup=None):
2292 def parse(spec, lookup=None):
2283 p = parser.parser(elements)
2293 return _parsewith(spec, lookup=lookup)
2284 tree, pos = p.parse(tokenize(spec, lookup=lookup))
2285 if pos != len(spec):
2286 raise error.ParseError(_("invalid token"), pos)
2287 return parser.simplifyinfixops(tree, ('list', 'or'))
2288
2294
2289 def posttreebuilthook(tree, repo):
2295 def posttreebuilthook(tree, repo):
2290 # hook for extensions to execute code on the optimized tree
2296 # hook for extensions to execute code on the optimized tree
General Comments 0
You need to be logged in to leave comments. Login now