[dingus] Reset the grammar globals every time

Now I can rewrite the grammar
This commit is contained in:
John Doty 2024-10-06 07:44:11 -07:00
parent 474bbf6964
commit 1a8c768772

View file

@ -80,23 +80,22 @@ import parser.runtime as runtime
import pyodide.code import pyodide.code
import pyodide.ffi as ffi import pyodide.ffi as ffi
GRAMMAR_GLOBALS = {}
GRAMMAR = None GRAMMAR = None
PARSE_TABLE = None PARSE_TABLE = None
LEXER = None LEXER = None
def eval_grammar(code): def eval_grammar(code):
global GRAMMAR_GLOBALS
global GRAMMAR global GRAMMAR
global PARSE_TABLE global PARSE_TABLE
global LEXER global LEXER
try: try:
dingus.post_grammar_status("Evaluating grammar...") dingus.post_grammar_status("Evaluating grammar...")
pyodide.code.eval_code(code, globals=GRAMMAR_GLOBALS) grammar_globals={}
pyodide.code.eval_code(code, globals=grammar_globals)
grammar = None grammar = None
for key, value in GRAMMAR_GLOBALS.items(): for key, value in grammar_globals.items():
if isinstance(value, type) and issubclass(value, parser.Grammar) and value is not parser.Grammar: if isinstance(value, type) and issubclass(value, parser.Grammar) and value is not parser.Grammar:
value = value() value = value()