-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug_real_parse.py
More file actions
36 lines (30 loc) · 1.11 KB
/
debug_real_parse.py
File metadata and controls
36 lines (30 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/env python3
from arbol.compiler.lexer import Lexer
from arbol.compiler.parser import Parser
from arbol.compiler.error import ErrorReporter
def debug_real_parse():
with open('arbol/test.arbol', 'r') as f:
arbol_code = f.read()
error_reporter = ErrorReporter()
lexer = Lexer(arbol_code)
parser = Parser(lexer, error_reporter)
# Parse and see what happens
try:
ast = parser.parse()
print("Parsing completed successfully!")
print(f"AST statements: {len(ast.statements)}")
for i, stmt in enumerate(ast.statements):
print(f" {i}: {type(stmt).__name__}")
if hasattr(stmt, 'name'):
print(f" name: {stmt.name}")
if hasattr(stmt, 'line'):
print(f" line: {stmt.line}")
except Exception as e:
print(f"Exception during parsing: {e}")
import traceback
traceback.print_exc()
print(f"\nErrors: {len(error_reporter.get_errors())}")
for error in error_reporter.get_errors():
print(f" - {error}")
if __name__ == "__main__":
debug_real_parse()