Parser combinator library for Python
Project description
Parsita
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 for the full user guide.
Installation
The recommended means of installation is with pip
from PyPI.
pip install parsita
Hello world
The following is a very basic parser for extracting the name from a Hello, {name}!
string.
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!
# ^
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file parsita-2.2.0.tar.gz
.
File metadata
- Download URL: parsita-2.2.0.tar.gz
- Upload date:
- Size: 19.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6976cb4944080c3ad23d4ccf797060da46aec933fde4f705fb6b3923d9c6f2fa |
|
MD5 | 2c76517fb6efe5ea3a6a66ebd927e0ea |
|
BLAKE2b-256 | 67f925656f7f3b5fac688bed028b74bbe8757eb0912577899f63847e63635093 |
Provenance
The following attestation bundles were made for parsita-2.2.0.tar.gz
:
Publisher:
release.yml
on drhagen/parsita
-
Statement type:
https://in-toto.io/Statement/v1
- Predicate type:
https://docs.pypi.org/attestations/publish/v1
- Subject name:
parsita-2.2.0.tar.gz
- Subject digest:
6976cb4944080c3ad23d4ccf797060da46aec933fde4f705fb6b3923d9c6f2fa
- Sigstore transparency entry: 150380460
- Sigstore integration time:
- Predicate type:
File details
Details for the file parsita-2.2.0-py3-none-any.whl
.
File metadata
- Download URL: parsita-2.2.0-py3-none-any.whl
- Upload date:
- Size: 28.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e0ba8f9867aa413dd3c1ba9104cf9003b2981dc44ac777cf33e78c82bcc02bc9 |
|
MD5 | 2b0442084bc4193fc2bb215fd5d6db33 |
|
BLAKE2b-256 | 34a0865dd936d655b9d6283468ef4c2d236c255737160d988a25b2773cf73c13 |
Provenance
The following attestation bundles were made for parsita-2.2.0-py3-none-any.whl
:
Publisher:
release.yml
on drhagen/parsita
-
Statement type:
https://in-toto.io/Statement/v1
- Predicate type:
https://docs.pypi.org/attestations/publish/v1
- Subject name:
parsita-2.2.0-py3-none-any.whl
- Subject digest:
e0ba8f9867aa413dd3c1ba9104cf9003b2981dc44ac777cf33e78c82bcc02bc9
- Sigstore transparency entry: 150380462
- Sigstore integration time:
- Predicate type: