Do some refactor with multiple left associative operators
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
from smnp.ast.node.expression import ExpressionNode
|
||||
from smnp.ast.node.ignore import IgnoredNode
|
||||
from smnp.ast.node.none import NoneNode
|
||||
from smnp.ast.parser import Parser
|
||||
from smnp.token.type import TokenType
|
||||
|
||||
@@ -7,7 +7,7 @@ from smnp.token.type import TokenType
|
||||
class RelationOperatorNode(ExpressionNode):
|
||||
def __init__(self, pos):
|
||||
super().__init__(pos)
|
||||
self.children.append(IgnoredNode(pos))
|
||||
self.children = [ NoneNode(), NoneNode(), NoneNode()]
|
||||
|
||||
@property
|
||||
def left(self):
|
||||
@@ -18,33 +18,42 @@ class RelationOperatorNode(ExpressionNode):
|
||||
self[0] = value
|
||||
|
||||
@property
|
||||
def right(self):
|
||||
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[1] = value
|
||||
self[2] = value
|
||||
|
||||
@classmethod
|
||||
def relationParser(cls):
|
||||
def createNode(left, right):
|
||||
def createNode(left, operator, right):
|
||||
node = RelationOperatorNode(right.pos)
|
||||
node.left = left
|
||||
node.operator = operator
|
||||
node.right = right
|
||||
return node
|
||||
|
||||
return Parser.leftAssociativeOperatorParser(
|
||||
cls._relationLiteralParser(),
|
||||
cls._relationLhs(),
|
||||
TokenType.EQUAL,
|
||||
cls._parseRelationProperty(),
|
||||
cls._relationRhs(),
|
||||
createNode=createNode
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def _relationLiteralParser(cls):
|
||||
raise RuntimeError(f"_relationLiteralParser() is not implemented in {cls.__name__} class")
|
||||
def _relationLhs(cls):
|
||||
raise RuntimeError(f"_relationLhs() is not implemented in {cls.__name__} class")
|
||||
|
||||
@staticmethod
|
||||
def _parseRelationProperty():
|
||||
def _relationRhs():
|
||||
# TODO doAssert
|
||||
return ExpressionNode.parse
|
||||
Reference in New Issue
Block a user