Expand description
Semantic analysis: scope building and validation.
Signature files (.sig): When .sig files are provided (e.g. stdlib), they are parsed
with the signature grammar, then type expressions in each function/global declaration
are turned into Type via parse_type_expr and seeded into the root scope. The type checker
uses these for inference (e.g. call return types, global variable types). Use
analyze_with_signatures(program_root, signature_roots) so that built-in names resolve and
types are inferred from the .sig definitions.
Structs§
- Analysis
Result - Result of running scope building and validation.
- Analyze
Options - Options for running analysis (single entry point for program or document).
- Class
Decl Info - Info extracted from a
NodeClassDecl(name and optional super class). - Function
Decl Info - Info extracted from a
NodeFunctionDecl(name and parameter counts). - Scope
- Single scope: variables and optional main-only data.
- Scope
Builder - Builds scope tree by walking the syntax tree; maintains a stack of scope IDs. Records the sequence of scope IDs pushed (in walk order) so Validator can use the same IDs.
- ScopeId
- Identifies a scope in the scope store (used for parent chain).
- Scope
Store - Store for all scopes; root is at index 0.
- SigMeta
- Documentation and complexity metadata for a root function or global (from .sig).
- Type
Checker - Tracks inferred types and runs arity checks. Runs after scope building and validation.
- Validator
- Collects diagnostics and maintains scope stack (replaying scope structure from first pass).
Uses the same scope ID sequence as
ScopeBuildersoresolve()looks up the correct scope. - VarDecl
Info - Info extracted from a
NodeVarDecl(var/global/const/let or typed). - Variable
Info - Variable binding: local, global, or parameter.
Enums§
- Analysis
Error - Error codes for semantic validation (mirroring leekscript-java Error enum).
- Member
Visibility - Visibility of a class member. Properties and methods are public by default when no modifier is given.
- Resolved
Symbol - Scope
Kind - Kind of a scope block (determines what can be declared and how lookup works).
- Type
Expr Result - Result of parsing a type expression: either a type or an error span.
- VarDecl
Kind - Declaration kind for a variable declaration node.
- Variable
Kind
Functions§
- analyze
- Build scope from the tree and run validation. Returns diagnostics and the scope store.
- analyze_
with_ include_ tree - Analyze the main file of an include tree: seed scope from included files and signatures, then analyze the main AST.
- analyze_
with_ options - Run analysis with the given options. Dispatches to
analyze,analyze_with_signatures, oranalyze_with_include_treeas appropriate. - analyze_
with_ signatures - Analyze the program with the root scope pre-seeded from signature files (e.g. stdlib constants and functions).
This allows references to global constants and built-in functions to resolve without errors.
Also seeds built-in type/class names (e.g.
Class,bool) so that commonLeekScriptcode validates. - binary_
expr_ rhs - Returns the right-hand side expression of a
NodeBinaryExpr. Prefers the named field “rhs” when present; otherwise uses the last node child. When the grammar labels RHS, it may wrap it inNodeExpr; we unwrap so the returned node is the inner expression. - build_
scope_ extents - Build list of (
ScopeId, extent) where extent is (start_byte,end_byte). Root scope (ScopeId(0)) is always first with extent (0,source_len). Remaining entries are in walk order, matchingscope_id_sequence. - call_
argument_ count - Number of argument expressions in a
NodeCallExpr. Used for type inference so the call is inferred as the function’s return type. The grammar uses lparen, optional(expr,zero_or_more(comma, expr)), rparen; the optional may be one node (with 0, 1, or more children) or optional +zero_or_moreas siblings. - call_
argument_ node - Returns the syntax node for the
i-th argument expression of aNodeCallExpr(0-based), for error spans. - class_
decl_ info - Returns class name and optional super class from a
NodeClassDecl. - class_
field_ info - Field name, optional declared type, and whether it’s static from a
NodeClassField. Returns (name, type,is_static) where type is None if the field has no type annotation. - class_
member_ visibility - Visibility of a class member from the preceding modifier. Public by default when no modifier. The modifier that applies is the last visibility keyword before this member that is not “consumed” by another member (i.e. no other member’s range contains that keyword).
- complexity_
display_ string - Display string for complexity code 1–13 from .sig
@complexity N. - find_
type_ expr_ child - Find a child node of
parentthat isNodeTypeExpr(for var decl, param, etc.). - function_
decl_ info - Returns name and parameter counts from a
NodeFunctionDecl. For default parameters,min_arityis the number of required params;max_arityis total. - member_
expr_ member_ name - Returns the member name (identifier after the dot) from a
NodeMemberExpr. - member_
expr_ receiver_ name - Returns the receiver name (identifier or keyword before the dot) from a
NodeMemberExpr. ForCell.getCellreturnsSome("Cell"), forthis.updatereturnsSome("this"). - param_
name - Parameter name and span from a
NodeParam(for scope building). - parse_
type_ expr - Parse a
NodeTypeExprnode into aType. Works for both program and signature grammar. - primary_
expr_ new_ constructor - If this primary is a
new ClassName(...)constructor call, returnsSome((class_name, num_args)). - primary_
expr_ resolvable_ name - Name to use for type/scope resolution from a primary expr: identifier, or “this”/“super” when
the single token is the corresponding keyword (class methods don’t use the
functionkeyword). - scope_
at_ offset - Find the innermost scope containing the given byte offset. When extents is empty (e.g. partial state), returns root scope ID so the LSP never panics.
- seed_
scope_ from_ program - Seed the root scope from a program AST (top-level classes, functions, globals only).
Also registers class fields and methods so member access (e.g.
myCell.x) infers types. Used when building scope from included files so the main file sees their declarations. - seed_
scope_ from_ signatures - Seed the root scope from parsed signature file(s). Each element of
signature_rootsshould be the root node returned byparse_signatures()(may be a wrapper orNodeSigFile). - var_
decl_ info - Returns the declaration kind and name from a
NodeVarDecl. For “var x”, “global T x”: name is the first identifier after the keyword. For typed form “Arrayarr” or “integer? y”: name is the last identifier before “=” (type names come first).
Type Aliases§
- Type
MapKey - Key for type map: (span.start, span.end) for exact span lookup.