Yet another PEG parser combinator library
Python C Shell
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
eg_ebnf extract gen_kinds May 6, 2018
eg_itsy
.gitignore
README.md
combinator_grammars.py
eg_basic.py
eg_bicicleta.py
eg_calc.py
eg_calc_compile.py
eg_calc_to_rpn.py
eg_fp.py
eg_json.py
eg_linear_equations.py fnordify example Jul 6, 2016
eg_metapeg.py add fnords Jun 8, 2016
eg_microses.py start of microses Jun 21, 2016
eg_misc.py
eg_mutagen_from_js.py
eg_oberon0.py
eg_oberon0_with_lexer.py
eg_outline.py
eg_pother.py
eg_precedence.py
eg_puzzler.py
eg_regex.py
eg_roman.py
eg_templite.py
eg_trees.py
eg_url.py
eg_wc.py
microses.py
parson.py
peg.py
peglet_to_parson.py
pegvm.py
setup.py
structs.py
testsmoke.py
treepeg.py fix: chain(x, succeed) should always == x Dec 8, 2012

README.md

parson

Yet another PEG parser combinator library in Python. Selling points:

  • The optional concrete syntax for grammars incorporates semantic actions in a concise host-language-independent way. A Parson grammar won't tie you to Python.

  • Whole grammars can be analyzed and compiled, even if built at runtime using combinators. (Contrast with a monadic library, where this is uncomputable.)

  • Semantic actions take and return values in a kind of point-free style.

  • You can use the concrete syntax with about as little ceremony as re.match.

  • You can parse non-string sequences.

Anti-selling points:

  • This library's in fluid design still, undocumented, utterly untuned, etc. I'd like you to use it if you think you might give feedback on the design; otherwise, no promises.

  • Semantic actions work in a nontraditional way that may remind you of Forth and which I haven't yet tried to make play well in typed languages like Haskell. It's concise and just right for parsing, but maybe in the end it'll turn out too cute and make me rip it out if I want this to be used.

  • I don't intend to make grammars work in other host languages before the design settles. (I have done this a bit for the Peglet library, a more basic and settled expression of the same approach to actions: it has Python and JavaScript ports.)

I guess the most similar library out there is LPEG, and that's way way more polished.

Examples

For now, see all the eg_whatever.py files here. eg_calc.py, eg_misc.py, eg_wc.py, and eg_regex.py have the smallest ones. eg_trees.py shows parsing of tree structures, OMeta-style. Other examples include programming languages and other somewhat-bigger stuff.

Basic things still to explain:

  • grammar syntax
  • combinators
  • recursion with combinators
  • actions

Examples of where I've used it for more than examples:

  • IDEAL, a drawing language
  • Linogram, also a drawing language
  • Pythological, a MiniKanren with a vaguely Prologish frontend
  • tinyhiss -- Smalltalkish
  • Squee, an experimental language not much like any others
  • Toot, a tutorial on writing a bytecode compiler