feat(parser): use AST printer in test script

This commit is contained in:
2026-05-14 01:12:05 +02:00
parent 052339ad3a
commit 6d885a0449

22
test.py
View File

@@ -1,10 +1,11 @@
import importlib import importlib
from pathlib import Path from pathlib import Path
from core.ast.printer import AnnotationAstPrinter
from lexer.annotations import AnnotationLexer from lexer.annotations import AnnotationLexer
from lexer.midas import MidasLexer from lexer.midas import MidasLexer
from lexer.token import Token from lexer.token import Token
from parser.annotations import AnnotationParser
# Frame annotation # Frame annotation
mod = importlib.import_module("examples.00_syntax_prototype.01_simple_types") mod = importlib.import_module("examples.00_syntax_prototype.01_simple_types")
@@ -12,17 +13,20 @@ mod = importlib.import_module("examples.00_syntax_prototype.01_simple_types")
annotation: str = mod.__annotations__["df"] annotation: str = mod.__annotations__["df"]
lexer: AnnotationLexer = AnnotationLexer(annotation, "01_simple_types.py") lexer: AnnotationLexer = AnnotationLexer(annotation, "01_simple_types.py")
tokens: list[Token] = lexer.process() tokens: list[Token] = lexer.process()
print([ # print([f"{t.type.name}('{t.lexeme}')" for t in tokens])
f"{t.type.name}('{t.lexeme}')"
for t in tokens parser = AnnotationParser(tokens)
]) parsed = parser.parse()
print(parsed)
for err in parser.errors:
print(err.get_report())
printer = AnnotationAstPrinter()
if parsed is not None:
print(printer.print(parsed))
# Midas type definitions # Midas type definitions
path: Path = Path("examples") / "00_syntax_prototype" / "02_custom_types.midas" path: Path = Path("examples") / "00_syntax_prototype" / "02_custom_types.midas"
definitions: str = path.read_text() definitions: str = path.read_text()
midas_lexer: MidasLexer = MidasLexer(definitions, path.name) midas_lexer: MidasLexer = MidasLexer(definitions, path.name)
tokens = midas_lexer.process() tokens = midas_lexer.process()
print([ # print([f"{t.type.name}('{t.lexeme}')" for t in tokens])
f"{t.type.name}('{t.lexeme}')"
for t in tokens
])