parglare


Nameparglare JSON
Version 0.17.0 PyPI version JSON
download
home_pageNone
SummaryA pure Python LR/GLR parser
upload_time2024-02-14 19:50:39
maintainerNone
docs_urlNone
authorNone
requires_python>=3.8, <3.13
licenseNone
keywords parser lr glr
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            .. image:: https://raw.githubusercontent.com/igordejanovic/parglare/master/docs/images/parglare-logo.png

|build-status| |coverage| |docs| |status| |license| |python-versions|


A pure Python scannerless LR/GLR parser.


For more information see `the docs <http://www.igordejanovic.net/parglare/>`_.


Quick intro
-----------

This is just a small example to get the general idea. This example shows how to
parse and evaluate expressions with 5 operations with different priority and
associativity. Evaluation is done using semantic/reduction actions.

The whole expression evaluator is done in under 30 lines of code!

.. code:: python

    from parglare import Parser, Grammar

    grammar = r"""
    E: E '+' E  {left, 1}
     | E '-' E  {left, 1}
     | E '*' E  {left, 2}
     | E '/' E  {left, 2}
     | E '^' E  {right, 3}
     | '(' E ')'
     | number;

    terminals
    number: /\d+(\.\d+)?/;
    """

    actions = {
        "E": [lambda _, n: n[0] + n[2],
              lambda _, n: n[0] - n[2],
              lambda _, n: n[0] * n[2],
              lambda _, n: n[0] / n[2],
              lambda _, n: n[0] ** n[2],
              lambda _, n: n[1],
              lambda _, n: n[0]],
        "number": lambda _, value: float(value),
    }

    g = Grammar.from_string(grammar)
    parser = Parser(g, debug=True, actions=actions)

    result = parser.parse("34 + 4.6 / 2 * 4^2^2 + 78")

    print("Result = ", result)

    # Output
    # -- Debugging/tracing output with detailed info about grammar, productions,
    # -- terminals and nonterminals, DFA states, parsing progress,
    # -- and at the end of the output:
    # Result = 700.8


Installation
------------

- Stable version:

.. code:: shell

    $ pip install parglare

- Development version:

.. code:: shell

    $ git clone git@github.com:igordejanovic/parglare.git
    $ pip install -e parglare

Citing parglare
---------------

If you use parglare in your research please cite this paper:

