Skip to main content

Robinson Crusoe's parsing package.

Project description

Peglet

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

  1. pleasant enough to use;
  2. simple to adapt or rewrite from scratch if I’m faced with some new situation like a new programming language;
  3. with code easy enough to follow that it could introduce people to parsing.

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.

Installing it

pip install peglet, or else download then python setup.py install.

Project details


Download files

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

Files for Peglet, version 0.1.1
Filename, size File type Python version Upload date Hashes
Filename, size Peglet-0.1.1.cygwin-1.7.17-i686.exe (60.9 kB) File type Windows Installer Python version any Upload date Hashes View hashes
Filename, size Peglet-0.1.1.tar.gz (31.3 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page