.center.middle # Funcparserlib ### Functional parsing library Andrey Vlasovskikh --- # Background * Parsing little languages, external DSLs * Competitors: Pyparsing, PLY, Parsley * Why * Pyparsing API is too large * Funcparserlib API is just ~10 functions * Milestones * Started in 2009 * Latest: 0.3.6, May 2013 --- # Parsing combinators API * The idea from functional programming * OCaml, Haskell, etc. .python +--------------------------------------------+----------+ | | | | p1 + p2 p1 | p2 p >> f | | | | | | many(p) maybe(p) skip(p) | | | | Parser | +--------------------------------------------+ | | | | | some(pred) forward_decl() finished | | | | | +--------------------------------------------+----------+ --- # Example: S-exp parser (1) * Symbols and lists .no-highlight some-symbol (and (this is (a nested s-exp)) (the end)) --- # Example: S-exp parser (2) def tokenize(s): ... def parse(s): sym_token = some(lambda t: t.type == 'sym') symbol = sym_token >> (lambda t: t.value) list = forward_decl() expr = symbol | list list.define(skip(op('(')) + many(expr) + skip(op(')'))) return expr.parse(tokenize(s)) def op(value): return some(lambda t: t.type == 'op' and t.value == value) --- # Code size .no-highlight .we[## Funcparserlib 590] ########### Parsley 2863 ############## Pyparsing 3604 ##################### PLY 5369 * LOC without tests, examples, etc. --- # Performance .no-highlight 10KB 50KB 100KB 500KB ------------------------------------------- PLY 29 162 328 1731 .we[Funcparserlib 28 166 342 1816] Pyparsing 64 379 782 4090 Parsley 668 4063 8614 n/a * JSON parsing time (ms), easy to compare * Official examples: Funcparserlib, Pyparsing, Parsley * They all are 100 times slower than C --- # Popularity :( .no-highlight ############################################ Pyparsing 201K ######### PLY 55K .we[# Funcparserlib 8K] # Parsley 2K * Downloads from PyPI last month --- .center.middle # Funcparserlib For more details visit # [pirx.ru](http://pirx.ru/)