@eagleoutice/flowr-dev
Version:
Static Dataflow Analyzer and Program Slicer for the R Programming Language
19 lines (18 loc) • 1.41 kB
TypeScript
/** the name of the special `...` parameter which collects everything that finds no formal of its own */
export declare const DotsParameterName = "...";
/**
* Bind the arguments of a call to the formal parameters of the called function, following R's argument matching
* rules (see https://cran.r-project.org/doc/manuals/R-lang.html#Argument-matching):
*
* 1. every named argument that *exactly* matches a formal takes it,
* 2. every remaining named argument that is a *unique prefix* of a still-free formal takes it (`pmatch`),
* 3. the remaining unnamed arguments fill the still-free formals from left to right, stopping at `...`
* (formals behind `...` can only be matched by name), and
* 4. everything that is still unmatched goes to `...` if the function has one.
*
* Both sides are given by their names alone (`undefined` for an unnamed argument or an anonymous formal), so this
* works for the normalized AST, the dataflow graph, and a plain signature list alike. An empty argument (`f(1, ,3)`)
* is an unnamed one: it takes its formal like any other, the caller just has nothing to bind to it.
* @returns for every argument (by index) the index of the parameter it binds to, `undefined` if it stays unbound
*/
export declare function matchArgumentsToParameters(argNames: readonly (string | undefined)[], paramNames: readonly (string | undefined)[]): readonly (number | undefined)[];