Returns a set() of all items (symbols and choices) that appear in the expression 'expr'. Passing subexpressions of expressions to this function works as expected.
(expr)
| 6214 | |
| 6215 | |
| 6216 | def expr_items(expr): |
| 6217 | """ |
| 6218 | Returns a set() of all items (symbols and choices) that appear in the |
| 6219 | expression 'expr'. |
| 6220 | |
| 6221 | Passing subexpressions of expressions to this function works as expected. |
| 6222 | """ |
| 6223 | res = set() |
| 6224 | |
| 6225 | def rec(subexpr): |
| 6226 | if subexpr.__class__ is tuple: |
| 6227 | # AND, OR, NOT, or relation |
| 6228 | |
| 6229 | rec(subexpr[1]) |
| 6230 | |
| 6231 | # NOTs only have a single operand |
| 6232 | if subexpr[0] is not NOT: |
| 6233 | rec(subexpr[2]) |
| 6234 | |
| 6235 | else: |
| 6236 | # Symbol or choice |
| 6237 | res.add(subexpr) |
| 6238 | |
| 6239 | rec(expr) |
| 6240 | return res |
| 6241 | |
| 6242 | |
| 6243 | def split_expr(expr, op): |