peco
This is a tiny (100 LOC) parser combinator library in Python.
No installation needed, just add peco.py to your project.
Main features:
- Combined lexical and syntactic parsing using the PEG formalism.
- Lexical rules with regular expressions (see
eat). - Stack-based implementation of semantic actions (see
pushandto). - Selective memoization for performance (see
memo). - Support for left recursion (see
left).
Parsers are built from combinators and operate on a Peco namedtuple:
text: str. Source text.pos: int. Position in thetext.ok: bool. Parsing result.stack: tuple | None. Semantic result stack.glob: dict. Global data, including the error position field (err).
Most combinators follow PEG constructs:
empty. Empty string.seq. Sequence.alt. Ordered choice.many. Zero-or-more.some. One-or-more.opt. Optional.peek. And-predicate.npeek. Not-predicate.
Support for semantic actions:
push(f). Pushes a text fragment parsed by thefcombinator onto thestack.to(f). Popsnelements from thestackand passes them as arguments to functionfwith arityn. The result is pushed back onto thestack.group(f). Combines all elements pushed onto thestackbyfinto a single tuple.
For examples of using peco's combinators, see the tests.
Metadata
Release files for pecolib 0.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pecolib-0.0.2.tar.gz | 5.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pecolib-0.0.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 13.2 kB
Release files / pecolib-0.0.2.tar.gz
| Download URL | pecolib-0.0.2.tar.gz |
|---|---|
| Size | 5.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e710c7be173ba60b9c1b80f8939780233f3719decbb6e34f9e457168cf66b053
|
|
BLAKE2b-256 checksum How to use checksums |
28f3ee2ac15c24069db6eda612518c0ed0b5ce34ddcbcd498a5b626b4ec9c70f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.1
|
Release files / pecolib-0.0.2-py3-none-any.whl
| Download URL | pecolib-0.0.2-py3-none-any.whl |
|---|---|
| Size | 8.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5dfdd1d07a3a4d1dc0b4bf5461ac5cd23a0f49a95bf816d362882a91979ee2d5
|
|
BLAKE2b-256 checksum How to use checksums |
528eb02007d2a4a02a516986766ba3336c4c1915ef855418407b6667f813a1d3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.1
|