Skip to main content

Crate jetro_core

Crate jetro_core 

Source
Expand description

Jetro core — parser, compiler, and VM for the Jetro JSON query language.

This crate is storage-free. For the embedded B+ tree store, named expressions, graph queries, joins, and Session, depend on the sibling jetrodb crate, or pull the umbrella jetro crate which re-exports both.

§Architecture

  source text
      │
      ▼
  parser.rs  ── pest grammar → [ast::Expr] tree
      │
      ▼
  vm::Compiler::emit      ── Expr → Vec<Opcode>
      │
      ▼
  vm::Compiler::optimize  ── peephole passes (root_chain, filter/count,
                             filter/map fusion, strength reduction,
                             constant folding, nullness-driven specialisation)
      │
      ▼
  Compiler::compile runs:
      • AST rewrite: reorder_and_operands        (selectivity-based)
      • post-pass  : analysis::dedup_subprograms (CSE on Arc<Program>)
      │
      ▼
  vm::VM::execute          ── stack machine over &serde_json::Value
                               with thread-local pointer cache.

§Quick start

use jetro_core::Jetro;
use serde_json::json;

let j = Jetro::new(json!({
    "store": {
        "books": [
            {"title": "Dune",        "price": 12.99},
            {"title": "Foundation",  "price":  9.99}
        ]
    }
}));

let count = j.collect("$.store.books.len()").unwrap();
assert_eq!(count, json!(2));

Re-exports§

pub use engine::Engine;
pub use eval::EvalError;
pub use eval::Method;
pub use eval::MethodRegistry;
pub use eval::Val as JetroVal;
pub use expr::Expr;
pub use graph::Graph;
pub use parser::ParseError;
pub use vm::VM;
pub use vm::Compiler;
pub use vm::Program;

Modules§

analysis
Static analysis passes over compiled Program IR.
ast
Abstract syntax tree for Jetro v2 expressions.
cfg
Control-flow graph for v2 programs.
engine
Top-level execution handle.
eval
Tree-walking evaluator — reference semantics for Jetro v2.
expr
Typed expression values.
graph
Graph layer — query across multiple named JSON documents.
parser
PEG parser for Jetro v2 source text.
plan
Logical plan IR.
scan
SIMD byte-scan over raw JSON bytes.
schema
Schema / shape inference for JSON documents.
ssa
SSA-style numbering + data-flow graph for v2 programs.
strref
Borrowed-slice string view that shares a parent Arc<str>.
vm
High-performance bytecode VM for v2 Jetro expressions.

Structs§

Jetro
Primary entry point for evaluating Jetro expressions.

Enums§

Error
Engine-side error type. Either a parse failure or an evaluation failure.

Traits§

JetroSchema
Trait implemented by #[derive(JetroSchema)] — pairs a type with a fixed set of named expressions.

Functions§

query
Evaluate a Jetro expression against a JSON value.
query_with
Evaluate a Jetro expression with a custom method registry.

Type Aliases§

Result