Expand description
Implementation of the r! proc-macro.
Parses the optional env: <expr> ; head, validates the R token tail with
the conservative grammar checker in grammar, then either:
- Lowers the tail to
RCall-basedRf_lang*construction when the tail is a single call of the lowerable subset (seelowering), or - Falls back to the
r_eval_strstring path for everything else.
The fallback path produces code byte-identical to the old macro_rules! r
expansion โ ::core::stringify! rather than TokenStream::to_string() so
spacing normalisation is identical.
โ
// Lowered: r!(c(1L, 2L, 3L))
unsafe {
let __r_scope = ::miniextendr_api::gc_protect::ProtectScope::new();
// ... protect each arg ...
::miniextendr_api::expression::RCall::new("c")
.arg(__r_arg_0)
...
.eval(::miniextendr_api::sys::R_GlobalEnv)
}
// Fallback: r!(1L + 2L)
unsafe {
::miniextendr_api::expression::r_eval_str(
::core::stringify!(1L + 2L),
::miniextendr_api::sys::R_GlobalEnv,
)
}Modulesยง
- grammar ๐
- Conservative R-grammar validation for the
r!proc-macro. - lowering ๐
- Lowering of the call-shaped
r!()subset toRCall-based Rf_lang* construction.
Functionsยง
- expand ๐
- Parse and validate
r!(...)input, returning the expandedTokenStream. - expand_
inner ๐ - parse_
r_ ๐macro_ input - Parse the
r!(...)input into an optionalenvexpression and the tail token stream.