Skip to content

[FEATURE] dialect presets for the lexer-level feature switches #2510

Description

@fudianchn

AI disclosure: this issue was prepared with AI coding agents, reviewed and revised line by line by me.

Grammar or Syntax Description

Not a single grammar production, but the switch layer below it. JSqlParser now has three lexer-level switches, each added when one lexeme carries different meanings in two dialects:

Every lexeme conflict settled the same way adds one more switch, and every user of a dialect then has to know and wire the full set by hand:

CCJSqlParserUtil.parse(sql, parser -> parser.withBackslashEscapeCharacter(true)
        .withHashLineComments(true));

Proposal: a preset layer so one call selects the dialect's full switch set. Prototyping found the parser already owns a narrow Dialect enum (ORACLE, EXASOL) behind withDialect(Dialect) for grammar gating, so extending that enum keeps a single entry point:

CCJSqlParserUtil.parse(sql, parser -> parser.withDialect(Dialect.MYSQL));

Pure data mapping, no mechanism changes: individual switches keep working and override the preset.

SQL Example

One statement, MySQL reading, today vs proposed:

-- MySQL: `col` is a quoted identifier, 'x\'yz' keeps the escaped quote, 42#24 is 42 plus a line comment
SELECT `col` FROM t WHERE a = 'x\'yz' AND b = 42#24

today: two switches wired manually per parse call (backticks already parse by default, brackets are not MySQL syntax); proposed: withDialect(Dialect.MYSQL) once.

Additional context

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions