4. Cheatsheet 备忘单

https://lalrpop.github.io/lalrpop/cheatsheet.html

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.

gpt --- Lalrpop 的用户编制了以下这张备忘单,作为快速查找常用 Lalrpop 语法的工具。如果你正在寻找某个特定功能,可以通过这张表快速跳转到相应的部分。

ms --- Lalrpop 的用户编译了以下 cheatsheet 表,作为查找有用的 Lalrpop-isms 的快速方法。如果要查找特定功能,请使用此表跳转到右侧部分。

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 = 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:( ",")*> 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 = { ... , 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

posted on 2024-12-29 18:57  及途又八  阅读(11)  评论(0)    收藏  举报

导航