Giter VIP home page Giter VIP logo

peglet's Introduction

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.

peglet's People

Contributors

darius avatar

Watchers

Alex Willmer avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.