{ "info": { "author": "Jazeps Basko", "author_email": "jazeps.basko@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Programming Language :: Python", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7" ], "description": "=========\nshreducer\n=========\n\nSimple compilers in Python for fun and profit.\n\n-----------------------------------------\nExample Grammars Included in This Project\n-----------------------------------------\n\nIf you want to reuse the examples code, feel free to copy the code into your projects, but\ndo not introduce dependencies on examples as the examples may be changed or removed without notice.\nBuild your own grammar and related classes by extending classes provided in the `shreducer` package only.\n\n* Python 3.6+ type hints string representation\n* Filter expressions for web APIs. Allows parsing of expressions like this:\n ``https://your.api?filter=(status eq open and type eq store) or (status eq closed and type not in office, garage)``\n* With a compiler of Elasticsearch queries included (not tested since 2016)\n* A couple of primitive grammars for basic arithmetic expressions as examples\n\n----------\nComponents\n----------\n\n* *Tokenizers* (no need to implement your own, we rely on ``shlex`` from Python Standard Library)\n* Grammars\n* *Parsers* (no need to implement your own, we use a *shift-reduce* parser, hence the name of the project)\n* Generators\n\n**Tokenizer** splits input string into lexical units of the grammar (we call them tokens here).\n\n**Grammar** describes the syntax rules of a language that we want to parse.\n\n**Parser** parses sequence of tokens and generates a parse tree.\nFor example ``('+', 2, ('-', 10, 3))`` could be a parse tree.\n\n**Generator** takes a parse tree and evaluates it. For example, an arithmetic generator could take \na parse tree ``('+', 2, ('-', 10, 3))`` as an input and produce ``9`` as an output.\n\nAll these components together make a compiler.\n\n------------------------\nExpressing a New Grammar\n------------------------\n\nSee examples under ``shreducer_examples/``:\n\n* ``DictG`` - simplest of all grammars, the most suitable to understand the basic idea, parser produces parsed dictionary\n* ``ListG`` - another simple grammar, but unlike dictionary grammar, parser for this one produces parse tree\n* ``PlusMinusArithmeticsG`` - simple arithmetic expression parser, parser produces parse tree\n* ``BetterArithmeticsG`` - arithmetic expression parser that respects operator precedence, parser produces parse tree\n* ``FilterExpressionsG`` - comparison operators and logical operators, parser produces parse tree\n* ``BetterFiltersG`` - comparatively rich filter expression language, unlike other grammars this one uses look-ahead,\n parser produces parse tree\n* ``TypeHintsG`` - parsing Python 3.6+ type hints string representation\n\nThere is some magic (a meta class) going on in ``t`` class to allow\ndeclaring a string constant without writing its value twice:\n\n.. code-block:: python\n\n class MyGrammar(Grammar):\n class t:\n IDENT = None\n PLUS_MINUS = '+-' \n EXPR = ()\n\n\nAfter the class ``MyGrammar`` is created, the value of ``MyGrammar.t.IDENT`` will be ``\"IDENT\"``.\nSimilarly, ``MyGrammar.t.PLUS_MINUS`` will be ``\"PLUS_MINUS\"``, and ``MyGrammar.t.EXPR`` will be ``\"EXPR\"``.\n\nMember of ``class t`` with value ``None`` is treated as the default token type.\n\nMembers of ``class t`` with value ``()`` are treated as names of tokens of higher order -- expressions.\n\n------------------------\nTesting Your New Grammar\n------------------------\n\nIf you implement just a grammar, you can try parsing input strings with ``Grammar.simple_parse`` (which is a class\nmethod).\n\nFor example, to try ``TypeHintsG`` (grammar for parsing type hints string representation in Python 3.6+),\nyou can do:\n\n.. code-block:: python\n\n print(TypeHintsG.simple_parse('typing.Union[typing.List[str], typing.Dict[str, int]]'))\n\n\nThis will produce the following parse tree:\n\n.. code-block:: python\n\n {\n \"name\": \"typing.Union\",\n \"args\": [\n {\n \"name\": \"typing.List\",\n \"args\": [\n {\"name\": \"str\", \"args\": None},\n ],\n },\n {\n \"name\": \"typing.Dict\",\n \"args\": [\n {\"name\": \"str\", \"args\": None},\n {\"name\": \"int\", \"args\": None},\n ],\n },\n ],\n }\n\n\n\n", "description_content_type": "", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/jbasko/shreducer", "keywords": "", "license": "MIT", "maintainer": "Jazeps Basko", "maintainer_email": "jazeps.basko@gmail.com", "name": "shreducer", "package_url": "https://pypi.org/project/shreducer/", "platform": "", "project_url": "https://pypi.org/project/shreducer/", "project_urls": { "Homepage": "https://github.com/jbasko/shreducer" }, "release_url": "https://pypi.org/project/shreducer/1.0.1/", "requires_dist": null, "requires_python": "", "summary": "Grammars, parsers, and compilers in Python 3.6+", "version": "1.0.1" }, "last_serial": 4284860, "releases": { "1.0.0": [ { "comment_text": "", "digests": { "md5": "1b4d71ae3d3bbbbec8b43b0f7214dd1a", "sha256": "d696ebcd37a738c66a25bf96e0d1d5b91c046c1836eae667e226a7ed73fa4eb9" }, "downloads": -1, "filename": "shreducer-1.0.0-py3-none-any.whl", "has_sig": false, "md5_digest": "1b4d71ae3d3bbbbec8b43b0f7214dd1a", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 39461, "upload_time": "2018-09-18T18:45:59", "url": "https://files.pythonhosted.org/packages/86/b7/4602d612a6ac34279bdb88713d492b34ca264f4954f8dbe80c0bee1858fd/shreducer-1.0.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "7303a523bf7c6792b16775252bf0c67a", "sha256": "3facbaab35e17ab364a86a51b672de22ca11fa702b13d7c06bde4aa43da7b8e9" }, "downloads": -1, "filename": "shreducer-1.0.0.tar.gz", "has_sig": false, "md5_digest": "7303a523bf7c6792b16775252bf0c67a", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 18246, "upload_time": "2018-09-18T18:46:01", "url": "https://files.pythonhosted.org/packages/09/b8/f356717de2cbc2d03e566a97cf79111087498422e0647fd40ba20b8d9a62/shreducer-1.0.0.tar.gz" } ], "1.0.1": [ { "comment_text": "", "digests": { "md5": "9e605d3d1a3de5c0056c26f7990a2adc", "sha256": "346fb326ff3efe8de246b909e5dbf2694837508a9437c0bf08600076b908bc24" }, "downloads": -1, "filename": "shreducer-1.0.1-py3-none-any.whl", "has_sig": false, "md5_digest": "9e605d3d1a3de5c0056c26f7990a2adc", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 39727, "upload_time": "2018-09-18T19:00:23", "url": "https://files.pythonhosted.org/packages/45/27/942ca9a59e030c44fc0c1e58f7db67ff96c6ff07841cf3fccff63eca62fc/shreducer-1.0.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "5ab30f29481e5e0a8ca38623c727e45b", "sha256": "35d35ab034c14517ec2ecc6d5b483b519b59d40ceb01e7f660fe402bf6e1a81b" }, "downloads": -1, "filename": "shreducer-1.0.1.tar.gz", "has_sig": false, "md5_digest": "5ab30f29481e5e0a8ca38623c727e45b", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 18673, "upload_time": "2018-09-18T19:00:25", "url": "https://files.pythonhosted.org/packages/ac/25/c65af496d49dea8c2530822f966855a55ce08d62d73c400286aa6b332c9f/shreducer-1.0.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "9e605d3d1a3de5c0056c26f7990a2adc", "sha256": "346fb326ff3efe8de246b909e5dbf2694837508a9437c0bf08600076b908bc24" }, "downloads": -1, "filename": "shreducer-1.0.1-py3-none-any.whl", "has_sig": false, "md5_digest": "9e605d3d1a3de5c0056c26f7990a2adc", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 39727, "upload_time": "2018-09-18T19:00:23", "url": "https://files.pythonhosted.org/packages/45/27/942ca9a59e030c44fc0c1e58f7db67ff96c6ff07841cf3fccff63eca62fc/shreducer-1.0.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "5ab30f29481e5e0a8ca38623c727e45b", "sha256": "35d35ab034c14517ec2ecc6d5b483b519b59d40ceb01e7f660fe402bf6e1a81b" }, "downloads": -1, "filename": "shreducer-1.0.1.tar.gz", "has_sig": false, "md5_digest": "5ab30f29481e5e0a8ca38623c727e45b", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 18673, "upload_time": "2018-09-18T19:00:25", "url": "https://files.pythonhosted.org/packages/ac/25/c65af496d49dea8c2530822f966855a55ce08d62d73c400286aa6b332c9f/shreducer-1.0.1.tar.gz" } ] }