Skip to main content

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 push and to).
  • 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 the text.
  • 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 the f combinator onto the stack.
  • to(f). Pops n elements from the stack and passes them as arguments to function f with arity n. The result is pushed back onto the stack.
  • group(f). Combines all elements pushed onto the stack by f into 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)

Source distribution for pecolib 0.0.2
File Size Uploaded
pecolib-0.0.2.tar.gz 5.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pecolib 0.0.2
File Interpreter ABI Platform
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

Release history Release notifications | RSS feed

This release

0.0.2 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page