Expand description
Lowering of the call-shaped r!() subset to RCall-based Rf_lang* construction.
§Strategy
After grammar validation, the macro attempts to classify the tail token
stream as a lowerable call: a single top-level call of the form
ident(args…) or pkg::fn(args…) whose every argument belongs to the
lowerable atom set (string literals, integer/float literals, symbolic
constants, bare identifiers, nested lowerable calls, or name = value
named args).
When lowerable, the macro emits code that builds the call tree with
RCall + literal→SEXP constructors and evaluates it. This avoids the
parse-then-eval round-trip through r_eval_str.
When NOT lowerable (operators, assignments, control flow, [/$/@,
any ambiguity), it falls back to the original r_eval_str string path.
The fallback is the safety guarantee — no accepted input can start failing.
§Lowerable subset (exhaustive)
§Top-level shape
ident(args…)— simple function callpkg::fn(args…)— namespaced call
§Arg atoms
- String literal (
"hello") - Integer literal (
42L— one proc_macro2 token with theLsuffix). An unsuffixed42lowers as a double, matching R’s parser (R only produces INTSXP forL-suffixed literals;typeof(42)is"double") - Float literal (
1.5,1e3) - Symbolic constants:
TRUE,FALSE,NULL,NA,NA_integer_,NA_real_,NA_character_,NA_complex_,Inf,NaN - Bare identifier (symbol lookup at eval time)
- Nested lowerable call
- Named arg:
name = <atom>
Everything else → fallback.
Structs§
Enums§
Functions§
- classify_
args 🔒 - Parse the argument group of a call into
LowerArglist. ReturnsNoneif any argument is not lowerable. - classify_
atom 🔒 - Classify a token slice as a lowerable atom.
- classify_
call 🔒 - Classify a flat token slice as a lowerable top-level call.
- classify_
one_ 🔒arg - Classify one argument slot (possibly
name = atom). - emit_
atom 🔒 - Emit the SEXP-producing expression for an atom.
- emit_
call 🔒 - Emit a
TokenStreamthat builds + evaluates the lowered call. - emit_
nested_ 🔒call - Emit a nested call expression (returns the SEXP, adds protect_raw lines to the parent scope via a temporary).
- split_
by_ 🔒comma_ owned - Split a flat
Vec<TokenTree>by top-level commas. - try_
lower 🔒 - Attempt to lower a validated R tail token stream to a
RCall-basedTokenStream. - try_
parse_ 🔒r_ dotname - Try to parse a token sequence as an R dot-separated function name.