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)
| 6143 | |
| 6144 | |
| 6145 | def expr_items(expr): |
| 6146 | """ |
| 6147 | Returns a set() of all items (symbols and choices) that appear in the |
| 6148 | expression 'expr'. |
| 6149 | |
| 6150 | Passing subexpressions of expressions to this function works as expected. |
| 6151 | """ |
| 6152 | res = set() |
| 6153 | |
| 6154 | def rec(subexpr): |
| 6155 | if subexpr.__class__ is tuple: |
| 6156 | # AND, OR, NOT, or relation |
| 6157 | |
| 6158 | rec(subexpr[1]) |
| 6159 | |
| 6160 | # NOTs only have a single operand |
| 6161 | if subexpr[0] is not NOT: |
| 6162 | rec(subexpr[2]) |
| 6163 | |
| 6164 | else: |
| 6165 | # Symbol or choice |
| 6166 | res.add(subexpr) |
| 6167 | |
| 6168 | rec(expr) |
| 6169 | return res |
| 6170 | |
| 6171 | |
| 6172 | def split_expr(expr, op): |
no test coverage detected