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_interpreter::{DefaultPineOutput, 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);
assert_eq!(errors.len(), 1);
assert_eq!(errors[0].rule, "undeclared-variable");

Structs§

Analyzer
Diagnostic
A single finding from any analysis phase.

Enums§

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.

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.