Add support for assignment

This commit is contained in:
Bartłomiej Pluta
2019-07-05 23:33:28 +02:00
parent c1fbc2fe23
commit 2ecc86a9b2
2 changed files with 46 additions and 0 deletions

View File

@@ -0,0 +1,28 @@
from smnp.newast.node.expression import ExpressionNode
from smnp.newast.node.none import NoneNode
class AssignmentNode(ExpressionNode):
def __init__(self, pos):
super().__init__(pos)
self.children.append(NoneNode())
@property
def target(self):
return self[0]
@target.setter
def target(self, value):
self[0] = value
@property
def value(self):
return self[1]
@value.setter
def value(self, value):
self[1] = value
@classmethod
def _parse(cls, input):
raise RuntimeError("This class is not supposed to be automatically called")

View File

@@ -1,5 +1,7 @@
from smnp.newast.node.access import AccessNode
from smnp.newast.node.args import ArgumentsListNode
from smnp.newast.node.assignment import AssignmentNode
from smnp.newast.node.expression import ExpressionNode
from smnp.newast.node.invocation import FunctionCall
from smnp.newast.parser import Parser
from smnp.token.type import TokenType
@@ -14,9 +16,25 @@ class IdentifierNode(AccessNode):
def _literalParser(cls):
return Parser.oneOf(
IdentifierNode._functionCallParser(),
IdentifierNode._assignmentParser(),
IdentifierNode._identifierParser()
)
@staticmethod
def _assignmentParser():
def createNode(target, assignment, value):
node = AssignmentNode(assignment.pos)
node.target = target
node.value = value
return node
return Parser.allOf(
IdentifierNode._identifierParser(),
Parser.terminalParser(TokenType.ASSIGN),
ExpressionNode.parse,
createNode=createNode
)
@staticmethod
def _functionCallParser():
def createNode(name, arguments):