Reformat evaluator #1

This commit is contained in:
Bartłomiej Pluta
2019-07-04 17:57:12 +02:00
parent f0cbf37fe9
commit 34a0eda199
36 changed files with 470 additions and 270 deletions

View File

@@ -1,4 +1,5 @@
from smnp.ast.node.block import BlockNode, CloseBlockNode, BlockItemNode
from smnp.ast.parsers.statement import parseStatement
from smnp.token.type import TokenType

View File

@@ -1,4 +1,5 @@
from smnp.ast.node.colon import ColonNode
from smnp.ast.parsers.expression import parseExpression
from smnp.error.syntax import SyntaxException
from smnp.token.type import TokenType
@@ -11,7 +12,7 @@ def parseColon(expr1, input, parent):
expr2 = parseExpression(input, parent)
if expr2 is None:
raise SyntaxException(input.current().pos, f"Expected expression '{input.current().value}'")
raise SyntaxException(f"Expected expression '{input.current().value}'", input.current().pos)
colon = ColonNode(expr1, expr2, parent, token.pos)
expr1.parent = colon
expr2.parent = colon

View File

@@ -7,6 +7,6 @@ def parseToken(input, parent):
value = combineParsers([ parseStatement ])(input, parent)
if value is None:
raise SyntaxException(None, "Unknown statement") # TODO
raise SyntaxException("Unknown statement") # TODO
return value

View File

@@ -15,9 +15,9 @@ def rollup(parser):
def assertToken(expected, input):
if not input.hasCurrent():
raise SyntaxException(None, f"Expected '{expected}'")
raise SyntaxException(f"Expected '{expected}'")
if expected != input.current().type:
raise SyntaxException(input.current().pos, f"Expected '{expected}', found '{input.current().value}'")
raise SyntaxException(f"Expected '{expected}', found '{input.current().value}'", input.current().pos)
def combineParsers(parsers):