Abacus.Runtime.Scope (abacus v2.1.0)

Contains helper functions to work with the scope of an Abacus script at runtime

Summary

Functions

Returns a scope with some default functions and constants

Tries to get values from a subject.

Renames first-level variables into their respective :"var#{x}" atoms

Types

@type index() :: integer()
@type key() :: String.t() | atom()

Functions

Link to this function

default_scope()

Returns a scope with some default functions and constants

Link to this function

get_in(subject, key_or_index, var_lookup \\ %{})

@spec get_in(nil, key() | index(), map()) :: nil
@spec get_in(map(), key(), map()) :: nil | term()
@spec get_in(list(), index(), map()) :: nil | term()
@spec get_in(list(), key(), map()) :: nil | term()

Tries to get values from a subject.

Subjects can be:

  • maps
  • keyword lists
  • lists (with integer keys)
  • nil (special case so access to undefined variables will not crash execution)

Keys can be:

  • strings
  • atoms (you can pass a resolve map that converts the given atom key into a string key)
  • positive integers (for lists only)

The Abacus parser will reference this function extensively like this:

a.b[2] will turn into

get_in(get_in(var0, :var1, var_lookup), 2, var_lookup)

in this case, var_lookup will be:

%{
  var1: "a",
  var2: "b"
}
Link to this function

prepare_scope(scope, lookup)

Renames first-level variables into their respective :"var#{x}" atoms