Skip to main content

StringLiteralSyntax

Struct StringLiteralSyntax 

Source
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: bool

Accept PostgreSQL E'...' escape string constants.

§dollar_quoted_strings: bool

Accept PostgreSQL $tag$...$tag$ dollar-quoted string constants.

§national_strings: bool

Accept N'...' national-character string constants (T-SQL; PostgreSQL sugar). Lexes as a String token spanning the N prefix.

§double_quoted_strings: bool

Lex "..." 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: bool

Honour 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: bool

Accept U&'...' Unicode-escape string constants (SQL standard, PostgreSQL).

§bit_string_literals: bool

Accept 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: bool

Accept 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: bool

Accept 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: bool

Concatenate 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

Source

pub const ANSI: Self

The ANSI predefined value.

Source§

impl StringLiteralSyntax

Source

pub const BIGQUERY: Self

Available on crate feature 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

Source

pub const HIVE: Self

Available on crate feature 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

Source

pub const LENIENT: Self

Available on crate feature 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.

Source§

impl StringLiteralSyntax

Source

pub const MSSQL: Self

Available on crate feature mssql only.

MSSQL string surface: the ANSI baseline plus N'…' national-character string constants. backslash_escapes stays off (its doc reads “MySQL default; not T-SQL”). Every other string knob is conservatively ANSI.

Source§

impl StringLiteralSyntax

Source

pub const MYSQL: Self

Available on crate feature mysql only.

The MYSQL preset for string literal syntax.

Source§

impl StringLiteralSyntax

Source

pub const POSTGRES: Self

Available on crate feature postgres only.

The POSTGRES preset for string literal syntax.

Source§

impl StringLiteralSyntax

Source

pub const SQLITE: Self

Available on crate feature sqlite only.

The SQLITE preset for string literal syntax.

Trait Implementations§

Source§

impl Clone for StringLiteralSyntax

Source§

fn clone(&self) -> StringLiteralSyntax

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for StringLiteralSyntax

Source§

impl Debug for StringLiteralSyntax

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for StringLiteralSyntax

Source§

impl PartialEq for StringLiteralSyntax

Source§

fn eq(&self, other: &StringLiteralSyntax) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for StringLiteralSyntax

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.