Skip to main content

Module ast

Module ast 

Source
Expand description

Abstract Syntax Tree (AST) types for gram notation

The AST provides a language-agnostic, JSON-serializable representation of the Pattern<Subject> structure that gram notation describes.

§Design Philosophy

The AST mirrors the Pattern<Subject> structure exactly:

  • No graph-specific concepts (no “nodes”, “edges”, “relationships”)
  • Path notation is already desugared by the parser
  • Just patterns and subjects - clean and conceptual

§Usage

use gram_codec::{parse_to_ast, AstPattern};

let ast = parse_to_ast("(alice:Person {name: \"Alice\"})")?;
println!("Identity: {}", ast.subject.identity);
println!("Labels: {:?}", ast.subject.labels);

§JSON Serialization

The AST is designed to be JSON-serializable for cross-language use:

use gram_codec::parse_to_ast;
use serde_json;

let ast = parse_to_ast("(alice:Person)")?;
let json = serde_json::to_string(&ast)?;

Structs§

AstPattern
Abstract Syntax Tree representation of a Pattern
AstSubject
Subject data - identity, labels, and properties
ParseWithHeaderResult
Wire type for parse_with_header across FFI boundaries (WASM and PyO3).