Metadata-Version: 2.4
Name: pPEGpy
Version: 0.3.2
Summary: pPEG -- portable PEG in Python
Author-email: Peter Cashin <cashin.peter@gmail.com>
License-File: LICENSE
Requires-Python: >=3.12
Description-Content-Type: text/markdown

# 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

``` py
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:

``` py    
    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:

``` py
    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/)

---

[pPEG]: https://github.com/pcanz/pPEG
