parsita


Nameparsita JSON
Version 2.0.0 PyPI version JSON
download
home_pagehttps://github.com/drhagen/parsita
SummaryParser combinator library for Python
upload_time2023-06-23 10:10:26
maintainer
docs_urlNone
authorDavid Hagen
requires_python>=3.8.0,<4.0.0
licenseMIT
keywords text parsing parser combinator
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Parsita

[![Build status][build-image]][build-link]
[![Code coverage][coverage-image]][coverage-link]
[![Latest PyPI version][pypi-image]][pypi-link]
[![Supported Python versions][python-versions-image]][python-versions-link]

> The executable grammar of parsers combinators made available in the executable pseudocode of Python.

Parsita is a parser combinator library written in Python. Parser combinators provide an easy way to define a grammar using code so that the grammar itself effectively parses the source. They are not the fastest at parsing, but they are the easiest to write.

Like all good parser combinator libraries, Parsita abuses operators to provide a clean grammar-like syntax. The `__or__` method is defined so that `|` tests between two alternatives. The `__and__` method is defined so that `&` tests two parsers in sequence. Other operators are used as well.

In a technique that I think is new to Python, Parsita uses metaclass magic to allow for forward declarations of values. This is important for parser combinators because grammars are often recursive or mutually recursive, meaning that some components must be used in the definition of others before they themselves are defined.

