Skip to main content

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 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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pecolib-0.0.2.tar.gz (5.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pecolib-0.0.2-py3-none-any.whl (8.2 kB view details)

Uploaded Python 3

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

Hashes for pecolib-0.0.2.tar.gz
Algorithm Hash digest
SHA256 e710c7be173ba60b9c1b80f8939780233f3719decbb6e34f9e457168cf66b053
MD5 1a55955b263cce056ed0ead63b830873
BLAKE2b-256 28f3ee2ac15c24069db6eda612518c0ed0b5ce34ddcbcd498a5b626b4ec9c70f

See more details on using hashes here.

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

Hashes for pecolib-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 5dfdd1d07a3a4d1dc0b4bf5461ac5cd23a0f49a95bf816d362882a91979ee2d5
MD5 7a608d853f384accaa0b2221e6877cd7
BLAKE2b-256 528eb02007d2a4a02a516986766ba3336c4c1915ef855418407b6667f813a1d3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page