Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

What Next?

Hopefully, this tutorial has provided a good overview of the Lexigram tool and how to use it to build a parser.

The reference documentation provides a complete overview of the features:

Don’t miss the crate documentation, which briefly presents the different crates.

To see practical examples, you can look at the GitHub repository. You’ll find an example directory with a few illustrations of common and more advanced features. Each example is divided into two parts: a gen_<name> crate with the grammar and the parser generator, and the <name> crate with the parser implementation. At the time of writing, the following examples are available:

  • microcalc / impl: a simple, bare-bones parser.
  • config / impl: a configuration parser on which this tutorial is based.
  • terminate / impl: a parser that uses Terminate::Conclude to discard the rest of the input.
  • watcher / impl: a parser that shows the latency between reading the input and calling the listener methods (check the Cargo.toml file to reduce the latency further).
  • pandemonium / impl: a test that includes all the grammar transformations. It’s probably less instructive.

Another example is a parser for the simplified lexicon/grammar (a -> "let" Id "=" expr ";";), and which is used for a series of unit tests. Some parts may be harder to understand because it uses the full library to generate a parser.

There are of course the lexers and parsers of Lexi and Gram, but they’re even less straightforward to follow because they’re built in two stages and also use the full library to build the lexer and the parser.