dsq-parser

Crates.iodsq-parser
lib.rsdsq-parser
version0.1.0
created_at2025-12-15 17:45:25.754824+00
updated_at2025-12-15 17:45:25.754824+00
descriptionParser for DSQ filter language that produces an AST
homepage
repositoryhttps://github.com/durableprogramming/dsq
max_upload_size
id1986450
size204,075
David J Berube (djberube)

documentation

README

dsq-parser

Parser for the DSQ filter language that produces an Abstract Syntax Tree (AST).

Overview

dsq-parser is a core component of the DSQ (DataSet Query) ecosystem that handles parsing of jq-like query syntax into an AST representation. The parser is built using the nom parser combinator library and produces a structured AST that can be evaluated by other DSQ components.

Features

  • jq-compatible syntax: Supports a subset of jq's filter language
  • Comprehensive AST: Produces a detailed abstract syntax tree for query evaluation
  • Error handling: Provides clear error messages for syntax errors
  • Extensible design: Easy to add new operators and functions
  • Parser combinators: Built with nom for composability and performance

Installation

Add this to your Cargo.toml:

[dependencies]
dsq-parser = "0.1"

Usage

Basic Parsing

use dsq_parser::parse_filter;

fn main() {
    let query = ".name | select(.age > 18)";

    match parse_filter(query) {
        Ok(ast) => println!("Parsed AST: {:?}", ast),
        Err(e) => eprintln!("Parse error: {}", e),
    }
}

Working with the AST

use dsq_parser::{parse_filter, Expr};

fn main() {
    let query = ".[] | .id";
    let ast = parse_filter(query).expect("Failed to parse");

    // Process the AST
    match ast {
        Expr::Pipe(left, right) => {
            println!("Pipeline detected");
            println!("Left: {:?}", left);
            println!("Right: {:?}", right);
        }
        _ => println!("Other expression type"),
    }
}

Supported Syntax

The parser supports the following jq-like constructs:

  • Field access: .field, .field.nested
  • Array operations: .[], .[0], .[1:3]
  • Pipes: expr | expr
  • Filters: select(), map(), sort_by()
  • Operators: +, -, *, /, ==, !=, <, >, <=, >=
  • Functions: Built-in and custom function calls
  • Literals: Numbers, strings, booleans, null
  • Object construction: {key: value}
  • Array construction: [expr]

API Documentation

For detailed API documentation, see docs.rs/dsq-parser.

Architecture

The parser is organized into several modules:

  • lexer: Tokenization of input strings
  • expr: Expression parsing
  • operators: Operator parsing and precedence
  • literals: Literal value parsing
  • combinators: Helper parser combinators

Contributing

Contributions are welcome! Please see the CONTRIBUTING.md file in the repository root for guidelines.

License

Licensed under either of:

at your option.

Commit count: 0

cargo fmt