pub struct StringLiteralSyntax {
pub escape_strings: bool,
pub dollar_quoted_strings: bool,
pub national_strings: bool,
pub double_quoted_strings: bool,
pub backslash_escapes: bool,
pub unicode_strings: bool,
pub bit_string_literals: bool,
pub blob_literals: bool,
pub charset_introducers: bool,
pub same_line_adjacent_concat: bool,
}Expand description
Dialect-owned string literal syntax extensions.
Standard single-quoted strings are always part of the baseline. These flags cover dialect-specific forms whose recognition must be an explicit dialect data decision, not a parser-side type check. Each is a lexical gate: it changes which token the scanner emits, never how a value is materialized (deferred).
Fields§
§escape_strings: boolAccept PostgreSQL E'...' escape string constants.
dollar_quoted_strings: boolAccept PostgreSQL $tag$...$tag$ dollar-quoted string constants.
national_strings: boolAccept N'...' national-character string constants (T-SQL; PostgreSQL
sugar). Lexes as a String token spanning the N prefix.
double_quoted_strings: boolLex "..." as a string constant rather than a quoted identifier (MySQL
without ANSI_QUOTES). Takes precedence over identifier quoting for ",
so a preset enabling this must not also list " in identifier_quotes.
backslash_escapes: boolHonour C-style backslash escapes inside '...' (and double-quoted) strings
for termination (MySQL default; not T-SQL), so 'a\'b' is one token. The
escape is recognised lexically only; value materialization stays deferred.
This bool collapses what PostgreSQL historically made a tri-state: legacy
standard_conforming_strings = off made a plain '…' backslash-aware too — a
third mode distinct from both the modern-off default and MySQL’s always-on. The
bool covers every shipped preset (modern PostgreSQL off, MySQL on); the
version-varying third mode belongs to the deferred per-release version presets
(prod-dialect-release-version-presets), which own version-varying knobs.
unicode_strings: boolAccept U&'...' Unicode-escape string constants (SQL standard, PostgreSQL).
bit_string_literals: boolAccept B'...' / X'...' bit-string constants (SQL standard, PostgreSQL).
Lexes as a String token spanning the B/X prefix; the binary-vs-hex
radix and the digit validation are recovered later, so a
malformed body like X'1FG' still lexes (PostgreSQL defers the check too).
blob_literals: boolAccept SQLite/MySQL x'53514C' / X'53514c' hexadecimal byte-string literals
(SQLite’s BLOB literal; MySQL’s hexadecimal literal). Only the x/X hex marker
— the B'…' binary form is bit_string_literals,
not this — and the quote must abut the marker (like E'/B').
Unlike a PostgreSQL/DuckDB deferred bit-string, the body is validated eagerly at
lex time: it must be an even number of ASCII hex digits (each pair is one
byte), so an odd-length (x'ABC', x'0') or non-hex (x'XY') body is a
tokenize-time syntax error — the rule both engines enforce (probed: SQLite
“unrecognized token”, MySQL ER_PARSE_ERROR). The empty body x'' is a valid
zero-byte blob. It lexes as a String token spanning the marker and classifies as
a hex BitString — the same canonical
hex-digit-string shape as X'…', differing only in this eager lex-time bound; the
spelling round-trips from the span and a consumer reads the bytes via
as_bit_text.
Disjoint from bit_string_literals on the shared x/X marker by scan
precedence: where both are on (MySQL), the eager hex arm claims x/X and the
deferred bit arm keeps B/b; where only bit_string_literals is on
(PostgreSQL) X'…' stays the deferred bit-string (odd-length allowed).
charset_introducers: boolAccept MySQL _charset'...' character-set introducers — an _-prefixed
charset name abutting a string constant (_utf8mb4'x', _latin1'x'). Like
the N'...' national prefix this lexes as one String token spanning the
introducer; the charset name is a surface tag that rides the span and is
recovered on demand, and the value materialises with the
introducer stripped. The abutting ' is required — a bare _name with no
quote stays an ordinary identifier — so with this off _utf8'x' lexes as the
identifier _utf8 then a string (the ANSI/PostgreSQL behaviour).
same_line_adjacent_concat: boolConcatenate adjacent string literals separated by whitespace with no newline
('a' 'b' on one line → 'ab'), MySQL’s rule. The SQL standard (and the default
here) requires a newline in the separator, so 'a' 'b' same-line is
otherwise an adjacency error. Not a lexical gate — each literal still tokenizes
separately; the parser reads this at the continuation-gap classification point and
the AST materializer walks the folded span the same way it walks the newline form.
A comment in the gap still blocks concatenation under either rule.
Implementations§
Source§impl StringLiteralSyntax
impl StringLiteralSyntax
Sourcepub const BIGQUERY: Self
Available on crate feature bigquery only.
pub const BIGQUERY: Self
bigquery only.BigQuery string surface: the ANSI baseline plus "…" double-quoted string constants
(BigQuery quotes strings with both '…' and "…", reserving the backtick for
identifiers). Enabling this is what lets BIGQUERY_IDENTIFIER_QUOTES drop " from the
quote set without stranding the byte. Every other string knob is conservatively ANSI —
BigQuery’s backslash escape sequences have no BigQuery-citing flag doc or oracle here and
are deferred rather than guessed at (backslash_escapes stays off).
Source§impl StringLiteralSyntax
impl StringLiteralSyntax
Sourcepub const HIVE: Self
Available on crate feature hive only.
pub const HIVE: Self
hive only.Hive string surface: the ANSI baseline plus "…" double-quoted string constants (HiveQL
string literals may be written with single or double quotes, reserving the backtick
for identifiers). Enabling this is what lets HIVE_IDENTIFIER_QUOTES drop " from the
quote set without stranding the byte. Every other string knob is conservatively ANSI —
Hive’s backslash escape sequences have no Hive-citing flag doc or oracle here and are
deferred rather than guessed at (backslash_escapes stays off).
Source§impl StringLiteralSyntax
impl StringLiteralSyntax
Sourcepub const LENIENT: Self
Available on crate feature lenient only.
pub const LENIENT: Self
lenient only.LENIENT: every dialect string form except double_quoted_strings.
double_quoted_strings is OFF because " is a quoted-identifier delimiter here
(conflict-resolution rule 1). backslash_escapes is ON: it is a strict superset
of escape recognition — the standard '' doubling still closes a string, and \'
additionally escapes — so it accepts the most input (the one form it changes is a
trailing 'a\', which becomes an escaped quote rather than a close).
national_strings is ON from the MySQL/T-SQL presets (PostgreSQL does not arm it —
its scanner has no N'…' constant and reads N'x' as the typed literal nchar 'x';
see the POSTGRES preset). Keeping it here means N'x' lexes as one national-string
token under LENIENT, shadowing that PG typed-literal reading. This is a grammar-level
shape choice, not a LexicalConflict: the alternative
reading is the parser’s typed-literal fallback, not a second enabled lexer claimant,
and both readings accept — so the union keeps the token form, consistent with the
accept-most-input model.
Trait Implementations§
Source§impl Clone for StringLiteralSyntax
impl Clone for StringLiteralSyntax
Source§fn clone(&self) -> StringLiteralSyntax
fn clone(&self) -> StringLiteralSyntax
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more