Exciting Parsing with SimpleParse

Christian Wyglendowski

Credentials (or lack thereof)

Python Parser Generators

About SimpleParse

  • Top-Down Recursive Descent Parser
  • Single Pass (no token generating stage)
  • Built on mxTextTools
  • Written by Michael Fletcher
  • http://simpleparse.sourceforge.net

Why SimpleParse?

Clean API

  • Separation of grammar, parser and post-processor
  • Defining multiple processors for the same grammar is easy
  • Look how nice!
  • parser = Parser(grammar)
    result = parser.parse(src, processor=myprocessor)
    

Nice and Fast!

Fine Grained Control

  • Top-down parsers give you more control
  • assign := name, '=', value
    
  • Complete control at both the tagging and post-processing stages
  • Can utilize raw mxTextTools tag tables if required

Feels Pythonic

  • It just does!
  • Mostly in comparison to the competition
  • i.e. no auxillary file creation

Drawbacks

Python-Like "if" Statement

file      := if_stmt+
if_stmt   := 'if', ts, boolexpr, ts, ':', ts, suite
def_stmt  := 'def', ts, 'foo()', ts, ':', ts, suite
>ts<      := [ \t]*
boolexpr  := atom, ts, '=='/'!='/'>='/'<=', ts, atom
suite     := '\n', indent, stmt+, dedent
atom      := number/string
indent    := '\017'
dedent    := '\016'
stmt      := if_stmt/def_stmt/atom_stmt
atom_stmt := atom, ts, '\n'

Short Demo

That's All Folks

The End