Commit 358e632e authored by Taddeus Kroes's avatar Taddeus Kroes

Moved n-ary operator definition to a constant list.

parent dfd85838
......@@ -31,6 +31,9 @@ OP_SUBSCRIPT = 8
OP_AND = 9
OP_OR = 10
# Binary operators that are considered n-ary
NARY_OPERATORS = [OP_ADD, OP_SUB, OP_MUL]
# N-ary (functions)
OP_INT = 11
OP_INT_INDEF = 12
......@@ -200,7 +203,7 @@ class ExpressionBase(object):
return exponent == None or self[1] == exponent
def is_nary(self):
return not self.is_leaf and self.op in [OP_ADD, OP_SUB, OP_MUL]
return not self.is_leaf and self.op in NARY_OPERATORS
def is_identifier(self, identifier=None):
return self.type == TYPE_IDENTIFIER \
......@@ -457,7 +460,7 @@ class ExpressionNode(Node, ExpressionBase):
if not isinstance(other, ExpressionNode) or other.op != self.op:
return False
if self.op in (OP_ADD, OP_MUL):
if self.op in NARY_OPERATORS:
s0 = Scope(self)
s1 = set(Scope(other))
......
from node import OP_NEG
from node import OP_NEG, NARY_OPERATORS
from rules import RULES
from rules.precedences import HIGH, LOW, RELATIVE
......@@ -70,7 +70,8 @@ def depth_possibilities(node, depth=0, parent_op=None):
# Add operator-specific handlers. Prevent duplicate possibilities in
# n-ary nodes by only executing the handlers on the outermost node of
# related nodes with the same operator
if node.op != parent_op and node.op in RULES:
if node.op in RULES and (node.op != parent_op \
or node.op not in NARY_OPERATORS):
handlers += RULES[node.op]
# Add negation handlers after operator-specific handlers to obtain an
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment