Show More
@@ -5,7 +5,7 b'' | |||
|
5 | 5 | # This software may be used and distributed according to the terms of the |
|
6 | 6 | # GNU General Public License version 2 or any later version. |
|
7 | 7 | |
|
8 | import parser, error | |
|
8 | import parser, error, util | |
|
9 | 9 | from i18n import _ |
|
10 | 10 | |
|
11 | 11 | elements = { |
@@ -110,6 +110,42 b' def notset(mctx, x):' | |||
|
110 | 110 | def listset(mctx, a, b): |
|
111 | 111 | raise error.ParseError(_("can't use a list in this context")) |
|
112 | 112 | |
|
113 | def func(mctx, a, b): | |
|
114 | if a[0] == 'symbol' and a[1] in symbols: | |
|
115 | return symbols[a[1]](mctx, b) | |
|
116 | raise error.ParseError(_("not a function: %s") % a[1]) | |
|
117 | ||
|
118 | def getlist(x): | |
|
119 | if not x: | |
|
120 | return [] | |
|
121 | if x[0] == 'list': | |
|
122 | return getlist(x[1]) + [x[2]] | |
|
123 | return [x] | |
|
124 | ||
|
125 | def getargs(x, min, max, err): | |
|
126 | l = getlist(x) | |
|
127 | if len(l) < min or len(l) > max: | |
|
128 | raise error.ParseError(err) | |
|
129 | return l | |
|
130 | ||
|
131 | def binary(mctx, x): | |
|
132 | getargs(x, 0, 0, _("binary takes no arguments")) | |
|
133 | return [f for f in mctx.subset if util.binary(mctx.ctx[f].data())] | |
|
134 | ||
|
135 | def exec_(mctx, x): | |
|
136 | getargs(x, 0, 0, _("exec takes no arguments")) | |
|
137 | return [f for f in mctx.subset if mctx.ctx.flags(f) == 'x'] | |
|
138 | ||
|
139 | def symlink(mctx, x): | |
|
140 | getargs(x, 0, 0, _("symlink takes no arguments")) | |
|
141 | return [f for f in mctx.subset if mctx.ctx.flags(f) == 'l'] | |
|
142 | ||
|
143 | symbols = { | |
|
144 | 'binary': binary, | |
|
145 | 'exec': exec_, | |
|
146 | 'symlink': symlink, | |
|
147 | } | |
|
148 | ||
|
113 | 149 | methods = { |
|
114 | 150 | 'string': stringset, |
|
115 | 151 | 'symbol': stringset, |
@@ -117,7 +153,8 b' methods = {' | |||
|
117 | 153 | 'or': orset, |
|
118 | 154 | 'list': listset, |
|
119 | 155 | 'group': getset, |
|
120 | 'not': notset | |
|
156 | 'not': notset, | |
|
157 | 'func': func, | |
|
121 | 158 | } |
|
122 | 159 | |
|
123 | 160 | class matchctx(object): |
General Comments 0
You need to be logged in to leave comments.
Login now