Create new parser (works for lists so far)
This commit is contained in:
@@ -1,17 +1,17 @@
|
||||
from smnp.ast.node.list import ListNode, ListItemNode, CloseListNode
|
||||
from smnp.ast.parsers.expression import parseExpression
|
||||
from smnp.ast.tools import rollup, assertToken
|
||||
from smnp.ast.tools import greedy, assertToken
|
||||
from smnp.token.type import TokenType
|
||||
|
||||
|
||||
# list -> CLOSE_PAREN | expr listTail
|
||||
def parseList(input, parent):
|
||||
if input.current().type == TokenType.OPEN_PAREN:
|
||||
if input.isCurrent(TokenType.OPEN_PAREN):
|
||||
node = ListNode(parent, input.current().pos)
|
||||
input.ahead()
|
||||
|
||||
# list -> CLOSE_PAREN (end of list)
|
||||
if input.hasCurrent() and input.current().type == TokenType.CLOSE_PAREN:
|
||||
if input.isCurrent(TokenType.CLOSE_PAREN):
|
||||
close = CloseListNode(node, input.current().pos)
|
||||
node.append(close)
|
||||
input.ahead()
|
||||
@@ -20,7 +20,7 @@ def parseList(input, parent):
|
||||
# list -> expr listTail
|
||||
if input.hasCurrent():
|
||||
token = input.current()
|
||||
expr = parseExpression(input, node)
|
||||
expr = greedy(parseExpression)(input, parent)
|
||||
item = ListItemNode(expr, node, token.pos)
|
||||
expr.parent = item
|
||||
node.append(item)
|
||||
@@ -33,7 +33,7 @@ def parseList(input, parent):
|
||||
# listTail -> COMMA expr listTail | CLOSE_PAREN
|
||||
def parseListTail(input, parent):
|
||||
# listTail -> CLOSE_PAREN
|
||||
if input.hasCurrent() and input.current().type == TokenType.CLOSE_PAREN:
|
||||
if input.isCurrent(TokenType.CLOSE_PAREN):
|
||||
close = CloseListNode(parent, input.current().pos)
|
||||
input.ahead()
|
||||
return close
|
||||
@@ -42,7 +42,7 @@ def parseListTail(input, parent):
|
||||
if input.hasCurrent() and input.hasMore():
|
||||
assertToken(TokenType.COMMA, input)
|
||||
input.ahead()
|
||||
expr = rollup(parseExpression)(input, parent)
|
||||
expr = greedy(parseExpression)(input, parent)
|
||||
if expr is not None:
|
||||
item = ListItemNode(expr, parent, expr.pos)
|
||||
expr.parent = item
|
||||
|
||||
Reference in New Issue
Block a user