Cheatsheet
Users of Lalrpop have compiled the following cheatsheet table as a quick way to look up useful Lalrpop-isms. If you are looking for a specific piece of functionality, use this table to jump to the right section.
name | snippet | description | tutorial |
---|---|---|---|
position | <left: @L> T <right: @R> | captures the offset of the first byte and the offset of the last byte plus one (as left and right respectively) | Location tracking |
error_recovery | ! => { ... } | recovers from parser errors | Error recovery |
grammar_parameter | grammar(scale: isize); | input parameters usable in the generated parser | Passing state parameter |
custom_error | "e" =>? Err(ParseError::User { error: "an error" }) | makes an action fallible | Fallible actions |
custom_macros | Comma<T> = { ... } | makes a non-terminal generic in other non-terminals | Macros |
quantifier_macros | <Num?> <Num*> <Num+> | a non-terminal which can appear 0..1, 0+, 1+ times | Macros |
tuple_macro | <a:(<Num> ",")*> | applies a quantifier to a group of matches | Macros |
extern | extern { } | allows to override some parts of the generated parser | Writing a custom lexer |
extern_error | type Error = MyError; | sets the error to use in the ParseError::User variant | Writing a custom lexer |
extern_location | type Location = MyLoc; | sets the type to for locations instead of usize | Writing a custom lexer |
extern_tok | enum MyToken { } | declares the type of lexer tokens to be consumed by the generated parser | Using tokens with references |
auto_parameters | <> | refers to all the parameters of the non-terminal as a tuple | Type inference |
conditional actions | Expr<I> = { ... , <T> if I == "a" => (), ...} | Conditional definition of a macro's alternative | index pointer |
precedence | #[precedence(level="0")] | creates a hierarchy to parser actions for which ones should be applied first | Handling full expressions |