Skip to content
Paul McGuire edited this page Aug 21, 2021 · 3 revisions

Zen of Pyparsing

  • Don't clutter up the parser grammar with whitespace, just handle it! (likewise for comments)
  • Class names are easier to read and understand than specialized typography
  • Use operators to implement an embedded parsing DSL:
    • + for And
    • | for MatchFirst
    • ^ for Or
    • ~ for NotAny
    • & for Each (like And, but accepting out of order)
    • - for And with no backtracking
    • << and <<= for Forward
    • ... for SkipTo
    • [...] for ZeroOrMore
  • Simple grammars can return lists; complex grammars need named results
  • Parsers can do more than just tokenize

Zen of Pyparsing Development

  • Grammars should be:
    • easy (and quick) to write
    • easy to read
    • easy to update
  • No separate code-generation step (like lex/yacc)
  • No forced naming conventions (like PLY)
  • Stay Pure Python
  • Liberally licensed (MIT license – free for commercial use)