Crate menhir_runtime [−] [src]
The Rust runtime for Menhir
All the parsers generated by Menhir with the --rust option (or using
the menhir package from crates.io) use functions and types from this
crate.
This documentation is a reference API of the runtime library. It might be
useful to learn how to interact with the genarated parser from Rust code.
To learn how to write grammars, see the Menhir manual. To learn how to use
the generator to produce an executable Rust parser, see
[the documentation of the menhir crate].
The runtime API
The runtime library in this crate implements a classic LR(1) automaton loop to interpret the parse tables generated from a grammar specification. This implementation is highly generic in order to hide implementation details in the generated code. The most notable elements are:
Lexer, the lexer interface ; see alsoIteratorLexer.LRParser, the trait implemented by the generated parser, that exposes functions to access the generated parse table.
The lexer interface
Menhir parsers do not require a specially-recognized EOF token. The user is free to declare such a token in its specification but there is nothing special about it: Menhir parsers are able to automatically detect when they successfuly parsed recognized a start non-terminal without comsuming any extra lookahead token. This way, what remains of the input can be used with another invokation of the parser, or anything else.
To represent this fact, the runtime uses its own Lexer trait, which
encodes an infinite stream of pairs of a token and its location.
trait Lexer { type Location; type Token; type Error; fn input(&mut self) -> Result<(Self::Location, Self::Token), Self::Error>; }
Modules
| internals |
The internal representation of the LR engine. |
| lexing |
The lexer interface. |
Structs
| ParserState |
The state of the parser during the parsing process. |
| SyntaxError |
An unrecoverable syntax error. |
Enums
| Error |
A fatal (non-recoverable parsing error). |
Traits
| EntryPoint |
The trait of the entry points of a grammar file. |
| LRErrors |
Extension trait for parser that can provide detailed error messages. |
| LRParser |
Trait describing a Menhir parser. |