From 1d650b79f973bf6a005e909eab08219f59b63faf Mon Sep 17 00:00:00 2001 From: John Doty Date: Mon, 30 Sep 2024 07:34:23 -0700 Subject: [PATCH] [dingus] sugnid --- dingus/worker.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/dingus/worker.js b/dingus/worker.js index 8fc99ee..ad6afaf 100644 --- a/dingus/worker.js +++ b/dingus/worker.js @@ -44,9 +44,27 @@ GRAMMAR_GLOBALS = {} def eval_grammar(code): global GRAMMAR_GLOBALS + try: dingus.post_grammar_status("Evaluating grammar...") 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() except Exception as e: dingus.post_grammar_error(f"{e}")