better ast cleanup

- try to fix block parsing
This commit is contained in:
Luna 2019-03-10 02:47:02 -03:00
parent 92a365d908
commit c2678fe360

View file

@ -175,7 +175,8 @@ def read_start(reader: Reader):
token = reader.next()
if token is None:
return []
print('eof!')
return None
ast = []
res = []
@ -184,13 +185,23 @@ def read_start(reader: Reader):
# handle blocks
if token.value == '{':
# next can be a whitespace, or a }
token = reader.next()
print('block start!, next:', token)
if token.type_ == TokenType.whitespace:
# keep going on reading
while True:
token = reader.next()
print(token)
if token.value == '}':
break
res.extend(read_start(reader))
elif token.value == '}':
res = []
# import, fn, etc
elif token.type_ == TokenType.reserved:
@ -205,20 +216,24 @@ def read_start(reader: Reader):
ast.append(res)
return ast
def read_loop(reader: Reader):
"""Read the AST."""
final_ast = []
while True:
ast = read_start(reader)
if not ast:
# break when eof
if ast is None:
break
try:
inner = ast[0]
except IndexError:
inner = None
if not inner:
break
if ast and not inner:
final_ast.append(ast)
return final_ast