Skip to main content

Module parser

Module parser 

Source
Expand description

The recursive-descent statement parser.

Invariant: the parser performs no I/O and consults no catalog. It turns bytes into an arena tree and nothing else, which is what lets a syntax error be reported before a file is opened and lets the same parser run inside the catalog loader on the CREATE text stored in sqlite_schema.

Depth is bounded before allocation rather than after: every recursive entry charges the expression-depth limit, so an adversarial ((((((... fails with a limit error at a known offset instead of growing the arena until something else notices.

One call parses one statement and reports how many bytes it consumed, which is SQLite’s prepare contract: the caller gets a statement and the unused tail, and an empty statement succeeds with no program.

Structs§

ParameterMap
Where a statement’s parameters ended up.
ParsedStatement
One parsed statement and everything the caller needs to continue.
Parser
The parser: a lexer, a token buffer, an arena, and a depth charge.

Enums§

StatementClass
What a statement is, decided without a full parse.

Functions§

classify_statement
Classifies a statement from its leading keywords alone.
parse_expression
Parses a bare expression, which is what a CHECK constraint or a default value is when it is re-read out of sqlite_schema.
parse_next_statement
Parses the next statement beginning at offset.
parse_next_statement_into
Parses one statement into an arena the caller supplies.