# query
`src/features/query/api.rs`
Parses a Cypher-inspired query string into an `Ast` and optionally validates it against a `Catalog`.
---
## Parsing
```rust
pub fn parse(query: &str) -> Result<Ast>
```
Parses `query` into an `Ast`. Returns `QueryError::InvalidSyntax` if the query does not conform to the supported grammar.
---
## Validation
```rust
pub fn validate(ast: &Ast, catalog: &Catalog) -> Result<TypedAst>
```
Validates an `Ast` for semantic correctness against a `Catalog`. Returns `QueryError::InvalidSemantic` if references are invalid. Currently `Catalog` is a zero-sized placeholder; richer schema support is planned.
---
## Ast
```rust
pub struct Ast {
pub match_aliases: Vec<String>, // all bound names in MATCH
pub match_alias: String, // primary match alias
pub where_clause: Option<WhereClause>,
pub where_predicate: Option<VectorPredicate>,
pub where_bitmap_predicate: Option<BitmapPredicate>,
pub with_items: Vec<ProjectionItem>,
pub return_items: Vec<ProjectionItem>,
pub return_alias: String,
pub limit: Option<u64>,
}
impl Ast {
pub fn to_json_pretty(&self) -> String
}
```
---
## WhereClause
```rust
pub enum WhereClause {
Function {
function: String,
args: Vec<String>,
operator: String,
threshold: String,
},
Comparison {
left: String,
operator: String,
right: String,
},
}
```
---
## VectorPredicate
Extracted from a `WHERE vector.<function>(target, $param) <operator> threshold` clause.
```rust
pub struct VectorPredicate {
pub function: String, // e.g. "cosine", "euclidean"
pub target: String, // e.g. "node.embedding"
pub param: String, // query parameter name, e.g. "$query_vec"
pub operator: String, // e.g. ">"
pub threshold: String, // e.g. "0.8"
}
```
---
## BitmapPredicate
Extracted from a `WHERE bitmap.contains(index_name, value_key) = 1` clause.
```rust
pub struct BitmapPredicate {
pub function: String, // "bitmap.contains"
pub index_name: String,
pub value_key: String,
}
```
---
## ProjectionItem
```rust
pub enum ProjectionItem {
Identifier(String),
Function {
name: String,
argument: String,
alias: Option<String>,
},
}
```
---
## TypedAst
The result of successful validation. Currently wraps `Ast` directly; it can carry richer type annotations in future revisions.
```rust
pub struct TypedAst {
pub ast: Ast,
}
```
---
## Errors
```rust
pub enum QueryError {
InvalidSyntax(String),
InvalidSemantic(String),
}
pub type Result<T> = std::result::Result<T, QueryError>;
```