# `Dmn.Compiler.Rename`
[🔗](https://github.com/FeeJai/BDM/blob/dmn-v0.1.0/apps/dmn/lib/dmn/compiler/rename.ex#L1)

Renames the reads of a name in a syntax tree of FEEL, where the tree reads it from outside.

An entry of a boxed context can have the name of something outside the context, and read it: `context01: context01`, or
`copied: context put(context01, "a", 2)` in a context that has an entry `context01`. In a FEEL context the key is a name for all the
entries, so the entry would read itself. The compiler renames the reads of the entry to a name that the context around it binds
to the outer value (`Dmn.Compiler.Expression`).

A read is a name that is not bound again inside the tree: the keys of a context in it, the parameters of a function, the
iterators of a `for` (and `partial` in its body), `some` and `every` (in the part they scope), and `item` in the brackets of a
filter bind names. The tree says where, in the function `scopes` of `Feel.Analysis.References` (not part of its public
interface), which `Feel.Analysis.References.to/2` reads the same way, so that the reads that are renamed are the reads that it
counts. The names of the parameters of a call by name, and
the parts of a path, are not reads.

# `reads?`

```elixir
@spec reads?(Feel.AST.t(), Feel.Name.t()) :: boolean()
```

Whether the tree reads the canonical name `name` from outside.

# `rename`

```elixir
@spec rename(Feel.AST.t(), Feel.Name.t(), [String.t(), ...]) :: Feel.AST.t()
```

The tree with the reads of the canonical name `from` read as `tokens`.

    iex> {:ok, tree} = Feel.parse("a + b + (function(a) a)(1)", scope: Feel.Scope.new(%{"a" => :number, "b" => :number}))
    iex> renamed = Dmn.Compiler.Rename.rename(tree, "a", ["outer", "a"])
    iex> Feel.Analysis.References.to(renamed, MapSet.new(["a", "b", "outer a"])) |> Enum.sort()
    ["b", "outer a"]

---

*Consult [api-reference.md](api-reference.md) for complete listing*
