Module scopes

Module scopes 

Source
Expand description

This module is responsible for building a tree of scopes from a SyntaxTree.

Scopes are built according to the following rules:

  • Most declarations spawn a new child scope which is valid through the end of the scope which contains it. The starting point for declaration scopes depends on the type of declaration:
    • var, let, and type bindings become active after their semicolon
    • struct bindings become active after their closing brace
    • fn bindings become active after their opening brace
  • Block statements (generally any chunk of code enclosed in curly braces, e.g. following an if statement’s condition expression) spawn a new child scope from the end of the opening brace to the start of the closing brace

There are a couple special cases to be aware of:

  • Parameter bindings are valid within their function body, but don’t spawn new scopes of their own
  • Bindings declared in the initializer of a for statement are valid within the statement’s body, and within the condition and increment expressions

Once the Scopes object has been constructed, the declaration for any given identifier binding can be found by querying the Scopes instance for the identifier’s Token. If the declaration is not found, either something has gone terribly wrong or the identifier is invalid.

Structs§

Scope

Functions§

build

Type Aliases§

Bindings
A mapping of identifier names to their declarations