7.2 Conditional compilation 条件编译
https://lalrpop.github.io/lalrpop/conditional-compilation.html
LALRPOP support conditional compilation of non-terminal declarations via #[cfg(feature = "FEATURE")] attributes. If run in a build script LALRPOP will automatically pickup the features from cargo and use those. Alternatively an explicit set of features can be set using the Configuration type.
MST -- LALRPOP 支持通过 #[cfg(feature = “FEATURE”)] 属性对非终端声明进行条件编译。如果在构建脚本中运行,LALRPOP 将自动从 cargo 中获取功能并使用这些功能。或者,可以使用 Configuration 类型设置一组显式功能。
GPT -- “LALRPOP 支持通过
#[cfg(feature = "FEATURE")]
属性进行非终结符声明的条件编译。如果在构建脚本中运行,LALRPOP 会自动获取 Cargo 的特性并使用这些特性。或者,也可以通过Configuration
类型显式设置一组特性。”
Like rust's cfg attribute, the syntax accepts not(), any() and all() arguments, even nested.
MST -- 就像 rust 的 cfg 属性一样,语法接受 not()、any() 和 all() 参数,甚至是嵌套的。
GPT -- “像 Rust 的
cfg
属性一样,语法接受not()
、any()
和all()
参数,甚至是嵌套的。”
#[cfg(feature = "FEATURE")]
pub MyRule1 : () = {
...
};
#[cfg(any(feature = "FEATURE_A", all(not(feature = "FEATURE_B"), feature = "FEATURE_C")))]
pub MyRule2 : () = {
...
};
pub MyRule3: () = {
#[cfg(feature = "FEATURE_A")]
"A" => (),
#[cfg(feature = "FEATURE_B")]
"B" => (),
};
When using a custom lexer:
extern {
type Location = usize;
type Error = LexicalError;
enum Token {
"int" => Token::Integer(<i64>),
"+" => Token::OperatorAdd,
// Feature flag the left shift operator
#[cfg(feature = "bit")]
"<<" => Token::OperatorShl,
}
}