🐐 Better arrays
This commit is contained in:
@@ -163,7 +163,7 @@ class DataArray(Node):
|
||||
|
||||
def print(self):
|
||||
items = ", ".join(i.print() for i in self.content)
|
||||
return f"[({items})]"
|
||||
return f"[{items}]"
|
||||
|
||||
def _eval(self, vtable):
|
||||
vals = []
|
||||
|
||||
@@ -138,6 +138,17 @@ class Parser():
|
||||
else:
|
||||
return [calls[0]] + calls[2]
|
||||
|
||||
@self.pg.production('array_items : ')
|
||||
@self.pg.production('array_items : expression')
|
||||
@self.pg.production('array_items : expression SYMBOL_COMMA array_items')
|
||||
def array_items(calls):
|
||||
if len(calls) == 0:
|
||||
return []
|
||||
elif len(calls) == 1:
|
||||
return [calls[0]]
|
||||
else:
|
||||
return [calls[0]] + calls[2]
|
||||
|
||||
@self.pg.production('expression : id')
|
||||
def expression_id(tokens):
|
||||
return tokens[0]
|
||||
@@ -187,7 +198,7 @@ class Parser():
|
||||
def parens(tokens):
|
||||
return tokens[1]
|
||||
|
||||
@self.pg.production('expression : SYMBOL_LBRACKET expressions SYMBOL_RBRACKET')
|
||||
@self.pg.production('expression : SYMBOL_LBRACKET array_items SYMBOL_RBRACKET')
|
||||
def array(tokens):
|
||||
return ast_nodes.DataArray(tokens[1])
|
||||
|
||||
@@ -221,7 +232,7 @@ class Parser():
|
||||
|
||||
@self.pg.error
|
||||
def error_handle(token):
|
||||
raise SyntaxError(token.name, token.value, token.source_pos)
|
||||
raise SyntaxError(f"{token.name}, {token.value}, {token.source_pos}")
|
||||
|
||||
parser = self.pg.build()
|
||||
return parser.parse(tokens_input) # type: ignore
|
||||
|
||||
Reference in New Issue
Block a user