From 766ec56642d878bfa692e98863230fca4fc6fa6e Mon Sep 17 00:00:00 2001 From: Evan Jones Date: Thu, 27 Jul 2023 21:24:05 -0400 Subject: [PATCH] ensure primitive types can be used as root of schema --- examples/json-schema-to-grammar.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/examples/json-schema-to-grammar.py b/examples/json-schema-to-grammar.py index 4519951fc..3407bbf32 100644 --- a/examples/json-schema-to-grammar.py +++ b/examples/json-schema-to-grammar.py @@ -90,7 +90,10 @@ class SchemaConverter: else: assert schema_type in PRIMITIVE_RULES, f'Unrecognized schema: {schema}' - return self._add_rule(schema_type, PRIMITIVE_RULES[schema_type]) + return self._add_rule( + 'root' if rule_name == 'root' else schema_type, + PRIMITIVE_RULES[schema_type] + ) def format_grammar(self): return '\n'.join((f'{name} ::= {rule}' for name, rule in self._rules.items()))