Peglet extends Python's regular expressions to handle recursive grammars. For example, to parse a tiny subset of HTML:
>>> from peglet import Parser >>> a_little_html = Parser(r"""parts = part parts | ... part = <(\w+)> parts </\w+> group ... | ([^<]+) ... """, group=lambda *values: values) >>> a_little_html("Hello. <p><em>Nesting</em> for <i>the win</i>.</p>") ('Hello. ', ('p', ('em', 'Nesting'), ' for ', ('i', 'the win'), '.'))
The goal was to make a parsing library
So it came down to one page of clear code not using combinators. (And then ballooned to 200+ lines from documentation and a few extras.) Some bits that couldn't fit the latter two constraints went into a combinator library, parson.
For more, see the examples or the module doc in the code. Other programs using this include bicicleta.py and .js, a logic puzzle solver, and the lexer for unitcalc.
pip install peglet
, or else download then python setup.py install
.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4