labels work im pretty sure
This commit is contained in:
@@ -3,6 +3,7 @@ from dataclasses import dataclass
|
||||
from tokenizer import Token, TokenType
|
||||
from typing import Optional, Any
|
||||
from error import traceback
|
||||
from console import console
|
||||
|
||||
|
||||
@dataclass
|
||||
@@ -100,8 +101,8 @@ def generate_ast(tokens: list[Token], code: str) -> RootNode:
|
||||
# todo: this is the absolute WORST way i could do this, but i could not care less lmao
|
||||
# its not even performant......
|
||||
for token in tokens:
|
||||
#print(token.type)
|
||||
if token.type == TokenType.INSTRUCTION:
|
||||
|
||||
if current_node:
|
||||
scope.statements.append(current_node)
|
||||
|
||||
@@ -125,6 +126,11 @@ def generate_ast(tokens: list[Token], code: str) -> RootNode:
|
||||
else:
|
||||
current_node = FunctionNode([], [], scope)
|
||||
current_node_type = "func"
|
||||
elif token.type == TokenType.LABEL_DECLERATION:
|
||||
if current_node:
|
||||
scope.statements.append(current_node)
|
||||
current_node = None
|
||||
scope.statements.append(LabelDecNode(token.value))
|
||||
|
||||
if current_node:
|
||||
if token.type == TokenType.STRING:
|
||||
@@ -199,9 +205,6 @@ def generate_ast(tokens: list[Token], code: str) -> RootNode:
|
||||
current_node.arguments.append(FunctionCallNode(token.value))
|
||||
else:
|
||||
traceback(code, "SyntaxError", "Expected instruction or function return type, got function reference.")
|
||||
|
||||
elif token.type == TokenType.LABEL_DECLERATION:
|
||||
scope.statements.append(LabelDecNode(token.value))
|
||||
|
||||
elif token.type == TokenType.COMMENT:
|
||||
continue
|
||||
|
Reference in New Issue
Block a user