revset: pass a lookup function to the tokenizer
authorMatt Mackall <mpm@selenic.com>
Tue, 18 Mar 2014 17:19:44 -0500
changeset 20779 ffc2295c6b80
parent 20778 7c4778bc29f0
child 20780 403f1f73d30f
revset: pass a lookup function to the tokenizer
mercurial/revset.py
--- a/mercurial/revset.py	Tue Mar 18 17:17:23 2014 -0500
+++ b/mercurial/revset.py	Tue Mar 18 17:19:44 2014 -0500
@@ -128,7 +128,7 @@
 
 keywords = set(['and', 'or', 'not'])
 
-def tokenize(program):
+def tokenize(program, lookup=None):
     '''
     Parse a revset statement into a stream of tokens
 
@@ -2023,14 +2023,17 @@
         aliases[alias.name] = alias
     return _expandaliases(aliases, tree, [], {})
 
-def parse(spec):
+def parse(spec, lookup=None):
     p = parser.parser(tokenize, elements)
-    return p.parse(spec)
-
-def match(ui, spec):
+    return p.parse(spec, lookup=lookup)
+
+def match(ui, spec, repo=None):
     if not spec:
         raise error.ParseError(_("empty query"))
-    tree, pos = parse(spec)
+    lookup = None
+    if repo:
+        lookup = repo.__contains__
+    tree, pos = parse(spec, lookup)
     if (pos != len(spec)):
         raise error.ParseError(_("invalid token"), pos)
     if ui: