Mercurial > public > mercurial-scm > hg
comparison mercurial/filesetlang.py @ 38826:6371ab78c3b3
fileset: add phase to transform parsed tree
This isn't strictly necessary, but I decided to just follow the strategy
of the revset parsing.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sat, 21 Jul 2018 16:11:36 +0900 |
parents | b9162ea1b815 |
children | 48fc2a8af345 |
comparison
equal
deleted
inserted
replaced
38825:8a9f6076e60c | 38826:6371ab78c3b3 |
---|---|
129 l = getlist(x) | 129 l = getlist(x) |
130 if len(l) < min or len(l) > max: | 130 if len(l) < min or len(l) > max: |
131 raise error.ParseError(err) | 131 raise error.ParseError(err) |
132 return l | 132 return l |
133 | 133 |
134 def _analyze(x): | |
135 if x is None: | |
136 return x | |
137 | |
138 op = x[0] | |
139 if op in {'string', 'symbol'}: | |
140 return x | |
141 if op == 'kindpat': | |
142 getsymbol(x[1]) # kind must be a symbol | |
143 t = _analyze(x[2]) | |
144 return (op, x[1], t) | |
145 if op in {'group', 'not', 'negate'}: | |
146 t = _analyze(x[1]) | |
147 return (op, t) | |
148 if op in {'and', 'minus'}: | |
149 ta = _analyze(x[1]) | |
150 tb = _analyze(x[2]) | |
151 return (op, ta, tb) | |
152 if op in {'list', 'or'}: | |
153 ts = tuple(_analyze(y) for y in x[1:]) | |
154 return (op,) + ts | |
155 if op == 'func': | |
156 getsymbol(x[1]) # function name must be a symbol | |
157 ta = _analyze(x[2]) | |
158 return (op, x[1], ta) | |
159 raise error.ProgrammingError('invalid operator %r' % op) | |
160 | |
161 def analyze(x): | |
162 """Transform raw parsed tree to evaluatable tree which can be fed to | |
163 getmatch() | |
164 | |
165 All pseudo operations should be mapped to real operations or functions | |
166 defined in methods or symbols table respectively. | |
167 """ | |
168 return _analyze(x) | |
169 | |
134 def prettyformat(tree): | 170 def prettyformat(tree): |
135 return parser.prettyformat(tree, ('string', 'symbol')) | 171 return parser.prettyformat(tree, ('string', 'symbol')) |