See the [Documentation](https://parsita.drhagen.com) for the full user guide.

## Installation

The recommended means of installation is with `pip` from PyPI.

```shell
pip install parsita
```

## Hello world

The following is a very basic parser for extracting the name from a `Hello, {name}!` string.

```python
from parsita import *

class HelloWorldParsers(ParserContext, whitespace=r'[ ]*'):
    hello_world = lit('Hello') >> ',' >> reg(r'[A-Z][a-z]*') << '!'

# A successful parse produces the parsed value
name = HelloWorldParsers.hello_world.parse('Hello, David!').unwrap()
assert name == 'David'

# A parsing failure produces a useful error message
name = HelloWorldParsers.hello_world.parse('Hello David!').unwrap()
# parsita.state.ParseError: Expected ',' but found 'David'
# Line 1, character 7
#
# Hello David!
#       ^
```

[build-image]: https://github.com/drhagen/parsita/workflows/python/badge.svg?branch=master&event=push
[build-link]: https://github.com/drhagen/parsita/actions?query=branch%3Amaster+event%3Apush
[coverage-image]: https://codecov.io/github/drhagen/parsita/coverage.svg?branch=master
[coverage-link]: https://codecov.io/github/drhagen/parsita?branch=master
[pypi-image]: https://img.shields.io/pypi/v/parsita.svg
[pypi-link]: https://pypi.python.org/pypi/parsita
[python-versions-image]: https://img.shields.io/pypi/pyversions/parsita.svg
[python-versions-link]: https://pypi.python.org/pypi/parsita

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/drhagen/parsita",
    "name": "parsita",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8.0,<4.0.0",
    "maintainer_email": "",
    "keywords": "text,parsing,parser,combinator",
    "author": "David Hagen",
    "author_email": "david@drhagen.com",
    "download_url": "https://files.pythonhosted.org/packages/71/0f/805bcd4f911a3835dbc62c5455f3731698a09581895b005e338f0abd2488/parsita-2.0.0.tar.gz",
    "platform": null,
    "description": "# Parsita\n\n[![Build status][build-image]][build-link]\n[![Code coverage][coverage-image]][coverage-link]\n[![Latest PyPI version][pypi-image]][pypi-link]\n[![Supported Python versions][python-versions-image]][python-versions-link]\n\n> The executable grammar of parsers combinators made available in the executable pseudocode of Python.\n\nParsita is a parser combinator library written in Python. Parser combinators provide an easy way to define a grammar using code so that the grammar itself effectively parses the source. They are not the fastest at parsing, but they are the easiest to write.\n\nLike all good parser combinator libraries, Parsita abuses operators to provide a clean grammar-like syntax. The `__or__` method is defined so that `|` tests between two alternatives. The `__and__` method is defined so that `&` tests two parsers in sequence. Other operators are used as well.\n\nIn a technique that I think is new to Python, Parsita uses metaclass magic to allow for forward declarations of values. This is important for parser combinators because grammars are often recursive or mutually recursive, meaning that some components must be used in the definition of others before they themselves are defined.\n\nSee the [Documentation](https://parsita.drhagen.com) for the full user guide.\n\n## Installation\n\nThe recommended means of installation is with `pip` from PyPI.\n\n```shell\npip install parsita\n```\n\n## Hello world\n\nThe following is a very basic parser for extracting the name from a `Hello, {name}!` string.\n\n```python\nfrom parsita import *\n\nclass HelloWorldParsers(ParserContext, whitespace=r'[ ]*'):\n    hello_world = lit('Hello') >> ',' >> reg(r'[A-Z][a-z]*') << '!'\n\n# A successful parse produces the parsed value\nname = HelloWorldParsers.hello_world.parse('Hello, David!').unwrap()\nassert name == 'David'\n\n# A parsing failure produces a useful error message\nname = HelloWorldParsers.hello_world.parse('Hello David!').unwrap()\n# parsita.state.ParseError: Expected ',' but found 'David'\n# Line 1, character 7\n#\n# Hello David!\n#       ^\n```\n\n[build-image]: https://github.com/drhagen/parsita/workflows/python/badge.svg?branch=master&event=push\n[build-link]: https://github.com/drhagen/parsita/actions?query=branch%3Amaster+event%3Apush\n[coverage-image]: https://codecov.io/github/drhagen/parsita/coverage.svg?branch=master\n[coverage-link]: https://codecov.io/github/drhagen/parsita?branch=master\n[pypi-image]: https://img.shields.io/pypi/v/parsita.svg\n[pypi-link]: https://pypi.python.org/pypi/parsita\n[python-versions-image]: https://img.shields.io/pypi/pyversions/parsita.svg\n[python-versions-link]: https://pypi.python.org/pypi/parsita\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Parser combinator library for Python",
    "version": "2.0.0",
    "project_urls": {
        "Documentation": "https://parsita.drhagen.com",
        "Homepage": "https://github.com/drhagen/parsita",
        "Repository": "https://github.com/drhagen/parsita"
    },
    "split_keywords": [
        "text",
        "parsing",
        "parser",
        "combinator"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "7d502f2e8df1af7f1a10531d5eb4a541eda0d22252bf6ac772b6cb27c26ecf2a",
                "md5": "cca41837e4437cd25b41d0733e864d5b",
                "sha256": "17e1b35c53e62ba59a8aade88edd363656ca670ae6ef83f746ae93c0eb423d1b"
            },
            "downloads": -1,
            "filename": "parsita-2.0.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "cca41837e4437cd25b41d0733e864d5b",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8.0,<4.0.0",
            "size": 26109,
            "upload_time": "2023-06-23T10:10:25",
            "upload_time_iso_8601": "2023-06-23T10:10:25.418976Z",
            "url": "https://files.pythonhosted.org/packages/7d/50/2f2e8df1af7f1a10531d5eb4a541eda0d22252bf6ac772b6cb27c26ecf2a/parsita-2.0.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "710f805bcd4f911a3835dbc62c5455f3731698a09581895b005e338f0abd2488",
                "md5": "10cbfa62e15a19a9defa29e09cdf3eb1",
                "sha256": "370cec69a8cfb1bcf33b44566a483318e6ff5f62c598034d6de37ed8378330ee"
            },
            "downloads": -1,
            "filename": "parsita-2.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "10cbfa62e15a19a9defa29e09cdf3eb1",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8.0,<4.0.0",
            "size": 17859,
            "upload_time": "2023-06-23T10:10:26",
            "upload_time_iso_8601": "2023-06-23T10:10:26.849428Z",
            "url": "https://files.pythonhosted.org/packages/71/0f/805bcd4f911a3835dbc62c5455f3731698a09581895b005e338f0abd2488/parsita-2.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-06-23 10:10:26",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "drhagen",
    "github_project": "parsita",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "parsita"
}
        
Elapsed time: 0.09347s