[dingus] sugnid
This commit is contained in:
parent
22b7b4d185
commit
1d650b79f9
1 changed files with 18 additions and 0 deletions
|
|
@ -44,9 +44,27 @@ GRAMMAR_GLOBALS = {}
|
||||||
|
|
||||||
def eval_grammar(code):
|
def eval_grammar(code):
|
||||||
global GRAMMAR_GLOBALS
|
global GRAMMAR_GLOBALS
|
||||||
|
|
||||||
try:
|
try:
|
||||||
dingus.post_grammar_status("Evaluating grammar...")
|
dingus.post_grammar_status("Evaluating grammar...")
|
||||||
pyodide.code.eval_code(code, globals=GRAMMAR_GLOBALS)
|
pyodide.code.eval_code(code, globals=GRAMMAR_GLOBALS)
|
||||||
|
|
||||||
|
grammar = None
|
||||||
|
for key, value in GRAMMAR_GLOBALS.items():
|
||||||
|
if isinstance(value, type) and issubclass(value, parser.Grammar) and value is not parser.Grammar:
|
||||||
|
value = value()
|
||||||
|
|
||||||
|
if isinstance(value, parser.Grammar):
|
||||||
|
if grammar is None:
|
||||||
|
grammar = value()
|
||||||
|
else:
|
||||||
|
raise Exception("More than one Grammar found in the file")
|
||||||
|
|
||||||
|
if grammar is None:
|
||||||
|
raise Exception("No grammar definition, define or instantiate a class that inherits from parser.Grammar")
|
||||||
|
|
||||||
|
# TODO: Build the table.
|
||||||
|
|
||||||
dingus.post_grammar_loaded()
|
dingus.post_grammar_loaded()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
dingus.post_grammar_error(f"{e}")
|
dingus.post_grammar_error(f"{e}")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue