Tiny parser combinators library
Project description
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.
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pecolib-0.0.2.tar.gz.
File metadata
- Download URL: pecolib-0.0.2.tar.gz
- Upload date:
- Size: 5.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e710c7be173ba60b9c1b80f8939780233f3719decbb6e34f9e457168cf66b053
|
|
| MD5 |
1a55955b263cce056ed0ead63b830873
|
|
| BLAKE2b-256 |
28f3ee2ac15c24069db6eda612518c0ed0b5ce34ddcbcd498a5b626b4ec9c70f
|
File details
Details for the file pecolib-0.0.2-py3-none-any.whl.
File metadata
- Download URL: pecolib-0.0.2-py3-none-any.whl
- Upload date:
- Size: 8.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5dfdd1d07a3a4d1dc0b4bf5461ac5cd23a0f49a95bf816d362882a91979ee2d5
|
|
| MD5 |
7a608d853f384accaa0b2221e6877cd7
|
|
| BLAKE2b-256 |
528eb02007d2a4a02a516986766ba3336c4c1915ef855418407b6667f813a1d3
|