Skip to main content

Module r_macro

Module r_macro 

Source
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:

  1. Lowers the tail to RCall-based Rf_lang* construction when the tail is a single call of the lowerable subset (see lowering), or
  2. Falls back to the r_eval_str string 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 to RCall-based Rf_lang* construction.

Functionsยง

expand ๐Ÿ”’
Parse and validate r!(...) input, returning the expanded TokenStream.
expand_inner ๐Ÿ”’
parse_r_macro_input ๐Ÿ”’
Parse the r!(...) input into an optional env expression and the tail token stream.