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.

namesnippetdescriptiontutorial
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)index pointer
error_recovery! => { ... }recovers from parser errorsError recovery
grammar_parametergrammar(scale: isize);input parameters usable in the generated parserPassing state parameter
custom_error"e" =>? Err(ParseError::User { error: "an error" })makes an action fallibleFallible actions
custom_macrosComma<T> = { ... }makes a non-terminal generic in other non-terminalsMacros
quantifier_macros<Num?> <Num*> <Num+>a non-terminal which can appear 0..1, 0+, 1+ timesMacros
tuple_macro<a:(<Num> ",")*>applies a quantifier to a group of matchesMacros
externextern { }allows to override some parts of the generated parserWriting a custom lexer
extern_errortype Error = MyError;sets the error to use in the ParseError::User variantWriting a custom lexer
extern_locationtype Location = MyLoc;sets the type to for locations instead of usizeWriting a custom lexer
extern_tokenum MyToken { }declares the type of lexer tokens to be consumed by the generated parserUsing tokens with references
auto_parameters<>refers to all the parameters of the non-terminal as a tupleType inference
conditional actionsExpr<I> = { ... , <T> if I == "a" => (), ...}Conditional definition of a macro's alternativeindex pointer
precedence#[precedence(level="0")]creates a hierarchy to parser actions for which ones should be applied firstHandling full expressions