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: boolTreat # as a line-comment introducer (MySQL). Mutually exclusive with
using # as an identifier byte (T-SQL #temp): a dialect that sets this
must not also mark # an identifier-start in its byte classes, or the
comment branch wins and #temp would never lex as a word.
line_comment_ends_at_carriage_return: boolWhether 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: boolWhether /* … */ 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: boolWhether 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
impl CommentSyntax
Source§impl CommentSyntax
impl CommentSyntax
Sourcepub const LENIENT: Self
Available on crate feature lenient only.
pub const LENIENT: Self
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
impl CommentSyntax
Sourcepub const MYSQL_8_VERSION_BOUND: u32 = 80499
Available on crate feature mysql only.
pub const MYSQL_8_VERSION_BOUND: u32 = 80499
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§impl CommentSyntax
impl CommentSyntax
Sourcepub const POSTGRES: Self
Available on crate feature postgres only.
pub const POSTGRES: Self
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
impl CommentSyntax
Sourcepub const SQLITE: Self
Available on crate feature sqlite only.
pub const SQLITE: Self
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
impl Clone for CommentSyntax
Source§fn clone(&self) -> CommentSyntax
fn clone(&self) -> CommentSyntax
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more