Package: pushdown
Pushdown - a modern parsing library for PythonThis project is a fork fromhttps://github.com/lark-parser/lark,
and the new name transition still in progress.
Then,
until this process is complete,
you should see the nameLarkseveral places.Parse any context-free grammar, FAST and EASY!Beginners:
Lark is not just another parser.
It can parse any grammar you throw at it,
no matter how complicated or ambiguous,
and do so efficiently.
It also constructs a parse-tree for you,
without additional code on your part.Experts:
Lark lets you choose between Earley and LALR(1),
to trade-off power and speed.
It also contains a CYK parser and unique features such as a contextual-lexer.Lark can:Parse all context-free grammars, and handle all ambiguityBuild a parse-tree automagically, no construction code requiredOutperform all other Python libraries when using LALR(1) (Yes, including PLY)Run on every Python interpreter (it's pure-python)Generate a stand-alone parser (for LALR(1) grammars)And many more features. Read ahead and find out.Most importantly,
Lark will save you time and prevent you from getting parsing headaches.Quick linksTutorialfor writing a JSON parser.Install pushdown$ pip install pushdownPushdown has no dependencies.Syntax Highlighting (new)Lark now provides syntax highlighting for its grammar files (*.lark):Sublime Text & TextMateHello WorldHere is a little program to parse "Hello, World!" (Or any other similar phrase):fromlarkimportLarkl=Lark('''start: WORD "," WORD "!"%import common.WORD   // imports from terminal library%ignore " "           // Disregard spaces in text''')print(l.parse("Hello, World!"))And the output is:Tree(start,[Token(WORD,'Hello'),Token(WORD,'World')])Notice punctuation doesn't appear in the resulting tree. It's automatically filtered away by Lark.Fruit flies like bananasLark is great at handling ambiguity. Let's parse the phrase "fruit flies like bananas":See moreexamples in the wikiList of main featuresBuilds a parse-tree (AST) automagically, based on the structure of the grammarEarleyparserCan parse all context-free grammarsFull support for ambiguous grammarsLALR(1)parserFast and light, competitive with PLYCan generate a stand-alone parserCYKparser, for highly ambiguous grammars (NEW! Courtesy ofehudt)EBNFgrammarUnicodefully supportedPython 2 & 3compatibleAutomatic line & column trackingStandard library of terminals (strings, numbers, names, etc.)Import grammars from Nearley.jsAnd much more!See the full list offeatures in the wikiComparison to other librariesPerformance comparisonLark is the fastest and lightest (lower is better)Check out theJSON tutorialfor more details on how the comparison was made.Note: I really wanted to add PLY to the benchmark, but I couldn't find a working JSON parser anywhere written in PLY. If anyone can point me to one that actually works, I would be happy to add it!Feature comparisonLibraryAlgorithmGrammarBuilds tree?Supports ambiguity?Can handle every CFG?Line/Column trackingGenerates Stand-aloneLarkEarley/LALR(1)EBNFYes!Yes!Yes!Yes!Yes! (LALR only)PLYLALR(1)BNFNoNoNoNoNoPyParsingPEGCombinatorsNoNoNo*NoNoParsleyPEGEBNFNoNoNo*NoNofuncparserlibRecursive-DescentCombinatorsNoNoNoNoNoParsimoniousPEGEBNFYesNoNo*NoNoANTLRLL(*)EBNFYesNoYes?YesNo(*PEGs cannot handle non-deterministic grammars. Also, according to Wikipedia, it remains unanswered whether PEGs can really parse all deterministic CFGs)Projects using Larkmappyfile- a MapFile parser for working with MapServer configurationpytreeview- a lightweight tree-based grammar explorertartiflette- a GraphQL engine by Dailymotion (Lark is used to parse the GraphQL schemas definitions)Using Lark? Send me a message and I'll add your project!How to use Nearley grammars in LarkLark comes with a tool to convert grammars fromNearley, a popular Earley library for Javascript. It usesJs2Pyto convert and run the Javascript postprocessing code segments.Here's an example:gitclonehttps://github.com/Hardmath123/nearley
python-mlark.tools.nearleynearley/examples/calculator/arithmetic.nemainnearley>ncalc.pyYou can use the output as a regular python module:>>>importncalc>>>ncalc.parse('sin(pi/4) ^ e')0.38981434460254655LicenseLark uses theMIT license.(The standalone tool is under GPL2)ContributeLark is currently accepting pull-requests.There are many ways you can help the project:Help solve issuesImprove the documentationWrite new grammars for Lark's libraryWrite a blog post introducing Lark to your audiencePort Lark to another languageHelp me with code developemntIf you're interested in taking one of these on, let me know and I will provide more details and assist you in the process.DonateFor the original project calledlark-parser, see:https://github.com/lark-parser/lark#donateContactFor the original project calledlark-parser, see:https://github.com/lark-parser/lark#contactFor this fork project calledpushdown,
open a new issue on:https://github.com/evandrocoan/pushdown/issues