

.. _sphx_glr_examples_advanced:

Advanced Examples
~~~~~~~~~~~~~~~~~



.. raw:: html

    <div class="sphx-glr-thumbnails">

.. thumbnail-parent-div-open

.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="This example demonstrates the power of LALR&#x27;s contextual lexer, by parsing a toy configuration ...">

.. only:: html

  .. image:: /examples/advanced/images/thumb/sphx_glr_conf_lalr_thumb.png
    :alt:

  :ref:`sphx_glr_examples_advanced_conf_lalr.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">LALR’s contextual lexer</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="This example shows how to use Lark&#x27;s templates to achieve cleaner grammars">

.. only:: html

  .. image:: /examples/advanced/images/thumb/sphx_glr_templates_thumb.png
    :alt:

  :ref:`sphx_glr_examples_advanced_templates.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Templates</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="Demonstrates the power of Earley’s dynamic lexer on a toy configuration language">

.. only:: html

  .. image:: /examples/advanced/images/thumb/sphx_glr_conf_earley_thumb.png
    :alt:

  :ref:`sphx_glr_examples_advanced_conf_earley.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Earley’s dynamic lexer</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="This example demonstrates error handling using an interactive parser in LALR">

.. only:: html

  .. image:: /examples/advanced/images/thumb/sphx_glr_error_handling_thumb.png
    :alt:

  :ref:`sphx_glr_examples_advanced_error_handling.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Error handling using an interactive parser</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="Demonstrates the experimental text-reconstruction feature">

.. only:: html

  .. image:: /examples/advanced/images/thumb/sphx_glr_reconstruct_json_thumb.png
    :alt:

  :ref:`sphx_glr_examples_advanced_reconstruct_json.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Reconstruct a JSON</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="Demonstrates using a custom lexer to parse a non-textual stream of data">

.. only:: html

  .. image:: /examples/advanced/images/thumb/sphx_glr_custom_lexer_thumb.png
    :alt:

  :ref:`sphx_glr_examples_advanced_custom_lexer.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Custom lexer</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="This example demonstrates how to subclass TreeForestTransformer to directly transform a SPPF.">

.. only:: html

  .. image:: /examples/advanced/images/thumb/sphx_glr_tree_forest_transformer_thumb.png
    :alt:

  :ref:`sphx_glr_examples_advanced_tree_forest_transformer.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Transform a Forest</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="The code is short and clear, and outperforms every other parser (that&#x27;s written in Python). For...">

.. only:: html

  .. image:: /examples/advanced/images/thumb/sphx_glr__json_parser_thumb.png
    :alt:

  :ref:`sphx_glr_examples_advanced__json_parser.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Simple JSON Parser</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="This example demonstrates how to subclass ForestVisitor to make a custom SPPF node prioritizer ...">

.. only:: html

  .. image:: /examples/advanced/images/thumb/sphx_glr_prioritizer_thumb.png
    :alt:

  :ref:`sphx_glr_examples_advanced_prioritizer.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Custom SPPF Prioritizer</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="This example demonstrates how to translate between two trees using tree templates. It parses Py...">

.. only:: html

  .. image:: /examples/advanced/images/thumb/sphx_glr_py3to2_thumb.png
    :alt:

  :ref:`sphx_glr_examples_advanced_py3to2.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Python 3 to Python 2 converter (tree templates)</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="A fully-working Python 2 &amp; 3 parser (but not production ready yet!)">

.. only:: html

  .. image:: /examples/advanced/images/thumb/sphx_glr_python_parser_thumb.png
    :alt:

  :ref:`sphx_glr_examples_advanced_python_parser.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Grammar-complete Python Parser</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="    This example demonstrates how to transform a parse-tree into an AST using lark.ast_utils.">

.. only:: html

  .. image:: /examples/advanced/images/thumb/sphx_glr_create_ast_thumb.png
    :alt:

  :ref:`sphx_glr_examples_advanced_create_ast.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Creating an AST from the parse tree</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="A demonstration of example-driven error reporting with the Earley parser (See also: error_repor...">

.. only:: html

  .. image:: /examples/advanced/images/thumb/sphx_glr_error_reporting_earley_thumb.png
    :alt:

  :ref:`sphx_glr_examples_advanced_error_reporting_earley.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Example-Driven Error Reporting</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="A demonstration of example-driven error reporting with the LALR parser (See also: error_reporti...">

.. only:: html

  .. image:: /examples/advanced/images/thumb/sphx_glr_error_reporting_lalr_thumb.png
    :alt:

  :ref:`sphx_glr_examples_advanced_error_reporting_lalr.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Example-Driven Error Reporting</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="Demonstrates how Lark&#x27;s experimental text-reconstruction feature can recreate functional Python...">

.. only:: html

  .. image:: /examples/advanced/images/thumb/sphx_glr_reconstruct_python_thumb.png
    :alt:

  :ref:`sphx_glr_examples_advanced_reconstruct_python.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Reconstruct Python</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="Demonstrates how to use lexer=&#x27;dynamic_complete&#x27; and ambiguity=&#x27;explicit&#x27;">

.. only:: html

  .. image:: /examples/advanced/images/thumb/sphx_glr_dynamic_complete_thumb.png
    :alt:

  :ref:`sphx_glr_examples_advanced_dynamic_complete.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Using lexer dynamic_complete</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="This example shows how to write a syntax-highlighted editor with Qt and Lark">

.. only:: html

  .. image:: /examples/advanced/images/thumb/sphx_glr_qscintilla_json_thumb.png
    :alt:

  :ref:`sphx_glr_examples_advanced_qscintilla_json.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Syntax Highlighting</div>
    </div>


.. thumbnail-parent-div-close

.. raw:: html

    </div>


.. toctree::
   :hidden:

   /examples/advanced/conf_lalr
   /examples/advanced/templates
   /examples/advanced/conf_earley
   /examples/advanced/error_handling
   /examples/advanced/reconstruct_json
   /examples/advanced/custom_lexer
   /examples/advanced/tree_forest_transformer
   /examples/advanced/_json_parser
   /examples/advanced/prioritizer
   /examples/advanced/py3to2
   /examples/advanced/python_parser
   /examples/advanced/create_ast
   /examples/advanced/error_reporting_earley
   /examples/advanced/error_reporting_lalr
   /examples/advanced/reconstruct_python
   /examples/advanced/dynamic_complete
   /examples/advanced/qscintilla_json

