##// END OF EJS Templates
fileset: add phase to transform parsed tree...
Yuya Nishihara -
r38862:6371ab78 default
parent child Browse files
Show More
@@ -901,6 +901,7 b' def debugfileset(ui, repo, expr, **opts)'
901
901
902 stages = [
902 stages = [
903 ('parsed', pycompat.identity),
903 ('parsed', pycompat.identity),
904 ('analyzed', filesetlang.analyze),
904 ]
905 ]
905 stagenames = set(n for n, f in stages)
906 stagenames = set(n for n, f in stages)
906
907
@@ -528,6 +528,7 b' def _intree(funcs, tree):'
528 def match(ctx, expr, badfn=None):
528 def match(ctx, expr, badfn=None):
529 """Create a matcher for a single fileset expression"""
529 """Create a matcher for a single fileset expression"""
530 tree = filesetlang.parse(expr)
530 tree = filesetlang.parse(expr)
531 tree = filesetlang.analyze(tree)
531 mctx = matchctx(ctx, _buildstatus(ctx, tree), badfn=badfn)
532 mctx = matchctx(ctx, _buildstatus(ctx, tree), badfn=badfn)
532 return getmatch(mctx, tree)
533 return getmatch(mctx, tree)
533
534
@@ -131,5 +131,41 b' def getargs(x, min, max, err):'
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'))
@@ -89,4 +89,5 b' def compile(text):'
89 root except for "bin/README".
89 root except for "bin/README".
90 """
90 """
91 tree = filesetlang.parse(text)
91 tree = filesetlang.parse(text)
92 tree = filesetlang.analyze(tree)
92 return _compile(tree)
93 return _compile(tree)
@@ -169,6 +169,18 b' Show parsed tree at stages:'
169 (func
169 (func
170 (symbol 'clean')
170 (symbol 'clean')
171 None))))
171 None))))
172 * analyzed:
173 (or
174 (symbol 'a1')
175 (symbol 'a2')
176 (group
177 (and
178 (func
179 (symbol 'grep')
180 (string 'b'))
181 (func
182 (symbol 'clean')
183 None))))
172 * matcher:
184 * matcher:
173 <unionmatcher matchers=[
185 <unionmatcher matchers=[
174 <patternmatcher patterns='(?:a1$)'>,
186 <patternmatcher patterns='(?:a1$)'>,
General Comments 0
You need to be logged in to leave comments. Login now