Skip to main content

CommentSyntax

Struct CommentSyntax 

Source
pub struct CommentSyntax {
    pub line_comment_hash: bool,
    pub line_comment_ends_at_carriage_return: bool,
    pub nested_block_comments: bool,
    pub versioned_comments: Option<u32>,
    pub unterminated_block_comment_at_eof: bool,
}
Expand description

Dialect-owned comment syntax extensions.

Standard -- line comments and /* … */ block comments are always part of the baseline. These flags cover dialect-specific comment forms — and the dialect-specific shape of the baseline forms — whose recognition is an explicit dialect data decision.

Fields§

§line_comment_hash: bool

Treat # as a line-comment introducer (MySQL). One of several coexisting # claimants (see FeatureSet module docs, “Shared byte-trigger ownership: #”); trivia phase shadows identifier / XOR / positional readings when on. Do not also mark # an identifier-start in byte classes (T-SQL #temp), or the comment branch wins and #temp never lexes as a word (LexicalConflict::HashCommentVersusHashIdentifier).

§line_comment_ends_at_carriage_return: bool

Whether a bare carriage return (\r, 0x0d) ends a --/# line comment, on top of the newline (\n) that always ends one. PostgreSQL and DuckDB terminate a line comment at either \n or \r — their flex scanner’s comment body is [^\n\r]* (engine-verified: SELECT 1 -- c\rFROM reads FROM as a live token and rejects) — while SQLite and MySQL end it at \n alone, treating a \r as ordinary comment content (the same input is one comment to end-of-line, accepted). All four engines fold \r as whitespace outside a comment, so this flag governs only whether \r ends a comment, never how it lexes elsewhere. The terminating byte is left for the whitespace scan either way (\r is in CLASS_WHITESPACE for every preset), so it never joins the comment’s trivia span — matching PG, whose [^\n\r]* body excludes the \r. 0x0b/0x0c (vertical tab / form feed) sit in the flex space set but not its newline set, so they are never terminators here.

§nested_block_comments: bool

Whether /* … */ block comments nest: an inner /* raises a depth an inner */ must lower before the comment can close. PostgreSQL nests; MySQL ends every block comment at the first */ (engine-verified against mysql:8 — SELECT /* a /* b */ 1 parses as SELECT 1 there, while a nesting scanner reads it as an unterminated comment). The permissive nesting superset predates this flag, so every preset except MySQL keeps it on.

§versioned_comments: Option<u32>

MySQL versioned comments (/*! … */, /*!NNNNN … */) as conditional inclusion: the engine executes the body, so it is not a comment. None (every non-MySQL dialect) keeps the whole construct an ordinary block comment. Some(bound) models a server whose MYSQL_VERSION_ID is bound: the body lexes as live tokens when the version is absent or <= bound, and the region is discarded wholesale when the version exceeds it — exactly the engine’s include/skip gate.

Engine-verified semantics (probed against mysql:8, 8.4.10): the version is the digit run immediately abutting the ! (a space breaks it) — exactly five or exactly six digits form a version; 0–4 digits are not a version (the digits stay body tokens and the region is included unconditionally); from a run of ≥7 the first five are the version. Regions do not nest (a flag, not a depth): a passing inner /*!NNNNN marker is a no-op, a failing one discards only up to the next */, and the first region-level */ closes the region. A */ inside a string literal of an included body does not close it (the body is lexed normally), while a discarded body is raw bytes — not string-aware.

§unterminated_block_comment_at_eof: bool

