This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
# Build
cargo build
# Run tests
cargo test
# Run a single test
cargo test test_name
# Run tests in a specific module
cargo test parser::tests
# Run the CLI
cargo run -- "SELECT * FROM users"
# Run the REPL
cargo run
# Run the CSV database example
cargo run --example csv_database seed # Seed sample data
cargo run --example csv_database -c "SELECT * FROM employees LIMIT 5"vibesql is a SQL parser and semantic analyzer conforming to ISO SQL standards with zero dependencies (standard library only).
SQL text → Lexer → Tokens → Parser → AST → Analyzer → Typed/Validated AST
↑
Catalog (schema metadata)-
lexer/ - Tokenizer that produces
TokenwithTokenKind(keywords, operators, literals). Keywords defined intoken.rswith reserved/non-reserved distinction. -
parser/ - Recursive descent parser split by SQL construct:
expr.rs- Expression parsing (operators, functions, CASE, etc.)query.rs- SELECT, FROM, JOIN, GROUP BY, HAVING, ORDER BY, window functionsstmt.rs- DDL/DML statements (CREATE, INSERT, UPDATE, DELETE, MERGE)
-
ast/ - AST node definitions:
expr.rs- Expression nodes (ExprKindenum)stmt.rs- Statement nodes (StatementKindenum)types.rs- Common AST types (Ident, ObjectName, Span)
-
analyzer/ - Semantic analysis:
mod.rs- MainAnalyzerstruct, query/statement analysisscope.rs- Name resolution scopes (Scope,ScopeTable,ScopeColumn)type_checker.rs- Expression type inferenceerror.rs- Analyzer-specific errors
-
catalog/ - Schema metadata abstraction:
Catalogtrait - Interface for storage backendsMemoryCatalog- In-memory implementation with builtin functionsCatalogBuilder- Fluent API for building custom catalogsTypeRegistry- Type alias managementTableSchema,ColumnSchema- Table/column definitionsFunctionSignature- Function metadata (scalar/aggregate/window)
-
types/ - SQL type system:
SqlTypeenum - All SQL types (INTEGER, BIGINT, VARCHAR, ARRAY, STRUCT, etc.)Value- Runtime values
Use CatalogBuilder to create catalogs with custom functions, tables, and type aliases:
use vibesql::catalog::{CatalogBuilder, TypeRegistry};
use vibesql::types::SqlType;
let catalog = CatalogBuilder::new()
.with_builtins() // Include standard functions
.add_scalar_function("MY_HASH", SqlType::Int64) // Custom function
.add_aggregate_function("MY_AGG", SqlType::Float64) // Custom aggregate
.add_table("users", |t| { // Custom table
t.primary_key("id", SqlType::Int64)
.column("name", SqlType::Varchar)
})
.build();Use TypeRegistry for custom type aliases:
let mut registry = TypeRegistry::new();
registry.add_alias("SERIAL", SqlType::Int32);
registry.add_alias("MONEY", SqlType::Numeric { precision: Some(19), scale: Some(4) });-
Parser utilities in
parser/mod.rs:parse_comma_separated,parse_optional_alias,expect_keyword- reused across all parsing modules. -
Scope stack in analyzer: Pushed for subqueries/CTEs, enables proper name resolution.
-
Catalog trait: Storage backends implement this to provide schema info to the analyzer.
The docs/sql/ directory contains SQL language specification based on ISO/IEC 9075 (SQL standard):
syntax/- Lexical structure, query syntax, operators, subqueriestypes/- Data types, arrays, conversion rules, collationstatements/- DDL (CREATE/ALTER/DROP) and DML (INSERT/UPDATE/DELETE)functions/- Scalar, aggregate, window, and time series functions
Each directory has a README.md index.