""" Using lexer dynamic_complete ============================ Demonstrates how to use ``lexer='dynamic_complete'`` and ``ambiguity='explicit'`` Sometimes you have data that is highly ambiguous or 'broken' in some sense. When using ``parser='earley'`` and ``lexer='dynamic_complete'``, Lark will be able parse just about anything as long as there is a valid way to generate it from the Grammar, including looking 'into' the Regexes. This examples shows how to parse a json input where the quotes have been replaced by underscores: ``{_foo_:{}, _bar_: [], _baz_: __}`` Notice that underscores might still appear inside strings, so a potentially valid reading of the above is: ``{"foo_:{}, _bar": [], "baz": ""}`` """ from pprint import pprint from lark import Lark, Tree, Transformer, v_args from lark.visitors import Transformer_InPlace GRAMMAR = r""" %import common.SIGNED_NUMBER %import common.WS_INLINE %import common.NEWLINE %ignore WS_INLINE ?start: value ?value: object | array | string | SIGNED_NUMBER -> number | "true" -> true | "false" -> false | "null" -> null array : "[" [value ("," value)*] "]" object : "{" [pair ("," pair)*] "}" pair : string ":" value string: STRING STRING : ESCAPED_STRING ESCAPED_STRING: QUOTE_CHAR _STRING_ESC_INNER QUOTE_CHAR QUOTE_CHAR: "_" _STRING_INNER: /.*/ _STRING_ESC_INNER: _STRING_INNER /(?