Lepl combines the simplicity and ease–of–use of a recursive descent parser with scalability (through memoisation) and advanced (but optional) features like lexing, AST generation, offside–rule, robustness to ambiguous and left–recursive grammars, etc.

  • Parsers are Python code, defined in Python itself. No separate grammar is necessary.
  • Friendly syntax using Python’s operators allows grammars to be defined in a declarative style close to BNF.
  • Optional, integrated lexer simplifies handling whitespace.
  • Built-in AST support with support for iteration, traversal and re–writing.
  • Generic, pure-Python approach supports parsing a wide variety of data including binary data (Python 3+ only).
  • Well documented and extensible, modular design.
  • Unlimited recursion depth. The underlying algorithm is recursive descent, which can exhaust the stack for complex grammars and large data sets. Lepl avoids this problem by using Python generators as coroutines.
  • The parser can itself be manipulated by Python code. This gives unlimited opportunities for future expansion and optimisation.
  • Support for ambiguous grammars. A parser can return more than one result (“complete backtracking”, “parse forests”).
  • Parsers can be made much more efficient with automatic memoisation (“packrat parsing”).
  • Memoisation can detect and control left recursive grammars. Together with Lepl’s support for ambiguity this means that “any” grammar can be supported.
  • Support for the “offside rule” (significant indentation levels) when using the lexer.
  • Trace and resource management, including deepest match diagnostics and the ability to limit backtracking.

Previous topic


Next topic

A Tutorial for Lepl

This Page