Create parser for chain (dot operator)

This commit is contained in:
Bartłomiej Pluta
2019-07-10 21:31:02 +02:00
parent e31dab52f6
commit ab990f3071
4 changed files with 52 additions and 5 deletions

View File

@@ -6,6 +6,44 @@ from smnp.error.syntax import SyntaxException
from smnp.token.type import TokenType
class BinaryOperator(Node):
def __init__(self, pos):
super().__init__(pos)
self.children = [NoneNode(), NoneNode(), NoneNode()]
@property
def left(self):
return self[0]
@left.setter
def left(self, value):
self[0] = value
@property
def operator(self):
return self[1]
@operator.setter
def operator(self, value):
self[1] = value
@property
def right(self):
return self[2]
@right.setter
def right(self, value):
self[2] = value
@classmethod
def withValues(cls, left, operator, right):
node = cls(operator.pos)
node.left = left
node.operator = operator
node.right = right
return node
class LeftAssociativeOperatorNode(ExpressionNode):
def __init__(self, pos):
super().__init__(pos)
@@ -67,7 +105,7 @@ class LeftAssociativeOperatorNode(ExpressionNode):
)
class OperatorNode(Node):
class Operator(Node):
def __init__(self, pos):
super().__init__(pos)
self.children = [None]