Expand description
§VPL Parser
Lexing and parsing for the VPL streaming analytics language.
This crate transforms VPL source code into an Abstract Syntax Tree (AST) that can be executed by the runtime engine.
§Features
- Complete VPL grammar support
- Detailed error messages with line/column information
- Syntax hints for common mistakes
- PEG-based parsing via Pest
§Modules
pest_parser: Main parser implementation using Pest PEG grammarlexer: Token definitions (used for syntax highlighting)error: Parse error types with location informationhelpers: Parsing utility functionsindent: Indentation handling
§Quick Start
use varpulis_parser::parse;
let source = r#"
stream Readings = SensorReading
.where(temperature > 100)
.emit(alert("HighTemp", "Temperature exceeded threshold"))
"#;
match parse(source) {
Ok(program) => {
println!("Parsed {} statements", program.statements.len());
}
Err(e) => {
eprintln!("Parse error: {}", e);
}
}§Error Handling
Parse errors include detailed location information:
use varpulis_parser::{parse, ParseError};
let result = parse("stream X form Y"); // Typo: "form" instead of "from"
if let Err(ParseError::Located { line, column, message, hint, .. }) = result {
println!("Error at {}:{}: {}", line, column, message);
if let Some(h) = hint {
println!("Hint: {}", h);
}
}§Grammar
The VPL grammar is defined in varpulis.pest and supports:
- Stream declarations with filtering, selection, windowing, and aggregation
- Event type definitions
- SASE+ pattern declarations (sequences, Kleene closures, negation)
- User-defined functions
- Configuration blocks
- Control flow (if/elif/else, for, while)
- Expressions with operators and function calls
§See Also
varpulis_core: AST types produced by the parservarpulis_runtime: Executing parsed programs
Re-exports§
pub use error::ParseError;pub use lexer::Token;pub use pest_parser::parse;