Create ast package

This commit is contained in:
Bartłomiej Pluta
2019-07-03 11:27:51 +02:00
parent 2823fd1896
commit c8ff5ce38f
38 changed files with 622 additions and 11 deletions

View File

@@ -0,0 +1,19 @@
from smnp.ast.node.colon import ColonNode
from smnp.error.syntax import SyntaxException
from smnp.token.type import TokenType
# colon -> expr ':' expr
def parseColon(expr1, input, parent):
if input.hasCurrent() and input.current().type == TokenType.COLON:
token = input.current()
input.ahead()
expr2 = parseExpression(input, parent)
if expr2 is None:
raise SyntaxException(input.current().pos, f"Expected expression '{input.current().value}'")
colon = ColonNode(expr1, expr2, parent, token.pos)
expr1.parent = colon
expr2.parent = colon
return colon
return None