pPEG -- portable PEG in Python
Project description
pPEGpy
This is an implementation of pPEG in Python.
The package pPEGpy was created with: uv init --lib
from pPEGpy import peg
The peg.py file (in src/pPEGpy) is a module with no dependencies.
Example
from pPEGpy import peg
# Equivalent to the regular expression for well-formed URI's in RFC 3986.
pURI = pPEG.compile("""
URI = (scheme ':')? ('//' auth)? path ('?' query)? ('#' frag)?
scheme = ~[:/?#]+
auth = ~[/?#]*
path = ~[?#]*
query = ~'#'*
frag = ~[ \t\n\r]*
""")
if not pURI.ok: raise Exception("URI grammar error: "+pURI.err)
test = "http://www.ics.uci.edu/pub/ietf/uri/#Related";
uri = pURI.parse(test)
if uri.ok: print(uri.ptree)
else: print(uri.err)
"""
["URI",[["scheme","http"],["auth","www.ics.uci.edu"],["path","/pub/ietf/uri/"],["frag","Related"]]]
"""
Usage
The pPEG.py implementation is a single file with no dependencies.
Put a copy of the pPEG.py file into the same directory as your application, or use a PYTHONPATH shell environment variable for Python to load the pPEG.py module.
Not yet available for pip install.
Basic usage:
import pPEG
my_parser = pPEG.compile(""... my grammar rules...""")
# For the grammar rules see the [pPEG] documentation, then:
my_parse = my_parser.parse(""...input string...")
print(my_parse) # prints the ptree result or an error message
Common usage:
import pPEG
my_parser = pPEG.compile(""... my grammar rules...""")
if not my_parser.ok: raise Exception(my_parser.err)
# -- use my-parser in my application .......
my_parse = my_parser.parse('...input string...}')
if not my_parse.ok:
print(my_parse.err)
.... handle parse failure ...
else:
process(my_parse.ptree)
The ptree parse tree type is JSON data, as defined in pPEG.
Notes
The uv init --lib made the project name lower case ppegpy, I editied the name back to pPEGpy in several places (.toml, src/pPEGpy/)
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 ppegpy-0.3.2.tar.gz.
File metadata
- Download URL: ppegpy-0.3.2.tar.gz
- Upload date:
- Size: 19.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d7b2ad0bcc07c4fde56dbdceaf6b9bb5d408ebb74766d9978aac9ee25e3446fa
|
|
| MD5 |
16e7804c791797707538dee0626195b5
|
|
| BLAKE2b-256 |
2db381b2f7e95eb8b7ecdec2308ed2333956e247d774df4fcc1d465ebdadf5a4
|
File details
Details for the file ppegpy-0.3.2-py3-none-any.whl.
File metadata
- Download URL: ppegpy-0.3.2-py3-none-any.whl
- Upload date:
- Size: 9.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
886f3c729d54f77abb736e5d1afa4fe985ecf348887ae1313b4c3e19a9c7e064
|
|
| MD5 |
3868043b7c1329b667c99564df7840db
|
|
| BLAKE2b-256 |
7b1c36d6887e8a7cc94d91ae2beca0373d004170ba1f3d6c00102b46b595fedc
|