Lexigram
About
Lexigram is a lexer/parser generator. It is written in Rust and generates Rust code.
It takes a grammar and generates the Rust source code to parse the corresponding language, providing a custom listener trait as user interface. This interface allows your code to interact with the parser by executing user-implemented callback methods when the rules are reduced, as in ANTLR. It is also somewhat similar to the code written next to each rule in tools like Yacc and Bison, but it’s cleaner and more flexible.
Two parser types can be generated: top-down and bottom-up.
The top-down option generates a predictive, non-recursive LL(1) parser. You may write non-LL(1) grammars as long as Lexigram can transform it into LL(1): left-recursive and ambiguous rules such as binary expressions are supported, and left factorization is performed automatically. The grammar also supports extended syntax such as repetition, token-separated repetitions, and so on. The generated interface hides those transformations by referring to the original rules as much as possible.
The bottom-up option currently generates an LALR(1) parser. Ambiguous rules are resolved with the same simple grammar notation used in LL(1) grammars. In general, Lexigram makes it relatively straightforward to move from LL to LALR.
The project is currently hosted on Codeberg.
This Documentation
This documentation consists of several chapters.
The introduction gives a general overview of parsers, their components, how they are designed, how they can be used, and the main parser types. If you’re not familiar with the design of parsers and the limitations of LL(1) and LALR grammars, it is recommended to read it, otherwise it can be skipped.
The tutorial gives a brief overview of the flow, and then shows how to build a small parser step by step. It helps you familiarize yourself with Lexigram using a hands-on approach.
The quick overview of the crates presents the main crates of this project.
The lexer generator reference and the parser generator reference describe more formally the lexicon and grammar language, the grammar transformations, and the generated code.
The Lexigram Book covers versions 0.10.0 to 0.10.2; it was last updated on 29 October 2026.
Older versions
Installation and Dependencies
The lexigram crate contains the executable. You’ll find information on how to install it and its main command-line options in the Lexigram Crates chapter.
The lexigram-core crate is the only dependency you need with the generated code. There are more details about it in the relevant Lexigram Crates chapter.
Generating the Code
lexigram -h shows the available options.
For example, to create a parser from the combined lexicon/grammar in ./grammar/calc.lg, and to write the generated code to ./src/lexer.rs and ./src/parser.rs, referring to user types defined in the types module, use this command:
lexigram -c grammar/calc.lg -l src/lexer.rs -p src/parser.rs --lib "crate::types::*" --log
If you prefer to insert the code between tags of an existing file, it’s possible too:
lexigram -c grammar/calc.lg --indent 4 -l src/calc.rs tag calc_lexer -p src/calc.rs tag calc_parser
You can also generate a parser programatically from your source code instead of using the command-line tool. In that case, you need the full library; see the Lexigram Crates chapter and the tutorial for more information.
Don’t miss the examples in the repository, under the examples directory (they’re briefly listed at the end of the tutorial).