| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
A '#' followed by a blank now lexes as a line comment, the MySQL form from issue JSQLParser#2499. '#' without a following blank keeps its current lexing: identifier start (SQL Server #temp, ##global) and the JSON operators #> / #>> are unchanged. Signed-off-by: Fu Dian <fudianchn@gmail.com>
Ooofffff! |
Sorry, something went wrong.
For completeness on the lexeme: besides the bitwise XOR row in Table 9.4, Mathematical Operators (integral_type # integral_type → integral_type, "Bitwise exclusive OR", 17 # 5 → 20), the current documentation (PostgreSQL 18) gives # three more meanings, all in Table 9.36, Geometric Operators:
Sources: Mathematical Functions and Operators, Geometric Functions and Operators |
Sorry, something went wrong.
|
Honestly a tough call, we are doomed when we do and also when we don't.
I am in favor of 1) or 3), but I won't oppose when you prefer 2). You have provided so much good stuff that I trust your good judgement. |
Sorry, something went wrong.
|
My position up front: either leave it as is (closing this PR is fine with me), or fix it properly with a switch, so that no reading silently loses data. The proper fix is an architecture decision that is yours to make; I will not push it unilaterally.
The simplest decision. Put "never silently change semantics" first, and current master is not only acceptable but safer than this PR. First-hand runs on both sides (master 1e4e92b vs PR branch eaf9884, each built locally; re-checked on current master 4c6a4fb):
All three are correct under real MySQL semantics, so for the MySQL reading this PR fixes a real gap. The problem is the other reading: data silently lost, no error at all. Master is the only state where neither reading gets silently changed. The "I want it all" route. My gut reaction to such conflicts is "I want it all :)", so I searched the code for switch-like mechanisms and found the earlier cases:
This class of problem has come up more than once, so for maintaining these switches we could consider a Feature set + Dialect enum extension, in three phases as I expect it:
If it is not worth it. The flag mechanism has existed for over six years and one more flag is cheap, so the real question is not feasibility but which side the default takes. My preference is PG syntax by default, for two reasons:
With PG as the default, if real demand shows up on the MySQL side, one flag (off by default) enables # comments. And whether that single flag or the dialect presets above, once a switch exists the dividing line is the same: on the MySQL side # is an unconditional line comment (in real MySQL semantics 42#24 is a comment too; in that mode there is no competing #temp, #> or XOR need, so not even the space gate is needed); on the PG side # is all operators (#>/#>>/#- JSON family plus bare #), with no # comment. The two modes do not leak into each other. |
Sorry, something went wrong.
|
Greetings, this would be the best indeed and you are right: token manipulation should work although there is one particular challenge here. SPECIAL_TOKEN vs. TOKEN, so far we have manipulated only TOKEN vs. TOKEN. JavaCC is very poorly equipped for such use-cases and we won't get any help from anyone. But if you want to do this, you have my full support. I would suggest starting to implement the Postgres INTERSECT operator, because this has some merit on its own. Once this works, we try to bend the token into a Special Token so it finds MySQL comments. |
Sorry, something went wrong.
First step up for review: #2507, the Postgres # binary operator (bitwise XOR, docs Table 9.4; geometric intersection of lseg / line / box, Table 9.36). A dedicated token declared before S_IDENTIFIER wins the length tie on a lone #; longest match keeps every other # lexing untouched (#temp, ##global, #$tab1#, a#b, #>, #>>). The operator assertions were verified failing on master and passing on the branch; the guard test pins the identifier and JSON families. One behavior delta disclosed there: a lone # can no longer be an identifier, so bare names (SELECT # FROM t, SELECT 1 #, ...) fail loudly instead of parsing silently; quoted "#" still parses. Second step: Feature.allowHashLineComments (off by default) routing # into a Special Token per lexer state, so MySQL line comments work under the switch. A spike says MORE + SwitchTo handles it; #word adjacency and SELECT 1 # at EOF are the open edges to disclose in that PR. I will start on it once this lands. |
Sorry, something went wrong.
|
I assume, this is obsolete after #2508? |
Sorry, something went wrong.
…nts (#2508) * feat(parser): support MySQL # line comments behind allowHashLineComments The second step agreed in #2502: with Feature.allowHashLineComments (default off) a `#` runs to end of line as a comment, unconditional like MySQL itself (no blank needed, `42#24` is a comment too); with the flag off a lone `#` stays the binary operator introduced in #2507, so neither reading silently replaces the other. Mechanics: under the flag SimpleCharStream rewrites a token-start `#` in the buffer to a character no other lexical rule starts with, so the dedicated HASH_LINE_COMMENT production wins the match for every `#` form while identifier and JSON-operator lexing of the default mode stay untouched (rewriting the buffer keeps the matcher's backup / re-read arithmetic intact, and GetImage() restores the `#` in the token image). Unquoted identifiers (and @@variables) end at their first `#` via their token actions, which re-lex the remainder as the comment. Quoted forms ("#", `#`, "a#b") keep their `#` in both modes. Under the flag the statement semantics are MySQL's: `SELECT #temp FROM t` comments out the rest of the line and fails, quoted "#temp" still parses. Closes #2499, supersedes #2502. Signed-off-by: Fu Dian <fudianchn@gmail.com> * docs(parser): add regeneration warning to SimpleCharStream header The file is maintained by hand on top of the JavaCC template and carries the in-buffer rewrite of a leading # in BeginToken(), which Feature.allowHashLineComments depends on. Per review on #2508. --------- Signed-off-by: Fu Dian <fudianchn@gmail.com>
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
AI disclosure: this change was prepared with AI coding agents, reviewed and revised line by line by me.
What
Support MySQL # line comments, fixing #2499:
Both forms currently fail with a ParseException: # lexes as an identifier and the comment text then fails as keywords (SELECT 1 # comment fails on comment).
Why / Root cause
LINE_COMMENT only knows -- and //. A # falls through to the identifier token (# is a legal identifier start and part character), so the comment text itself has to parse and does not.
How
One additional alternation in the LINE_COMMENT token: a # followed by a blank runs to end of line. The blank gate keeps every existing # lexing intact:
Scope
Testing
CCJSqlParserUtilTest: 5 new tests. The 3 comment form tests were verified failing on master; the 2 guard tests pin the identifier and JSON operator families (they fail when the blank gate is removed). Full suite green.
Performance
gradle jmh, JSQLParserBenchmark.parseSQLStatements on performance.sql, version=latest, 10 forks × 10 iterations (100 samples) on a 32-core host:
Δ +0.9% with overlapping 99.9% CIs → no regression.