Mutare.Transform.KeywordRouting (mutare v0.4.0)

Copy Markdown View Source

Interprets a normalized keyword route against one concrete argument, without walking it.

A literal keyword list becomes ordered pairs of {node, treatment} entries plus a shape-preserving rebuilder. A non-keyword argument gets its whole-argument fallback: the leading treatment for a keyed refinement, or :raw for positional keyword routing. Positional routing requires exactly one treatment per pair; it never silently truncates.

Keyed refinements choose each value's final treatment before any descent. Unnamed values and data keys inherit the leading treatment, except that :interior becomes :expression below the container. Block keys are always raw. Positional keyword routes leave all keys raw and assign treatments to values by order, including duplicate keys.

Resolve, body analysis, guard tagging, self-call rewriting and binding analysis share this interpretation, not a traversal. Each pass still decides what a treatment means for its task; the container's own offer and nested syntax scopes also remain with that pass. In particular, withholding mutation does not establish whether an expression executes.

Summary

Types

decoded()

@type decoded() ::
  {:pairs, [{routed_node(), routed_node()}], rewrap()} | {:whole, position()}

position()

@type position() :: treatment() | routing()

rewrap()

@type rewrap() :: ([{Macro.t(), Macro.t()}] -> Macro.t())

routed_node()

@type routed_node() :: {Macro.t(), position()}

routing()

@type routing() ::
  {:keyed, treatment(), [{atom(), position()}]} | {:keyword, [position()]}

treatment()

@type treatment() :: atom() | {:hosted, [module()]}

Functions

decode(arg, arg)

@spec decode(Macro.t(), routing()) :: decoded()