Skip to main content

PPeg is a pattern matching library for Python, based on Parsing Expression Grammars (PEGs). It’s a port of the LPeg library from Lua.

Usage

Unlike the re module [1], PPeg patterns can handle balanced sequences

>>> from _ppeg import Pattern as P
>>> pattern = P.Grammar('(' + ( (P(1)-P.Set('()')) | P.Var(0) )**0 + ')')
>>> pattern('(foo(bar()baz))').pos
15
>>> pattern('(foo(bar(baz)').pos
-1
>>> capture = P.Cap(pattern)
>>> capture('(foo(bar()baz))').captures
['(foo(bar()baz))']

This example corresponds roughly to the following LPeg example

> lpeg = require "lpeg"
> pattern = lpeg.P{ "(" * ((1 - lpeg.S"()") + lpeg.V(1))^0 * ")" }
> pattern:match("(foo(bar()baz))") -- Lua indexes begin at 1
16
> pattern:match("(foo(bar(baz)")
nil
> capture = lpeg.C(pattern)
> capture:match("(foo(bar()baz))")
"(foo(bar()baz))"

Modules

  • _cpeg.c

  • _ppeg.c
    • includes lpeg.c

Metadata

Release files for PPeg 0.9.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for PPeg 0.9.4
File Size Uploaded
PPeg-0.9.4.tar.gz 46.6 kB Details

Release files / PPeg-0.9.4.tar.gz

Download URL PPeg-0.9.4.tar.gz
Size 46.6 kB
Tags Source
SHA-256 checksum
How to use checksums
674632f08c4a1f2f9515a1080c7d5814dae5f3d44c2522df469345e9374c11f0
BLAKE2b-256 checksum
How to use checksums
4d5dbe7be7c5219051df1f4afdbdbf48bd4ed90a87cbcfd39942e02f1f82a307
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.9.4 This release

1 release file

0.9.3

1 release file

0.9.2

1 release file

0.9.1

1 release file

0.9

1 release file

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