# Parsita
[![Build status](https://github.com/drhagen/parsita/workflows/ci/badge.svg)](https://github.com/drhagen/parsita/actions/workflows/ci.yml)
[![Code coverage](https://codecov.io/github/drhagen/parsita/coverage.svg?branch=master)](https://codecov.io/github/drhagen/parsita?branch=master)
[![Latest PyPI version](https://img.shields.io/pypi/v/parsita.svg)](https://pypi.python.org/pypi/parsita)
[![License](https://img.shields.io/pypi/l/parsita.svg)](https://github.com/drhagen/parsita/blob/master/LICENSE)
[![Supported Python versions](https://img.shields.io/pypi/pyversions/parsita.svg)](https://pypi.python.org/pypi/parsita)
[![Black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://black.readthedocs.io)
[![Poetry](https://img.shields.io/endpoint?url=https://python-poetry.org/badge/v0.json)](https://python-poetry.org)
[![Nox](https://img.shields.io/badge/%F0%9F%A6%8A-Nox-D85E00.svg)](https://nox.thea.codes)
[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://beta.ruff.rs)
> 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!
# ^
```
Raw data
{
"_id": null,
"home_page": "https://github.com/drhagen/parsita",
"name": "parsita",
"maintainer": null,
"docs_url": null,
"requires_python": "<4.0,>=3.9",
"maintainer_email": null,
"keywords": "text, parsing, parser, combinator",
"author": "David Hagen",
"author_email": "david@drhagen.com",
"download_url": "https://files.pythonhosted.org/packages/65/99/3de12a89a2405b8af30872b325262650f8963119d9916080ca3111712325/parsita-2.2.1.tar.gz",
"platform": null,
"description": "# Parsita\n\n[![Build status](https://github.com/drhagen/parsita/workflows/ci/badge.svg)](https://github.com/drhagen/parsita/actions/workflows/ci.yml)\n[![Code coverage](https://codecov.io/github/drhagen/parsita/coverage.svg?branch=master)](https://codecov.io/github/drhagen/parsita?branch=master)\n[![Latest PyPI version](https://img.shields.io/pypi/v/parsita.svg)](https://pypi.python.org/pypi/parsita)\n[![License](https://img.shields.io/pypi/l/parsita.svg)](https://github.com/drhagen/parsita/blob/master/LICENSE)\n[![Supported Python versions](https://img.shields.io/pypi/pyversions/parsita.svg)](https://pypi.python.org/pypi/parsita)\n[![Black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://black.readthedocs.io)\n[![Poetry](https://img.shields.io/endpoint?url=https://python-poetry.org/badge/v0.json)](https://python-poetry.org)\n[![Nox](https://img.shields.io/badge/%F0%9F%A6%8A-Nox-D85E00.svg)](https://nox.thea.codes)\n[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://beta.ruff.rs)\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",
"bugtrack_url": null,
"license": "MIT",
"summary": "Parser combinator library for Python",
"version": "2.2.1",
"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": "933e9bc53169e8a93a6d5ea11153f822b11c65d536f5d85b128d5eb786ccd279",
"md5": "b2847eb21620878469f2acc5bf8d3f46",
"sha256": "98d7ca010965cda38a5322af74b4225f8876b3085aa159814875eaa846d108f1"
},
"downloads": -1,
"filename": "parsita-2.2.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "b2847eb21620878469f2acc5bf8d3f46",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.9",
"size": 28999,
"upload_time": "2024-11-26T19:24:08",
"upload_time_iso_8601": "2024-11-26T19:24:08.515388Z",
"url": "https://files.pythonhosted.org/packages/93/3e/9bc53169e8a93a6d5ea11153f822b11c65d536f5d85b128d5eb786ccd279/parsita-2.2.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "65993de12a89a2405b8af30872b325262650f8963119d9916080ca3111712325",
"md5": "2fc630b949797c2f31ad440afa2146f1",
"sha256": "054f6a20a82b890ed3c9201e773c7c53565db443b922804d7d6e8f8ca03c4fdd"
},
"downloads": -1,
"filename": "parsita-2.2.1.tar.gz",
"has_sig": false,
"md5_digest": "2fc630b949797c2f31ad440afa2146f1",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.9",
"size": 20254,
"upload_time": "2024-11-26T19:24:10",
"upload_time_iso_8601": "2024-11-26T19:24:10.461517Z",
"url": "https://files.pythonhosted.org/packages/65/99/3de12a89a2405b8af30872b325262650f8963119d9916080ca3111712325/parsita-2.2.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-11-26 19:24:10",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "drhagen",
"github_project": "parsita",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "parsita"
}