Whether an unterminated /* … block comment running to end of input is silently closed (valid trailing trivia) rather than the pre-existing hard UnterminatedBlockComment error. SQLite’s tokenizer swallows a /* whose body runs off the end as a TK_SPACE (engine-measured on rusqlite: SELECT 1/* eof and a whitespace-wrapped \t\t/*\t\t both prepare), while every other engine rejects it.

The one exception, replicated here: SQLite treats a bare /* sitting exactly at end of input (no byte after the *, z[2]==0) as the / slash operator, not a comment — so /* alone and SELECT 1 /* still reject on both. The scanner honours this by opening a silently-EOF-closed comment only when a byte follows the /*. On for SQLite / Lenient, off elsewhere.

Implementations§

Source§

impl CommentSyntax

Source

pub const ANSI: Self

The ANSI predefined value.

Source§

impl CommentSyntax

Source

pub const LENIENT: Self

Available on crate feature lenient only.

LENIENT: accept # line comments (MySQL) on top of the baseline -- / /* */. Safe with STANDARD_BYTE_CLASSES, where # is not an identifier-start byte (conflict-resolution: a #-led identifier would be shadowed by the comment).

MySQL /*!…*/ versioned comments are conditional inclusion with an unbounded version gate (u32::MAX): a version-agnostic reader executes every conditional region rather than modelling one server’s skip window, so a MySQL or MariaDB dump’s /*!NNNNN … */ bodies always parse. Block-comment nesting stays on — the two knobs pull in opposite directions for MySQL fidelity, but LENIENT keeps the permissive PostgreSQL superset it has always accepted (nesting rejects strictly fewer inputs than it accepts only on the degenerate /* a /* b */-unbalanced family, which no dump emits).

Source§

impl CommentSyntax

Source

pub const MYSQL_8_VERSION_BOUND: u32 = 80499

Available on crate feature mysql only.

The MYSQL_VERSION_ID the fitted preset models for versioned-comment gating: the ceiling of the MySQL 8.4 LTS series the mysql:8 oracle image tracks. Real-world /*!NNNNN … */ markers name the released version a feature appeared in, so every id the 8.4 line can reach is included regardless of which 8.4.x patch the oracle runs, while 8.5+/9.x ids are skipped exactly as the live server skips them (engine-verified: /*!80500 … */ and /*!90000 … */ are discarded on 8.4.10). Pinning the oracle’s exact patch id instead would rot on every image bump; ids in the unreleased tail of the window (above the running patch, at most ..=80499) are the accepted approximation.

Source

pub const MYSQL: Self

Available on crate feature mysql only.

The MYSQL preset for comment syntax.

Source§

impl CommentSyntax

Source

pub const POSTGRES: Self

Available on crate feature postgres only.

The POSTGRES preset for comment syntax: the ANSI baseline with line comments additionally terminated by a carriage return.

PostgreSQL’s flex scanner defines a -- line comment as ("--"{non_newline}*) with non_newline [^\n\r], so the comment ends at the first \n or \r (engine-verified against libpg_query: SELECT 1 -- c\rFROM reads FROM as a live token and rejects, where the \n-only reading accepts). DuckDB shares this PostgreSQL-derived scanner, so it adopts this preset too — the only two shipped dialects whose line comments end at a bare \r (SQLite/MySQL keep the \n-only CommentSyntax::ANSI/::MYSQL reading). Everything else matches ANSI.

Source§

impl CommentSyntax

Source

pub const SQLITE: Self

Available on crate feature sqlite only.

The SQLITE preset for comment syntax.

SQLite’s block comments diverge from the ANSI baseline in two engine-measured ways (rusqlite): they do not nest (/* a /* b */ closes at the first */, so the whole input is one comment and accepts — a nesting scanner would read it as unterminated), and an unterminated /* … running to end of input is silently closed as trailing trivia rather than an error (SELECT 1/* eof, \t\t/*\t\t prepare). Line comments (--) stay \n-terminated like the ANSI baseline (a bare /* at EOF is the / slash operator, handled by the tokenizer — see the field doc).

Trait Implementations§

Source§

impl Clone for CommentSyntax

Source§

fn clone(&self) -> CommentSyntax

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 CommentSyntax

Source§

impl Debug for CommentSyntax

Source§

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

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

impl Eq for CommentSyntax

Source§

impl PartialEq for CommentSyntax

Source§

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

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.