class Mint::Scope

Overview

The class is responsible for keeping track of which variable is pointing to which node.

The data strucutre is a tree where leafs are the levels of the child nodes of an AST node and a level is a container for the possible targets.

When resolving a variable we travese it's tree upwards to find the target which matches the value of the variable.

Defined in:

scope.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(ast : Ast) #

[View source]

Instance Method Detail

def add(node : Ast::Node, key : String, value : Ast::Node) #

Adds a target to the level of the given node.


[View source]
def build(node : Ast::Node | Nil, parent : Ast::Node) #

[View source]
def build(nodes : Array(Ast::Node), parent : Ast::Node, *, stack : Bool = false) #

Builds an array of nodes. If stack is true then each node will be the child of the previous nodes.


[View source]
def build(node : Ast::Node) #

Builds the scope for the given node and it's child nodes.


[View source]
def create(node : Ast::Node, parent : Ast::Node | Nil = nil) #

Builds a level for the node and yields the parents scope.


[View source]
def debug_name(node) #

TODO Move this somewhere else


[View source]
def nodes : Hash(Mint::Ast::Node, Mint::Scope::Level) #

We track the level of a node in here.


[View source]
def resolve(target : String, base : Ast::Node) #

[View source]
def resolve(node : Ast::Variable) #

Tries to find the target of the given variable.


[View source]
def resolve #

Resolves the targets which can be statically resolved, currently only the exposed variables of a connected store in a component.


[View source]
def root : Mint::Scope::Level #

[View source]
def scopes : Hash(Mint::Ast::Node, Array(Mint::Scope::Level)) #

We track the level stack of a node in here.


[View source]