Skip to main content

Module parser

Module parser 

Source
Expand description

Recursive-descent parser with a Pratt (precedence-climbing) sub-parser for expressions.

Precedence (lowest → highest binding): OR (1) < AND (2) < NOT unary (3) < comparisons = <> < <= > >= (4) < + - (5) < * / (6) < unary - (7) < parens / atom.

This matches PG’s behaviour for the operators we support — e.g. NOT a = b parses as NOT (a = b) and -a * b as (-a) * b.

Structs§

ParseError

Enums§

SciExpanded
v7.38 (read01) — parse a lexer Token::Numeric source string (digits with an optional single ., no sign, no exponent) into (unscaled, scale) for Literal::Numeric. Returns None if the mantissa overflows i128. v7.39 (read01 numeric.c) — the result of expanding an 1.5e3-style scientific literal into PG’s plain NUMERIC decimal form.

Functions§

expand_scientific_literal
Expand scientific notation into a plain decimal string by moving the decimal point — no float round-trip, so the value stays exact. PG treats such literals as NUMERIC; the digit-count caps mirror PG’s numeric format limits (“value overflows numeric format”).
is_multiword_type_phrase
v7.12.4 — map a bare type-name identifier (the form that appears in a function arg list or RETURNS clause) to a ColumnTypeName. Returns None for unknown / extension types so the caller can preserve them as FunctionArgType::Raw / FunctionReturn::Other.
parse_expression
v7.9.30 — parse a single expression (no trailing junk). Used by the engine to re-hydrate stored partial-index / unique-index predicates from their canonical Display form. The same Pratt parser the statement path uses; this entry point just skips the statement dispatch.
parse_function_body
v7.12.4 — parse a PL/pgSQL function body (the bytes between $$ ... $$). Returns the parsed BEGIN ... END; block.
parse_interval_text
parse_statement
Parse exactly one statement, swallow an optional trailing ;, and require the token stream to end there. PG string semantics.
parse_statement_with
v7.22 (round-13 T3) — dialect-aware entry: backslash_escapes selects MySQL-style string lexing (see lexer::tokenize_with). The engine threads its session flag through here.
syntax_error_position
v7.39 (read01 round 95) — recover PG’s 1-based CHARACTER error position for a ParseError::token_pos. Kept off the ParseError struct (and so off every recursive Result slot) to protect the nesting-budget frame cliff: this re-tokenizes input on the cold error path to map the failing token index to its start byte, then to a character offset. backslash_escapes must match the parse that produced token_pos (it barely shifts offsets, but stay consistent). Returns None when the index has no offset or the byte isn’t a char boundary. The wire attaches it as the ErrorResponse P.