FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix: support MySQL # line comments (#2499) by fudianchn · Pull Request #2502 · JSQLParser/JSqlParser · GitHub

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .java  (1) .jjt  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -1845,7 +1845,11 @@ TOKEN : /* Numeric Constants */

SPECIAL_TOKEN:
{
< LINE_COMMENT: ("--" | "//") (~["\r","\n"])*>
// The `#` comment requires a following blank: `#` without one stays an
// identifier start (SQL Server `#temp`, `##global`) and `#>` / `#>>`
// JSON operators must keep their usual lexing (issue #1197, #1695).
< LINE_COMMENT: ("--" | "//") (~["\r","\n"])*
| "#" [" ", "\t"] (~["\r","\n"])*>
}

// Nested block comments: /* ... /* ... */ ... */
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,40 @@ public void accept(Statement statement) {
assertEquals(3, list.size());
}

@Test
public void testLineCommentHashTrailing() throws Exception {
assertEquals("SELECT 1", CCJSqlParserUtil.parse("SELECT 1 # trailing comment").toString());
}

@Test
public void testLineCommentHashLeading() throws Exception {
assertEquals("SELECT 1", CCJSqlParserUtil.parse("# leading comment\nSELECT 1").toString());
}

@Test
public void testLineCommentHashWithinSelect() throws Exception {
assertEquals("SELECT 1 + 2, 3",
CCJSqlParserUtil.parse("SELECT 1 + 2 # note\n, 3").toString());
}

@Test
public void testHashWithoutBlankStaysIdentifier() throws Exception {
// without a following blank `#` is an identifier start, not a comment (#1197, #1695)
TestUtils.assertSqlCanBeParsedAndDeparsed("SELECT * FROM #temp");
TestUtils.assertSqlCanBeParsedAndDeparsed("SELECT * FROM ##global");
TestUtils.assertSqlCanBeParsedAndDeparsed("SELECT * FROM #$tab1#");
TestUtils.assertSqlCanBeParsedAndDeparsed("SELECT * FROM $#tab1#");
TestUtils.assertSqlCanBeParsedAndDeparsed("SELECT * FROM #$tab#tab1");
TestUtils.assertSqlCanBeParsedAndDeparsed("SELECT a#b FROM t");
TestUtils.assertSqlCanBeParsedAndDeparsed("SELECT 1 #note");
}

@Test
public void testHashJsonOperatorsStayOperators() throws Exception {
TestUtils.assertSqlCanBeParsedAndDeparsed("SELECT js #> '{a}' FROM t");
TestUtils.assertSqlCanBeParsedAndDeparsed("SELECT js #>> '{a,b}' FROM t");
}

@Test
public void testParseStatementsFail() throws Exception {
String sqlStr = "select * from dual;WHATEVER!!";
Expand Down
Loading

Back | FazBrowse Home | New Git URL