.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/advanced/dynamic_complete.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_examples_advanced_dynamic_complete.py: 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": ""}`` .. GENERATED FROM PYTHON SOURCE LINES 18-144 .. code-block:: default 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 /(?` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: dynamic_complete.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_