Skip to main content

Crate pine_sema

Crate pine_sema 

Source
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.
SymbolTable
The scope tree of a program, the symbols each scope declares, every use of those symbols, and the files they live in.

Enums§

ScopeKind
What opened a scope — for display and for scope-aware queries.
Severity
How serious a finding is.
SymbolKind
What a declared name refers to. This drives rules like “you can’t reassign a function” — only SymbolKind::Var is a reassignable value.

Traits§

LibraryLoader
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 SymbolTable reconstructed from the same walk — the durable declarations a tool (language server) queries.

Type Aliases§

FileId
A source file’s index within a SymbolTable. 0 is always the main script; imported libraries get the ids that follow.
ScopeId
A scope’s index within a SymbolTable. 0 is always the main file’s global scope.
SymbolId
A symbol’s index within a SymbolTable.