Expand description
Semantic analysis for Pine Script — a static pre-check that runs after parsing and before execution.
§Example
use pine_ast::Program;
use pine_lexer::Lexer;
use pine_parser::Parser;
let src = "x = clse + 1\n"; // typo: `clse`
let tokens = Lexer::new(src).tokenize().unwrap();
let program = Program::new(Parser::new(tokens).parse().unwrap());
use std::collections::HashMap;
use pine_core::DefaultPineOutput;
use pine_interpreter::Value;
// The built-ins the runtime registers; here just `close`.
let mut builtins: HashMap<String, Value<DefaultPineOutput>> = HashMap::new();
builtins.insert("close".to_string(), Value::Na);
let errors = pine_sema::analyze(&program, &builtins, None);
assert_eq!(errors.len(), 1);
assert_eq!(errors[0].rule, "undeclared-variable");Structs§
- Analyzer
- Diagnostic
- A single finding from any analysis phase.
- Symbol
- A declared name and what is known about it at its declaration.
- Symbol
Table - The scope tree of a program, the symbols each scope declares, every use of those symbols, and the files they live in.
Enums§
- Scope
Kind - What opened a scope — for display and for scope-aware queries.
- Severity
- How serious a finding is.
- Symbol
Kind - What a declared name refers to. This drives rules like “you can’t reassign a
function” — only
SymbolKind::Varis a reassignable value.
Traits§
- Library
Loader - Loads the source of a library by its import path.
Functions§
- analyze
- Run semantic analysis over a parsed program and return every error found. An empty result means the program passed all implemented semantic checks.
- analyze_
with_ symbols - Analyze a program and also return the
SymbolTablereconstructed from the same walk — the durable declarations a tool (language server) queries.
Type Aliases§
- FileId
- A source file’s index within a
SymbolTable.0is always the main script; imported libraries get the ids that follow. - ScopeId
- A scope’s index within a
SymbolTable.0is always the main file’s global scope. - Symbol
Id - A symbol’s index within a
SymbolTable.