Skip to main content

Crate surql_parser

Crate surql_parser 

Source
Expand description

surql-parser — Standalone SurrealQL parser extracted from SurrealDB.

Provides a complete SurrealQL parser without depending on the SurrealDB engine. Useful for building tools, linters, formatters, IDE extensions, and migration systems.

§Quick Start

let ast = surql_parser::parse("SELECT name, age FROM user WHERE age > 18").unwrap();
assert!(!ast.expressions.is_empty());

§Sync with SurrealDB

Parser source is auto-extracted from SurrealDB via tools/transform/. See UPSTREAM_SYNC.md for details.

Re-exports§

pub use error::Error;
pub use error::Result;
pub use keywords::all_keywords;
pub use upstream::sql::Ast;
pub use upstream::sql::expression::Expr;
pub use upstream::syn::ParserSettings;
pub use upstream::sql::Kind;
pub use upstream::sql::Idiom;
pub use upstream::sql::statements;
pub use upstream::syn::error as syntax_error;
pub use recovery::parse_with_recovery;
pub use schema_graph::DependencyNode;
pub use schema_graph::SchemaGraph;
pub use filesystem::*;
pub use params::*;
pub use schema_lookup::*;

Modules§

builtins_generated
compat
Compatibility stubs for types referenced by the upstream parser code.
config
Configuration constants for the parser.
diff
Schema diffing — compare two SchemaGraphs and report structural changes.
doc_urls
Auto-generated documentation URL mapping for SurrealQL. Generated from docs.surrealdb.com content on 2026-03-23.
error
Custom error types for the surql-parser public API.
filesystem
formatting
Configurable SurrealQL formatter.
keywords
lint
SurrealQL linter — static analysis for common schema issues.
params
recovery
Error-recovering parser — parses valid statements even when some are broken.
schema_graph
Schema graph — semantic model built from SurrealQL definitions.
schema_lookup
upstream
Auto-generated from SurrealDB source. DO NOT EDIT MANUALLY.

Structs§

ParseDiagnostic
A parse diagnostic with source location.
SchemaDefinitions

Functions§

builtin_function
Look up a built-in SurrealQL function by its full name (e.g., "string::len").
builtins_in_namespace
Return all built-in functions in a given namespace (e.g., "string" returns all string::*).
extract_definitions
Extract all DEFINE statements from a SurrealQL string.
extract_definitions_from_ast
Extract definitions from pre-parsed statements (e.g., from error-recovering parser).
format
Format an AST back to SurrealQL string.
is_reserved_keyword
Check if a string could be a reserved keyword in certain contexts.
list_functions
List all function names defined in a SurrealQL string.
list_tables
List all table names defined in a SurrealQL string.
parse
Parse a SurrealQL query string into an AST.
parse_for_diagnostics
Parse SurrealQL and return structured diagnostics on error.
parse_kind
Parse a SurrealQL type annotation (e.g., record<user>, option<string>).
parse_with_settings
Parse a SurrealQL query with custom parser settings.