Juggernaut.Operators.Helpers (Juggernaut v0.4.0)

Copy Markdown View Source

Building blocks shared by the operator families: operator swaps, table-driven call renames and literal replacements.

Summary

Functions

Whether op/arity at a site means Kernel's operator (the module does not define it).

The numeric literal replacements value + step, value - step and zero, without duplicates or the value itself; variants zero, succ, pred. With negated? the literal is the operand of a unary minus, so the variants name what happens to the written value: -3 → -4 is pred.

A rename table of symmetric pairs: for each {modules, pairs} group, each name maps to the other on every module listed.

Renames a resolved call per table: keys are {module, fun} (any arity) or {module, fun, arity}, values the new function names. Arguments and the written form are kept.

The sentinel string replacements use.

A sigil node with a delimiter that does not occur in content.

The content of a non-interpolated sigil, or :error.

A string literal node.

Swaps a binary operator for each operator table lists for it; the variant is the new operator. Operators the module defines itself are left alone.

Functions

kernel_op?(op, arity, ctx)

@spec kernel_op?(atom(), arity(), Juggernaut.Mutator.Context.t()) :: boolean()

Whether op/arity at a site means Kernel's operator (the module does not define it).

numeric(value, step, zero, negated?)

@spec numeric(number(), number(), number(), boolean()) :: [{String.t(), Macro.t()}]

The numeric literal replacements value + step, value - step and zero, without duplicates or the value itself; variants zero, succ, pred. With negated? the literal is the operand of a unary minus, so the variants name what happens to the written value: -3 → -4 is pred.

pairs(groups)

@spec pairs([{[module()], [{atom(), atom()}]}]) :: %{
  required({module(), atom()}) => [atom()]
}

A rename table of symmetric pairs: for each {modules, pairs} group, each name maps to the other on every module listed.

rename(node, ctx, table)

@spec rename(Macro.t(), Juggernaut.Mutator.Context.t(), map()) :: [{nil, Macro.t()}]

Renames a resolved call per table: keys are {module, fun} (any arity) or {module, fun, arity}, values the new function names. Arguments and the written form are kept.

sentinel()

@spec sentinel() :: String.t()

The sentinel string replacements use.

sigil(name, content, modifiers)

@spec sigil(atom(), String.t(), charlist()) :: Macro.t()

A sigil node with a delimiter that does not occur in content.

sigil_content(arg1)

@spec sigil_content(Macro.t()) :: {:ok, atom(), String.t(), charlist()} | :error

The content of a non-interpolated sigil, or :error.

string(text)

@spec string(String.t()) :: Macro.t()

A string literal node.

swap(arg1, ctx, table)

@spec swap(Macro.t(), Juggernaut.Mutator.Context.t(), %{required(atom()) => [atom()]}) ::
  [
    {String.t(), Macro.t()}
  ]

Swaps a binary operator for each operator table lists for it; the variant is the new operator. Operators the module defines itself are left alone.