.. code:: text

    Igor Dejanović, Parglare: A LR/GLR parser for Python,
    Science of Computer Programming, issn:0167-6423, p.102734,
    DOI:10.1016/j.scico.2021.102734, 2021.

    @article{dejanovic2021b,
        author = {Igor Dejanović},
        title = {Parglare: A LR/GLR parser for Python},
        doi = {10.1016/j.scico.2021.102734},
        issn = {0167-6423},
        journal = {Science of Computer Programming},
        keywords = {parsing, LR, GLR, Python, visualization},
        pages = {102734},
        url = {https://www.sciencedirect.com/science/article/pii/S0167642321001271},
        year = {2021}
    }

License
-------

MIT

Python versions
---------------

Tested with 3.6-3.11

Credits
-------

Initial layout/content of this package was created with `Cookiecutter
<https://github.com/audreyr/cookiecutter>`_ and the
`audreyr/cookiecutter-pypackage <https://github.com/audreyr/cookiecutter-pypackage>`_ project template.


.. |build-status| image:: https://github.com/igordejanovic/parglare/actions/workflows/ci-linux-ubuntu.yml/badge.svg
   :target: https://github.com/igordejanovic/parglare/actions

.. |coverage| image:: https://coveralls.io/repos/github/igordejanovic/parglare/badge.svg?branch=master
   :target: https://coveralls.io/github/igordejanovic/parglare?branch=master

.. |docs| image:: https://img.shields.io/badge/docs-latest-green.svg
   :target: http://www.igordejanovic.net/parglare/latest/

.. |status| image:: https://img.shields.io/pypi/status/parglare.svg

.. |license| image:: https://img.shields.io/badge/License-MIT-blue.svg
   :target: https://opensource.org/licenses/MIT

.. |python-versions| image:: https://img.shields.io/pypi/pyversions/parglare.svg

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "parglare",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8, <3.13",
    "maintainer_email": "\"Igor R. Dejanovi\u0107\" <igor.dejanovic@gmail.com>",
    "keywords": "parser,lr,glr",
    "author": null,
    "author_email": "\"Igor R. Dejanovi\u0107\" <igor.dejanovic@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/82/7b/d80df8ddf03c51fbe6c3a057b9251d0ffaa7fcb9b4af633314dd4cdd6ebd/parglare-0.17.0.tar.gz",
    "platform": null,
    "description": ".. image:: https://raw.githubusercontent.com/igordejanovic/parglare/master/docs/images/parglare-logo.png\n\n|build-status| |coverage| |docs| |status| |license| |python-versions|\n\n\nA pure Python scannerless LR/GLR parser.\n\n\nFor more information see `the docs <http://www.igordejanovic.net/parglare/>`_.\n\n\nQuick intro\n-----------\n\nThis is just a small example to get the general idea. This example shows how to\nparse and evaluate expressions with 5 operations with different priority and\nassociativity. Evaluation is done using semantic/reduction actions.\n\nThe whole expression evaluator is done in under 30 lines of code!\n\n.. code:: python\n\n    from parglare import Parser, Grammar\n\n    grammar = r\"\"\"\n    E: E '+' E  {left, 1}\n     | E '-' E  {left, 1}\n     | E '*' E  {left, 2}\n     | E '/' E  {left, 2}\n     | E '^' E  {right, 3}\n     | '(' E ')'\n     | number;\n\n    terminals\n    number: /\\d+(\\.\\d+)?/;\n    \"\"\"\n\n    actions = {\n        \"E\": [lambda _, n: n[0] + n[2],\n              lambda _, n: n[0] - n[2],\n              lambda _, n: n[0] * n[2],\n              lambda _, n: n[0] / n[2],\n              lambda _, n: n[0] ** n[2],\n              lambda _, n: n[1],\n              lambda _, n: n[0]],\n        \"number\": lambda _, value: float(value),\n    }\n\n    g = Grammar.from_string(grammar)\n    parser = Parser(g, debug=True, actions=actions)\n\n    result = parser.parse(\"34 + 4.6 / 2 * 4^2^2 + 78\")\n\n    print(\"Result = \", result)\n\n    # Output\n    # -- Debugging/tracing output with detailed info about grammar, productions,\n    # -- terminals and nonterminals, DFA states, parsing progress,\n    # -- and at the end of the output:\n    # Result = 700.8\n\n\nInstallation\n------------\n\n- Stable version:\n\n.. code:: shell\n\n    $ pip install parglare\n\n- Development version:\n\n.. code:: shell\n\n    $ git clone git@github.com:igordejanovic/parglare.git\n    $ pip install -e parglare\n\nCiting parglare\n---------------\n\nIf you use parglare in your research please cite this paper:\n\n.. code:: text\n\n    Igor Dejanovi\u0107, Parglare: A LR/GLR parser for Python,\n    Science of Computer Programming, issn:0167-6423, p.102734,\n    DOI:10.1016/j.scico.2021.102734, 2021.\n\n    @article{dejanovic2021b,\n        author = {Igor Dejanovi\u0107},\n        title = {Parglare: A LR/GLR parser for Python},\n        doi = {10.1016/j.scico.2021.102734},\n        issn = {0167-6423},\n        journal = {Science of Computer Programming},\n        keywords = {parsing, LR, GLR, Python, visualization},\n        pages = {102734},\n        url = {https://www.sciencedirect.com/science/article/pii/S0167642321001271},\n        year = {2021}\n    }\n\nLicense\n-------\n\nMIT\n\nPython versions\n---------------\n\nTested with 3.6-3.11\n\nCredits\n-------\n\nInitial layout/content of this package was created with `Cookiecutter\n<https://github.com/audreyr/cookiecutter>`_ and the\n`audreyr/cookiecutter-pypackage <https://github.com/audreyr/cookiecutter-pypackage>`_ project template.\n\n\n.. |build-status| image:: https://github.com/igordejanovic/parglare/actions/workflows/ci-linux-ubuntu.yml/badge.svg\n   :target: https://github.com/igordejanovic/parglare/actions\n\n.. |coverage| image:: https://coveralls.io/repos/github/igordejanovic/parglare/badge.svg?branch=master\n   :target: https://coveralls.io/github/igordejanovic/parglare?branch=master\n\n.. |docs| image:: https://img.shields.io/badge/docs-latest-green.svg\n   :target: http://www.igordejanovic.net/parglare/latest/\n\n.. |status| image:: https://img.shields.io/pypi/status/parglare.svg\n\n.. |license| image:: https://img.shields.io/badge/License-MIT-blue.svg\n   :target: https://opensource.org/licenses/MIT\n\n.. |python-versions| image:: https://img.shields.io/pypi/pyversions/parglare.svg\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "A pure Python LR/GLR parser",
    "version": "0.17.0",
    "project_urls": {
        "Changelog": "https://github.com/igordejanovic/parglare/master/CHANGELOG.md",
        "Homepage": "https://github.com/igordejanovic/parglare",
        "Repository": "https://github.com/igordejanovic/parglare"
    },
    "split_keywords": [
        "parser",
        "lr",
        "glr"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "3e3e926bb0548e27b2777752560847a7715f92a89ecb295610a7b4b6bd581018",
                "md5": "b83b4590cdf31dc2576f2996afac128f",
                "sha256": "4ddfde01effc8f1310a68baa8188021139f7e74a5b3c81b9268084d399ec2004"
            },
            "downloads": -1,
            "filename": "parglare-0.17.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "b83b4590cdf31dc2576f2996afac128f",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8, <3.13",
            "size": 58617,
            "upload_time": "2024-02-14T19:50:36",
            "upload_time_iso_8601": "2024-02-14T19:50:36.194346Z",
            "url": "https://files.pythonhosted.org/packages/3e/3e/926bb0548e27b2777752560847a7715f92a89ecb295610a7b4b6bd581018/parglare-0.17.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "827bd80df8ddf03c51fbe6c3a057b9251d0ffaa7fcb9b4af633314dd4cdd6ebd",
                "md5": "319da076ee334355de1be45cab5dfc13",
                "sha256": "6f6fa5f0b13e35a1c775151019eee97682c3e464b7c1dd508e2a1766e2f2ea34"
            },
            "downloads": -1,
            "filename": "parglare-0.17.0.tar.gz",
            "has_sig": false,
            "md5_digest": "319da076ee334355de1be45cab5dfc13",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8, <3.13",
            "size": 1573649,
            "upload_time": "2024-02-14T19:50:39",
            "upload_time_iso_8601": "2024-02-14T19:50:39.953197Z",
            "url": "https://files.pythonhosted.org/packages/82/7b/d80df8ddf03c51fbe6c3a057b9251d0ffaa7fcb9b4af633314dd4cdd6ebd/parglare-0.17.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-02-14 19:50:39",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "igordejanovic",
    "github_project": "parglare",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "parglare"
}
        
Elapsed time: 0.19294s