aiondb-parser

Lexer, token validator and recursive-descent parser that turns SQL (and Cypher) text into the AST consumed by the planner. The crate enforces hard limits on input size, token count, identifier length and bracket nesting depth before any recursive parsing begins, so the planner never sees inputs that could exhaust the stack or balloon allocations.

cargo

[dependencies]
aiondb-parser = { path = "../aiondb-parser" }

modules

modulepurpose
astSQL statement AST (Statement, SelectStatement, expressions, DDL/DML nodes).
cypher_astCypher AST (CypherStatement, CypherClause, patterns).
identifierIdentifier classification helpers.
keywordsReserved-word table (Keyword).
lexerlex_sql and the raw lexer driver.
tokensToken and TokenKind.
spanSpan source-position type.
parser_aclGRANT / REVOKE parsing.
parser_asyncLISTEN / NOTIFY / UNLISTEN.
parser_backupBackup-related statements.
parser_commentCOMMENT ON ....
parser_copyCOPY statement.
parser_cypherCypher entrypoint.
parser_ddl / parser_ddl_extCREATE / ALTER / DROP for tables, indexes, sequences, views, triggers, schemas, roles, extensions.
parser_dmlINSERT, UPDATE, DELETE, MERGE.
parser_exprExpression precedence climber.
parser_funcFunction-call and aggregate parsing.
parser_lockLOCK TABLE.
parser_ownedDROP OWNED / REASSIGN OWNED.
parser_security_labelSECURITY LABEL ....
parser_selectSELECT, set operations, CTEs.
parser_sessionSET / RESET / SHOW / DISCARD.
parser_txTransaction-control statements.
parser_typesType-name parsing.

entry points

functioninputoutput
parse_sql(sql: &str)full SQL textDbResult<Vec<Statement>>
parse_prepared_statement(sql: &str)a single statementDbResult<Statement>
parse_expression(sql: &str)a single expressionDbResult<Expr>
parse_cypher(sql: &str)Cypher textDbResult<CypherStatement>

Every entry point first runs lex_and_validate, which rejects oversized inputs and unbalanced brackets in a single O(n) pass.

key types

limits

The crate publishes its own resource ceilings and surfaces them through DbError::program_limit when violated. The defaults are:

namevaluemeaning
MAX_SQL_INPUT_BYTES64 MiBrejects oversized SQL text up front.
MAX_TOKEN_COUNT500000upper bound on tokens per statement.
MAX_IDENTIFIER_TOKEN_LEN1024per-identifier byte length.
DEFAULT_MAX_NESTING_DEPTH32 (debug) / 48 (release)parenthesis and bracket nesting.

Nesting depth can be overridden through AIONDB_PARSER_MAX_NESTING_DEPTH, clamped to [8, 128].

example

use aiondb_parser::{parse_sql, parse_expression, Statement};

let stmts = parse_sql("select 1 + 2; select 'hi'").expect("parse");
assert_eq!(stmts.len(), 2);
assert!(matches!(stmts[0], Statement::Select(_)));

let expr = parse_expression("a + b * 2").expect("expr");
let _ = expr;