Skip to main content

Crate varpulis_parser

Crate varpulis_parser 

Source
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 grammar
  • lexer: Token definitions (used for syntax highlighting)
  • error: Parse error types with location information
  • helpers: Parsing utility functions
  • indent: 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

Re-exports§

pub use error::ParseError;
pub use error::RichParseError;
pub use lexer::Token;
pub use optimizer::optimize_plan;
pub use pest_parser::parse;

Modules§

error
Parse error types with source location information. Parser error types
expand
Compile-time expansion of top-level for loops in VPL source.
helpers
Helper functions for parsing literal values (durations, timestamps). Helper functions for parsing literals in LALRPOP grammar
indent
Indentation preprocessor that converts Python-style blocks to explicit markers. Indentation preprocessor for VPL
lexer
Logos-based lexer producing spanned tokens for VPL source. Lexer for VPL using Logos
optimize
AST-level constant folding optimization pass. AST-level constant folding optimization pass.
optimizer
Rule-based logical plan optimizer (filter pushdown, window merge, etc.). Rule-based logical plan optimizer
pest_parser
Pest PEG parser that transforms VPL source into an AST.