Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/fileset.py @ 38844:d82c4d42b615
fileset: flatten 'or' nodes to unnest unionmatchers
This also makes it easier to compile a union of basic patterns into a single
regexp pattern.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sat, 21 Jul 2018 15:23:56 +0900 |
parents | 4dc498d61d86 |
children | b9162ea1b815 |
comparison
equal
deleted
inserted
replaced
38843:4dc498d61d86 | 38844:d82c4d42b615 |
---|---|
101 def parse(expr): | 101 def parse(expr): |
102 p = parser.parser(elements) | 102 p = parser.parser(elements) |
103 tree, pos = p.parse(tokenize(expr)) | 103 tree, pos = p.parse(tokenize(expr)) |
104 if pos != len(expr): | 104 if pos != len(expr): |
105 raise error.ParseError(_("invalid token"), pos) | 105 raise error.ParseError(_("invalid token"), pos) |
106 return parser.simplifyinfixops(tree, {'list'}) | 106 return parser.simplifyinfixops(tree, {'list', 'or'}) |
107 | 107 |
108 def getsymbol(x): | 108 def getsymbol(x): |
109 if x and x[0] == 'symbol': | 109 if x and x[0] == 'symbol': |
110 return x[1] | 110 return x[1] |
111 raise error.ParseError(_('not a symbol')) | 111 raise error.ParseError(_('not a symbol')) |
155 def andmatch(mctx, x, y): | 155 def andmatch(mctx, x, y): |
156 xm = getmatch(mctx, x) | 156 xm = getmatch(mctx, x) |
157 ym = getmatch(mctx, y) | 157 ym = getmatch(mctx, y) |
158 return matchmod.intersectmatchers(xm, ym) | 158 return matchmod.intersectmatchers(xm, ym) |
159 | 159 |
160 def ormatch(mctx, x, y): | 160 def ormatch(mctx, *xs): |
161 xm = getmatch(mctx, x) | 161 ms = [getmatch(mctx, x) for x in xs] |
162 ym = getmatch(mctx, y) | 162 return matchmod.unionmatcher(ms) |
163 return matchmod.unionmatcher([xm, ym]) | |
164 | 163 |
165 def notmatch(mctx, x): | 164 def notmatch(mctx, x): |
166 m = getmatch(mctx, x) | 165 m = getmatch(mctx, x) |
167 return mctx.predicate(lambda f: not m(f), predrepr=('<not %r>', m)) | 166 return mctx.predicate(lambda f: not m(f), predrepr=('<not %r>', m)) |
168 | 167 |