Use Cases
- Migration tools and schema analyzers
- Linters and formatters for
.surqlfiles - IDE extensions (Zed, VS Code) with syntax analysis
- Code generation from SurrealQL definitions
- CI validation of SurrealQL files
Quick Start
use parse;
let ast = parse.unwrap;
assert_eq!;
Parse DDL
let ast = parse.unwrap;
Parse type annotations
let kind = parse_kind.unwrap;
Extract schema definitions
let defs = extract_definitions.unwrap;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
Check reserved keywords
assert!;
assert!;
Compile-Time Tools
surql-macros — proc-macro crate
Validate SurrealQL at compile time:
[]
= "0.1"
use ;
// Compile-time validated query — typo here is a compile error
const QUERY: &str = surql_check!;
// Compile-time validated function name
Errors show both the SurrealQL location and the Rust source location:
error: Invalid SurrealQL: Unexpected token `WHERE`, expected FROM
--> [1:10]
|
1 | SELECT * WHERE age > 18
| ^^^^^
build.rs helper (feature build)
Validate .surql files and generate typed constants at build time:
[]
= { = "0.1", = ["build"] }
// build.rs
This generates constants like FN_GET_USER: &str = "fn::get_user" with doc comments showing parameter types and return types. See examples/sample-project/ for a complete working example.
CLI Tool
Testing
Validation deps (surrealdb, testcontainers) are dev-dependencies only — they don't leak to library consumers.
SurrealDB Compatibility
| surql-parser | SurrealDB | Status |
|---|---|---|
| 0.1.x | 3.x | Active |
Parser source is auto-synced from SurrealDB via an automated pipeline. See UPSTREAM_SYNC.md for details.
How It Works
The parser source code is extracted from SurrealDB using an AST-level Rust transformer (tools/transform/). This ensures 100% compatibility with SurrealDB's parser while removing engine-specific execution code.
The sync pipeline:
- Copies
syn/(lexer, parser) andsql/(AST types) from SurrealDB source - Rewrites imports via declarative rules (
mappings.toml) - Strips execution-layer code (318 impl blocks removed automatically)
- Validates compilation
Workspace
This repository is a Rust workspace with several crates:
| Crate | Description |
|---|---|
surql-parser |
Core parser — AST, schema graph, formatting, linting, diff |
surql-macros |
Compile-time validation with schema-aware type checking |
surql-lsp |
Language Server — hover, completions, rename, diagnostics, 8 slash commands |
surql-mcp |
MCP playground — 15 tools (query, graph, verify, rollback) |
overshift |
Migration engine — schema modules, rollback, shadow DB verification |
surql CLI |
check, fmt, info, diff, docs, lint, test |
| Zed extension | Syntax highlighting, 8 slash commands, MCP context server |
| VS Code extension | TextMate grammar, LSP client |
License
Apache 2.0 — same as SurrealDB.