Name | parsial JSON |
Version |
0.1.0
JSON |
| download |
home_page | None |
Summary | Python library that transforms any string parser into a parser that skips portions of the input that contain syntax errors. |
upload_time | 2024-03-31 18:38:13 |
maintainer | None |
docs_url | None |
author | Andrei Lapets |
requires_python | >=3.7 |
license | MIT |
keywords |
|
VCS |
 |
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
=======
parsial
=======
Python library that transforms any string parser into a parser that skips portions of the input that contain syntax errors.
|pypi| |readthedocs| |actions| |coveralls|
.. |pypi| image:: https://badge.fury.io/py/parsial.svg#
:target: https://badge.fury.io/py/parsial
:alt: PyPI version and link.
.. |readthedocs| image:: https://readthedocs.org/projects/parsial/badge/?version=latest
:target: https://parsial.readthedocs.io/en/latest/?badge=latest
:alt: Read the Docs documentation status.
.. |actions| image:: https://github.com/reity/parsial/workflows/lint-test-cover-docs/badge.svg#
:target: https://github.com/reity/parsial/actions/workflows/lint-test-cover-docs.yml
:alt: GitHub Actions status.
.. |coveralls| image:: https://coveralls.io/repos/github/reity/parsial/badge.svg?branch=main
:target: https://coveralls.io/github/reity/parsial?branch=main
:alt: Coveralls test coverage summary.
Installation and Usage
----------------------
This library is available as a `package on PyPI <https://pypi.org/project/parsial>`__:
.. code-block:: bash
python -m pip install parsial
The library can be imported in the usual way:
.. code-block:: python
from parsial import parsial
Example
^^^^^^^
.. |parsial| replace:: ``parsial``
.. _parsial: https://parsial.readthedocs.io/en/0.1.0/_source/parsial.html#parsial.parsial.parsial
The |parsial|_ function accepts a parsing function (that takes a string input) and returns a new parsing function. This new function attempts to parse an input string using the original parsing function *even if parsing errors occur*. This is accomplished by selectively removing portions of the input that cause errors:
.. code-block:: python
>>> lines = [
... 'x = 123',
... 'y =',
... 'print(x)',
... 'z = x +',
... 'print(2 * x)'
... ]
>>> import ast
>>> parser = parsial(ast.parse)
>>> (a, slices) = parser('\\n'.join(lines))
>>> exec(compile(a, '', 'exec'))
123
246
.. |slice| replace:: ``slice``
.. _slice: https://docs.python.org/3/library/functions.html#slice
In addition to returning the result, the new function also returns a list of |slice|_ instances (one for each line found in the input string):
.. code-block:: python
>>> for s in slices:
... print(s)
slice(0, 7, None)
slice(0, 0, None)
slice(0, 8, None)
slice(0, 0, None)
slice(0, 12, None)
Each |slice|_ instance indicates what portion of the corresponding line in the input was included in the successful parsing attempt:
.. code-block:: python
>>> [l[s] for (l, s) in zip(lines, slices)]
['x = 123', '', 'print(x)', '', 'print(2 * x)']
Development
-----------
All installation and development dependencies are fully specified in ``pyproject.toml``. The ``project.optional-dependencies`` object is used to `specify optional requirements <https://peps.python.org/pep-0621>`__ for various development tasks. This makes it possible to specify additional options (such as ``docs``, ``lint``, and so on) when performing installation using `pip <https://pypi.org/project/pip>`__:
.. code-block:: bash
python -m pip install .[docs,lint]
Documentation
^^^^^^^^^^^^^
The documentation can be generated automatically from the source files using `Sphinx <https://www.sphinx-doc.org>`__:
.. code-block:: bash
python -m pip install .[docs]
cd docs
sphinx-apidoc -f -E --templatedir=_templates -o _source .. && make html
Testing and Conventions
^^^^^^^^^^^^^^^^^^^^^^^
All unit tests are executed and their coverage is measured when using `pytest <https://docs.pytest.org>`__ (see the ``pyproject.toml`` file for configuration details):
.. code-block:: bash
python -m pip install .[test]
python -m pytest
Alternatively, all unit tests are included in the module itself and can be executed using `doctest <https://docs.python.org/3/library/doctest.html>`__:
.. code-block:: bash
python src/parsial/parsial.py -v
Style conventions are enforced using `Pylint <https://pylint.readthedocs.io>`__:
.. code-block:: bash
python -m pip install .[lint]
python -m pylint src/parsial
Contributions
^^^^^^^^^^^^^
In order to contribute to the source code, open an issue or submit a pull request on the `GitHub page <https://github.com/reity/parsial>`__ for this library.
Versioning
^^^^^^^^^^
The version number format for this library and the changes to the library associated with version number increments conform with `Semantic Versioning 2.0.0 <https://semver.org/#semantic-versioning-200>`__.
Publishing
^^^^^^^^^^
This library can be published as a `package on PyPI <https://pypi.org/project/parsial>`__ by a package maintainer. First, install the dependencies required for packaging and publishing:
.. code-block:: bash
python -m pip install .[publish]
Ensure that the correct version number appears in ``pyproject.toml``, and that any links in this README document to the Read the Docs documentation of this package (or its dependencies) have appropriate version numbers. Also ensure that the Read the Docs project for this library has an `automation rule <https://docs.readthedocs.io/en/stable/automation-rules.html>`__ that activates and sets as the default all tagged versions. Create and push a tag for this version (replacing ``?.?.?`` with the version number):
.. code-block:: bash
git tag ?.?.?
git push origin ?.?.?
Remove any old build/distribution files. Then, package the source into a distribution archive:
.. code-block:: bash
rm -rf build dist src/*.egg-info
python -m build --sdist --wheel .
Finally, upload the package distribution archive to `PyPI <https://pypi.org>`__:
.. code-block:: bash
python -m twine upload dist/*
Raw data
{
"_id": null,
"home_page": null,
"name": "parsial",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": null,
"keywords": null,
"author": "Andrei Lapets",
"author_email": "a@lapets.io",
"download_url": "https://files.pythonhosted.org/packages/df/fa/4826d8b9651adbb96c9fd97f3b2c7dca57d4953f80a088385b8b53acefde/parsial-0.1.0.tar.gz",
"platform": null,
"description": "=======\r\nparsial\r\n=======\r\n\r\nPython library that transforms any string parser into a parser that skips portions of the input that contain syntax errors.\r\n\r\n|pypi| |readthedocs| |actions| |coveralls|\r\n\r\n.. |pypi| image:: https://badge.fury.io/py/parsial.svg#\r\n :target: https://badge.fury.io/py/parsial\r\n :alt: PyPI version and link.\r\n\r\n.. |readthedocs| image:: https://readthedocs.org/projects/parsial/badge/?version=latest\r\n :target: https://parsial.readthedocs.io/en/latest/?badge=latest\r\n :alt: Read the Docs documentation status.\r\n\r\n.. |actions| image:: https://github.com/reity/parsial/workflows/lint-test-cover-docs/badge.svg#\r\n :target: https://github.com/reity/parsial/actions/workflows/lint-test-cover-docs.yml\r\n :alt: GitHub Actions status.\r\n\r\n.. |coveralls| image:: https://coveralls.io/repos/github/reity/parsial/badge.svg?branch=main\r\n :target: https://coveralls.io/github/reity/parsial?branch=main\r\n :alt: Coveralls test coverage summary.\r\n\r\nInstallation and Usage\r\n----------------------\r\nThis library is available as a `package on PyPI <https://pypi.org/project/parsial>`__:\r\n\r\n.. code-block:: bash\r\n\r\n python -m pip install parsial\r\n\r\nThe library can be imported in the usual way:\r\n\r\n.. code-block:: python\r\n\r\n from parsial import parsial\r\n\r\nExample\r\n^^^^^^^\r\n\r\n.. |parsial| replace:: ``parsial``\r\n.. _parsial: https://parsial.readthedocs.io/en/0.1.0/_source/parsial.html#parsial.parsial.parsial\r\n\r\nThe |parsial|_ function accepts a parsing function (that takes a string input) and returns a new parsing function. This new function attempts to parse an input string using the original parsing function *even if parsing errors occur*. This is accomplished by selectively removing portions of the input that cause errors:\r\n\r\n.. code-block:: python\r\n\r\n >>> lines = [\r\n ... 'x = 123',\r\n ... 'y =',\r\n ... 'print(x)',\r\n ... 'z = x +',\r\n ... 'print(2 * x)'\r\n ... ]\r\n >>> import ast\r\n >>> parser = parsial(ast.parse)\r\n >>> (a, slices) = parser('\\\\n'.join(lines))\r\n >>> exec(compile(a, '', 'exec'))\r\n 123\r\n 246\r\n\r\n.. |slice| replace:: ``slice``\r\n.. _slice: https://docs.python.org/3/library/functions.html#slice\r\n\r\nIn addition to returning the result, the new function also returns a list of |slice|_ instances (one for each line found in the input string):\r\n\r\n.. code-block:: python\r\n\r\n >>> for s in slices:\r\n ... print(s)\r\n slice(0, 7, None)\r\n slice(0, 0, None)\r\n slice(0, 8, None)\r\n slice(0, 0, None)\r\n slice(0, 12, None)\r\n \r\nEach |slice|_ instance indicates what portion of the corresponding line in the input was included in the successful parsing attempt:\r\n\r\n.. code-block:: python\r\n\r\n >>> [l[s] for (l, s) in zip(lines, slices)]\r\n ['x = 123', '', 'print(x)', '', 'print(2 * x)']\r\n\r\nDevelopment\r\n-----------\r\nAll installation and development dependencies are fully specified in ``pyproject.toml``. The ``project.optional-dependencies`` object is used to `specify optional requirements <https://peps.python.org/pep-0621>`__ for various development tasks. This makes it possible to specify additional options (such as ``docs``, ``lint``, and so on) when performing installation using `pip <https://pypi.org/project/pip>`__:\r\n\r\n.. code-block:: bash\r\n\r\n python -m pip install .[docs,lint]\r\n\r\nDocumentation\r\n^^^^^^^^^^^^^\r\nThe documentation can be generated automatically from the source files using `Sphinx <https://www.sphinx-doc.org>`__:\r\n\r\n.. code-block:: bash\r\n\r\n python -m pip install .[docs]\r\n cd docs\r\n sphinx-apidoc -f -E --templatedir=_templates -o _source .. && make html\r\n\r\nTesting and Conventions\r\n^^^^^^^^^^^^^^^^^^^^^^^\r\nAll unit tests are executed and their coverage is measured when using `pytest <https://docs.pytest.org>`__ (see the ``pyproject.toml`` file for configuration details):\r\n\r\n.. code-block:: bash\r\n\r\n python -m pip install .[test]\r\n python -m pytest\r\n\r\nAlternatively, all unit tests are included in the module itself and can be executed using `doctest <https://docs.python.org/3/library/doctest.html>`__:\r\n\r\n.. code-block:: bash\r\n\r\n python src/parsial/parsial.py -v\r\n\r\nStyle conventions are enforced using `Pylint <https://pylint.readthedocs.io>`__:\r\n\r\n.. code-block:: bash\r\n\r\n python -m pip install .[lint]\r\n python -m pylint src/parsial\r\n\r\nContributions\r\n^^^^^^^^^^^^^\r\nIn order to contribute to the source code, open an issue or submit a pull request on the `GitHub page <https://github.com/reity/parsial>`__ for this library.\r\n\r\nVersioning\r\n^^^^^^^^^^\r\nThe version number format for this library and the changes to the library associated with version number increments conform with `Semantic Versioning 2.0.0 <https://semver.org/#semantic-versioning-200>`__.\r\n\r\nPublishing\r\n^^^^^^^^^^\r\nThis library can be published as a `package on PyPI <https://pypi.org/project/parsial>`__ by a package maintainer. First, install the dependencies required for packaging and publishing:\r\n\r\n.. code-block:: bash\r\n\r\n python -m pip install .[publish]\r\n\r\nEnsure that the correct version number appears in ``pyproject.toml``, and that any links in this README document to the Read the Docs documentation of this package (or its dependencies) have appropriate version numbers. Also ensure that the Read the Docs project for this library has an `automation rule <https://docs.readthedocs.io/en/stable/automation-rules.html>`__ that activates and sets as the default all tagged versions. Create and push a tag for this version (replacing ``?.?.?`` with the version number):\r\n\r\n.. code-block:: bash\r\n\r\n git tag ?.?.?\r\n git push origin ?.?.?\r\n\r\nRemove any old build/distribution files. Then, package the source into a distribution archive:\r\n\r\n.. code-block:: bash\r\n\r\n rm -rf build dist src/*.egg-info\r\n python -m build --sdist --wheel .\r\n\r\nFinally, upload the package distribution archive to `PyPI <https://pypi.org>`__:\r\n\r\n.. code-block:: bash\r\n\r\n python -m twine upload dist/*\r\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Python library that transforms any string parser into a parser that skips portions of the input that contain syntax errors.",
"version": "0.1.0",
"project_urls": {
"Documentation": "https://parsial.readthedocs.io",
"Repository": "https://github.com/reity/parsial"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "a8947d468bcd22d491db6c0651188278a8790fba5951784e03c618cba55f97bc",
"md5": "ec35b489f1e59627abef98e275ca2692",
"sha256": "b9911496b75e619f2c866f72567597d49aeef3aeb1a298f3a1328170407197f9"
},
"downloads": -1,
"filename": "parsial-0.1.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "ec35b489f1e59627abef98e275ca2692",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7",
"size": 5879,
"upload_time": "2024-03-31T18:38:11",
"upload_time_iso_8601": "2024-03-31T18:38:11.855676Z",
"url": "https://files.pythonhosted.org/packages/a8/94/7d468bcd22d491db6c0651188278a8790fba5951784e03c618cba55f97bc/parsial-0.1.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "dffa4826d8b9651adbb96c9fd97f3b2c7dca57d4953f80a088385b8b53acefde",
"md5": "57457e065c0a2a10b4189f7a935da334",
"sha256": "99126d3dd0fae6b349701a6e6e2855f32fd61839aeb81b25a6a0a93b6521d7d1"
},
"downloads": -1,
"filename": "parsial-0.1.0.tar.gz",
"has_sig": false,
"md5_digest": "57457e065c0a2a10b4189f7a935da334",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 5660,
"upload_time": "2024-03-31T18:38:13",
"upload_time_iso_8601": "2024-03-31T18:38:13.485646Z",
"url": "https://files.pythonhosted.org/packages/df/fa/4826d8b9651adbb96c9fd97f3b2c7dca57d4953f80a088385b8b53acefde/parsial-0.1.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-03-31 18:38:13",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "reity",
"github_project": "parsial",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "parsial"
}