Skip to main content

NumericLiteralSyntax

Struct NumericLiteralSyntax 

Source
pub struct NumericLiteralSyntax {
    pub hex_integers: bool,
    pub octal_integers: bool,
    pub binary_integers: bool,
    pub underscore_separators: bool,
    pub radix_leading_underscore: bool,
    pub reject_trailing_junk: bool,
    pub money_literals: bool,
}
Expand description

Dialect-owned numeric literal syntax extensions.

Standard decimal/scientific numbers are always part of the baseline. These flags cover non-ANSI numeric forms whose recognition is an explicit dialect data decision. Each is lexical: it widens which numbers the scanner accepts as one token; value materialization stays deferred. The radix and separator forms below are PostgreSQL 14+ additions (also in T-SQL / MySQL for hex), so a release-pinned PostgreSQL preset gates them by version.

Fields§

§hex_integers: bool

Accept 0x.. hexadecimal integer literals (T-SQL, MySQL, PostgreSQL 14+).

§octal_integers: bool

Accept 0o.. octal integer literals (PostgreSQL 14+).

§binary_integers: bool

Accept 0b.. binary integer literals (MySQL, PostgreSQL 14+).

§underscore_separators: bool

Accept _ digit-group separators between digits (PostgreSQL 14+), e.g. 1_500_000. Recognised lexically only when a digit follows the _. When reject_trailing_junk is off the placement is loose (a _ is a separator wherever a digit follows it); when it is on the placement is strict (a decimal _ must sit between two digits, matching PG’s {decdigit}(_?{decdigit})*), so a leading-in-fraction/trailing/doubled _ stops the number and surfaces as trailing junk. Whether a _ may additionally lead a radix body (0x_1F) is a separate axis (radix_leading_underscore), because PG and SQLite disagree on it.

§radix_leading_underscore: bool

Accept a leading _ immediately after a radix marker, before the first radix digit (0x_1F, 0b_101) — PostgreSQL’s 0[xX](_?{hexdigit})+ grammar, which admits the underscore ahead of the first digit. Requires underscore_separators; an interior radix _ (0x1_F) rides that flag alone and is unaffected by this one.

Its own axis rather than a rider on reject_trailing_junk because the engines that reject trailing junk still split on it: PostgreSQL accepts 0x_1F (probed) but SQLite rejects it — SQLite’s radix grammar is 0[xX]{hexdigit}(_?{hexdigit})*, requiring a digit before the first _. With this off a leading-underscore radix body does not open, so 0x_1F falls back to the bare 0 plus a x_1F word/alias (loose dialects) or a trailing-junk reject (strict ones), exactly as before this axis existed.

§reject_trailing_junk: bool

Reject an identifier-start character abutting a numeric literal — PostgreSQL’s “trailing junk after numeric literal” scanner error (123abc, 1x, 0.0e, 100_), plus the bad-radix (0x, 0b0x) and misplaced-separator (100__000, 1_000._5) forms that decompose to it. A number is a maximal-munch lexeme, so with this on anything identifier-ish immediately following one is a lexer error, not a new token; it also switches underscore_separators to strict placement.

Dialect-gated because the reject is not universal: PostgreSQL and SQLite reject these (both probed against their engines), but DuckDB accepts them all (it re-reads 123abc as 123 aliased) and MySQL only rejects the integer/radix forms — so a dialect that lexes its numerics loosely (DuckDB/MySQL) leaves this off and the trailing text falls through to the ordinary word/alias scan, exactly as before.

§money_literals: bool

Accept $1234.56 / $.5 T-SQL money literals (the $ currency sigil prefixes a decimal). Off in ANSI/PostgreSQL: PostgreSQL spells $ as a positional parameter ($1) or a dollar-quote ($tag$), never money, so the three $-prefix lexer forms are dialect-disjoint. Lexes as a Number token spanning the $; the money type rides the literal kind and the sigil is stripped at the accessor, like the B/X bit-string prefix.

Implementations§

Source§

impl NumericLiteralSyntax

Source

pub const ANSI: Self

The ANSI predefined value.

Source§

impl NumericLiteralSyntax

Source

pub const DUCKDB: Self

Available on crate feature duckdb only.

The DUCKDB preset for numeric literal syntax.

Source§

impl NumericLiteralSyntax

Source

pub const LENIENT: Self

Available on crate feature lenient only.

LENIENT: every radix and separator form, but not money_literals.

money_literals is OFF because $+digit is a positional parameter here (conflict-resolution rule 3): the two cannot coexist, and $1 parameters are the dominant real-world meaning.

Source§

impl NumericLiteralSyntax

Source

pub const MSSQL: Self

Available on crate feature mssql only.

MSSQL numeric surface: the ANSI baseline plus $1234.56 / $.5 money literals. Every other numeric knob is conservatively ANSI.

Source§

impl NumericLiteralSyntax

Source

pub const MYSQL: Self

Available on crate feature mysql only.

The MYSQL preset for numeric literal syntax.

Source§

impl NumericLiteralSyntax

Source

pub const POSTGRES: Self

Available on crate feature postgres only.

The POSTGRES preset for numeric literal syntax.

Source§

impl NumericLiteralSyntax

Source

pub const SQLITE: Self

Available on crate feature sqlite only.

The SQLITE preset for numeric literal syntax.

Trait Implementations§

Source§

impl Clone for NumericLiteralSyntax

Source§

fn clone(&self) -> NumericLiteralSyntax

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 NumericLiteralSyntax

Source§

impl Debug for NumericLiteralSyntax

Source§

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

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

impl Eq for NumericLiteralSyntax

Source§

impl PartialEq for NumericLiteralSyntax

Source§

fn eq(&self, other: &NumericLiteralSyntax) -> 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 NumericLiteralSyntax

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.