.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/lark_grammar.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_lark_grammar.py: Lark Grammar ============ A reference implementation of the Lark grammar (using LALR(1)) .. GENERATED FROM PYTHON SOURCE LINES 7-37 .. code-block:: default import lark from pathlib import Path examples_path = Path(__file__).parent lark_path = Path(lark.__file__).parent parser = lark.Lark.open(lark_path / 'grammars/lark.lark', rel_to=__file__, parser="lalr") grammar_files = [ examples_path / 'advanced/python2.lark', examples_path / 'relative-imports/multiples.lark', examples_path / 'relative-imports/multiple2.lark', examples_path / 'relative-imports/multiple3.lark', examples_path / 'tests/no_newline_at_end.lark', examples_path / 'tests/negative_priority.lark', examples_path / 'standalone/json.lark', lark_path / 'grammars/common.lark', lark_path / 'grammars/lark.lark', lark_path / 'grammars/unicode.lark', lark_path / 'grammars/python.lark', ] def test(): for grammar_file in grammar_files: tree = parser.parse(open(grammar_file).read()) print("All grammars parsed successfully") if __name__ == '__main__': test() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.000 seconds) .. _sphx_glr_download_examples_lark_grammar.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: lark_grammar.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: lark_grammar.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_