Skip to content

[BUG] JSQLParser 5.4-SNAPSHOT : MySQL : # line comments are not supported #2499

Description

@fudianchn

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

Failing SQL Feature:

MySQL # line comments are not parsed. MySQL supports # to end of line as a comment style (MySQL 8.0 Manual, Comments). JSqlParser handles -- and /* */, but # fails.

Context: # is currently lexed for the PostgreSQL JSON operators #> and #>> (JSqlParserCC.jjt, token handling around line 8403). A line comment rule must not swallow those: with javacc longest-match, a plain # to end of line token would also consume #> / #>>, so the comment rule needs to exclude a > immediately after #.

SQL Example:

SELECT 1 # comment
net.sf.jsqlparser.JSQLParserException: net.sf.jsqlparser.parser.ParseException: Encountered: <K_COMMENT> / "comment", at line 1, column 12, in lexical state DEFAULT.

A standalone comment line fails the same way:

SELECT 1
# trailing comment
net.sf.jsqlparser.parser.ParseException: Encountered: <K_TRAILING> / "trailing", at line 2, column 3, in lexical state DEFAULT.

SELECT 1 -- comment parses fine.

Software Information:

  • JSqlParser version: master 1e4e92b (also present in 5.1)
  • Database: MySQL 8.0

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