pyleri
raw JSON → 1.5.0 verified Fri May 01 auth: no python
A Python Left-Right Parser (LL(k) parser) designed for easy grammar definition and parsing. Version 1.5.0 adds typing and drops Python 3.7/3.8 support. Release cadence is irregular, with occasional patch releases.
pip install pyleri Common errors
error ModuleNotFoundError: No module named 'pyleri' ↓
cause pyleri is not installed or imported incorrectly.
fix
Run 'pip install pyleri' and use 'from pyleri import ...'.
error AttributeError: 'Result' object has no attribute 'as_string' ↓
cause Typo: use 'as_str' (without 'ing').
fix
Replace result.as_string() with result.as_str().
error pyleri.errors.ParseError: Expecting ... got ... ↓
cause Input does not match grammar. Check your input or grammar definition.
fix
Use result.as_str(line_number=True) to get a detailed error message.
Warnings
breaking Dropped support for Python 3.7 and 3.8 in v1.5.0. Upgrade your Python version or pin pyleri <1.5.0 if you need these versions. ↓
fix Use Python >=3.9 or install pyleri==1.4.3.
gotcha The 'parse' method returns a Result object, not True/False. Check result.is_valid to determine success. ↓
fix Always check result.is_valid, not just the returned value.
gotcha Regex element requires the pattern to be anchored with '^' internally. Do not add '^' at start; pyleri already prepends it. ↓
fix Use Regex(r'[a-zA-Z]+') not Regex(r'^[a-zA-Z]+').
Imports
- Grammar
from pyleri import Grammar
Quickstart
from pyleri import Grammar, Sequence, Keyword, Regex
# Define grammar elements
class MyGrammar(Grammar):
r = Sequence(
Keyword('hello'),
Regex(r'[a-zA-Z0-9]+')
)
grammar = MyGrammar()
result = grammar.parse('hello world')
if result.is_valid:
print('Parse succeeded!')
else:
print(f'Parse error: {result.as_str(line_number=True)}')