Skip to content
Marcus edited this page Oct 15, 2015 · 3 revisions

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:

  1. read a variable
  2. write a variable
  3. 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:

  1. Namespaced names are always resolved directly, i.e. cannot be intercepted.
  2. 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.
  3. 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.
  4. Resolve to a field, property or method of the context object in the current scope.
  5. If not found, move to the parent scope and go to 3.
Clone this wiki locally