sn6uv / rply

An attempt to port David Beazley's PLY to RPython, and give it a cooler API.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

RPLY

image

Welcome to RPLY! A pure python parser generator, that also works with RPython. It is a more-or-less direct port of David Beazley's awesome PLY, with a new public API, and RPython support.

You can find the documentation online.

Basic API:

Then you can do:

You can also substitute your own lexer. A lexer is an object with a next() method that returns either the next token in sequence, or None if the token stream has been exhausted.

Why do we have the boxes?

In RPython, like other statically typed languages, a variable must have a specific type, we take advantage of polymorphism to keep values in a box so that everything is statically typed. You can write whatever boxes you need for your project.

If you don't intend to use your parser from RPython, and just want a cool pure Python parser you can ignore all the box stuff and just return whatever you like from each production method.

Error handling

By default, when a parsing error is encountered, an rply.ParsingError is raised, it has a method getsourcepos(), which returns an rply.token.SourcePosition object.

You may also provide an error handler, which, at the moment, must raise an exception. It receives the Token object that the parser errored on.

Python compatibility

RPly is tested and known to work under Python 2.6, 2.7, 3.1, and 3.2. It is also valid RPython for PyPy checkouts from 6c642ae7a0ea onwards.

About

An attempt to port David Beazley's PLY to RPython, and give it a cooler API.

License:BSD 3-Clause "New" or "Revised" License


Languages

Language:Python 85.6%Language:Shell 7.3%Language:Makefile 7.1%