Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/revset.py @ 20779:ffc2295c6b80
revset: pass a lookup function to the tokenizer
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Tue, 18 Mar 2014 17:19:44 -0500 |
parents | f15ff553b762 |
children | 403f1f73d30f |
comparison
equal
deleted
inserted
replaced
20778:7c4778bc29f0 | 20779:ffc2295c6b80 |
---|---|
126 "end": (0, None, None), | 126 "end": (0, None, None), |
127 } | 127 } |
128 | 128 |
129 keywords = set(['and', 'or', 'not']) | 129 keywords = set(['and', 'or', 'not']) |
130 | 130 |
131 def tokenize(program): | 131 def tokenize(program, lookup=None): |
132 ''' | 132 ''' |
133 Parse a revset statement into a stream of tokens | 133 Parse a revset statement into a stream of tokens |
134 | 134 |
135 Check that @ is a valid unquoted token character (issue3686): | 135 Check that @ is a valid unquoted token character (issue3686): |
136 >>> list(tokenize("@::")) | 136 >>> list(tokenize("@::")) |
2021 for k, v in ui.configitems('revsetalias'): | 2021 for k, v in ui.configitems('revsetalias'): |
2022 alias = revsetalias(k, v) | 2022 alias = revsetalias(k, v) |
2023 aliases[alias.name] = alias | 2023 aliases[alias.name] = alias |
2024 return _expandaliases(aliases, tree, [], {}) | 2024 return _expandaliases(aliases, tree, [], {}) |
2025 | 2025 |
2026 def parse(spec): | 2026 def parse(spec, lookup=None): |
2027 p = parser.parser(tokenize, elements) | 2027 p = parser.parser(tokenize, elements) |
2028 return p.parse(spec) | 2028 return p.parse(spec, lookup=lookup) |
2029 | 2029 |
2030 def match(ui, spec): | 2030 def match(ui, spec, repo=None): |
2031 if not spec: | 2031 if not spec: |
2032 raise error.ParseError(_("empty query")) | 2032 raise error.ParseError(_("empty query")) |
2033 tree, pos = parse(spec) | 2033 lookup = None |
2034 if repo: | |
2035 lookup = repo.__contains__ | |
2036 tree, pos = parse(spec, lookup) | |
2034 if (pos != len(spec)): | 2037 if (pos != len(spec)): |
2035 raise error.ParseError(_("invalid token"), pos) | 2038 raise error.ParseError(_("invalid token"), pos) |
2036 if ui: | 2039 if ui: |
2037 tree = findaliases(ui, tree) | 2040 tree = findaliases(ui, tree) |
2038 weight, tree = optimize(tree, True) | 2041 weight, tree = optimize(tree, True) |