Overview
TheScript class is the entry point for scope and variable analysis in Loretta. It holds one or more syntax trees and provides access to scopes, variables, and goto labels throughout the analyzed code.
Constructor
Script()
Initializes an empty script with no syntax trees.Script(ImmutableArray<SyntaxTree>)
Initializes a script from one or more syntax trees.syntaxTrees- An immutable array of syntax trees to analyze
ArgumentException- Thrown when the syntax trees array is a default (uninitialized) array
Properties
SyntaxTrees
Gets the syntax trees contained in this script.RootScope
Gets the root (global) scope of the script. This is the top-level scope that contains all file scopes.Methods
GetScope
Returns the scope associated with a specific syntax node, ornull if the node has no associated scope.
node- The syntax node to get the scope for
- The scope for the node, or
nullif not found
FindScope
Finds the outermost scope of the specified kind (or a more generic one) for a given node.node- The node to search fromkind- The kind of scope to search for (defaults toScopeKind.Block)
- The found scope, or
nullif not found
ScopeKind.Block- Searches for: Block, Function, File, or GlobalScopeKind.Function- Searches for: Function, File, or GlobalScopeKind.File- Searches for: File or GlobalScopeKind.Global- Searches for: Global only
GetVariable
Returns the variable associated with a specific syntax node.node- The syntax node (typically an identifier) to get the variable for
- The variable, or
nullif the node is not associated with a variable
GetLabel
Returns the goto label associated with a specific syntax node.node- The syntax node to get the label for
- The goto label, or
nullif the node is not associated with a label
RenameVariable
Attempts to rename a variable throughout the script, checking for conflicts.variable- The variable to renamenewName- The new name for the variable
Result.Ok(Script)- A new script with the renamed variable if successfulResult.Err(IEnumerable<RenameError>)- A collection of errors if the rename would cause conflicts
ArgumentNullException- Thrown whenvariableornewNameis null