-
Notifications
You must be signed in to change notification settings - Fork 2
Variable Binding
Variable binding is the process of binding a name to a value given a typed context value. By default Jefferson looks up names against the current context (aka "this"). This process can be controlled by implementing IVariableBinder
. Implementing this interface implements 3 operations:
- read a variable
- write a variable
- delete a variable
For an example see IndexerVariableBinder
, which implements reading and writing by using an indexer on the context class (e.g. using a Dictionary<,>
).
Variable binders are also used internally to support Jefferson functionality. For example the #block
directive adds a binder to establish a block scope.
Note that e.g. the #let
directive does not write variables but uses an internal store to bind a name to value and as such only implements the read operation.
The delete operation is currently only used by the #undef
directive.
Names are resolved for reading using the following algorithm:
- Namespaced names are always resolved directly, i.e. cannot be intercepted.
- Special namespaces
$<index>
supported to walk up the scope hierarchy,$0
is the current scope,$1
its parent etc. Set the current scope to the scope indexed. - If there is a variable binder at the current scope level, ask it to resolve the name. If null is returned or no binder set, goto 4.
- Resolve to a field, property or method of the context object in the current scope.
- If not found, move to the parent scope and go to 3.