Arpeggio is a Python library that provides a Packrat parser interpreter. It allows you to define grammars using Python functions or EBNF-like strings and then parse input text according to those grammars. The current version is 2.0.3, with releases focusing on bug fixes, performance, and modern Python compatibility.
pip install arpeggioVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates defining a simple arithmetic grammar, parsing an expression, and then using a `PTNodeVisitor` to traverse and evaluate the resulting parse tree.
Upgrade your Python environment to 3.6 or newer. If you need older Python support, use Arpeggio < 2.0.0 (e.g., 1.x).
Always check for the presence of a rule or use iteration/indexing (`node[idx]`) if uncertain about rule names. Refer to the documentation on parse tree structure for correct navigation.
When debugging parsing issues, ensure you are on Arpeggio >= 2.0.0 and consult the documentation on error handling to fully leverage the detailed `NoMatch` exception information.
Be consistent with your grammar definition method. Use `Parser(grammar_string)` for string-based grammars and `ParserPython(grammar_function)` for Python-function-based grammars.
Refactor the grammar to eliminate left recursion by restructuring the rules to avoid direct or indirect self-references at the beginning of a rule.
Ensure that more specific patterns are placed before more general ones in ordered choices to prevent premature matches.
Install Arpeggio using pip: `pip install Arpeggio`.
Correct the input string to conform to the grammar, or adjust the grammar definition to accept the given input. You can catch `arpeggio.NoMatch` to handle syntax errors gracefully in your code.
Ensure all string literals used for grammar definition are Unicode. For Python 2, use `from __future__ import unicode_literals`. For modern Python, verify the grammar element's syntax against Arpeggio's documentation.
No dependency data recorded yet.