Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1794,7 +1794,7 @@ BRACKETED_EMPTY_COMMENT
;

BRACKETED_COMMENT
Comment thread
cloud-fan marked this conversation as resolved.
: '/*' ~[+] .*? '*/' -> channel(HIDDEN)
: '/*' ~[+] ( ~'/' | ~'*' '/' ~'*' )*? BRACKETED_COMMENT? ( ~'/' | ~'*' '/' ~'*' )*? '*/' -> channel(HIDDEN)

@maropu maropu Feb 8, 2020

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

: '/*' ~[+] (BRACKETED_COMMENT|.)*? '*/' -> channel(HIDDEN) ?

@beliefer beliefer Feb 8, 2020

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sorry. Maybe I lost some information.
I try to use this again and found it works well.

;

WS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,54 @@ class PlanParserSuite extends AnalysisTest {
With(plan, ctes)
}

test("single comment") {
val plan = table("a").select(star())
assertEqual("-- single comment\nSELECT * FROM a", plan)
}

test("bracketed comment case one") {
val plan = table("a").select(star())
assertEqual("/* This is an example of SQL which should not execute:\n" +

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you follow a format like this?

    assertEqual(
      """
        |/*
        |  XXX
        | */
        |SELECT ...
      """.stripMargin,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. Thanks.

" * select 'multi-line';\n" +
" */\n" +
"SELECT * FROM a", plan)
}

test("bracketed comment case two") {
val plan = table("a").select(star())
assertEqual("/*\n" +
"SELECT 'trailing' as x1; -- inside block comment\n" +
"*/\n" +
"SELECT * FROM a", plan)
}

test("nexted bracketed comment case one") {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: nexted => nested

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK

val plan = table("a").select(star())
assertEqual("/* This block comment surrounds a query which itself has a block comment...\n" +
"SELECT /* embedded single line */ 'embedded' AS x2;\n" +
"*/\n" +
"SELECT * FROM a", plan)
}

test("nexted bracketed comment case two") {

@gengliangwang gengliangwang Feb 12, 2020

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK

val plan = table("a").select(star())
assertEqual("SELECT -- continued after the following block comments...\n" +
"/* Deeply nested comment.\n" +
" This includes a single apostrophe to make sure we aren't decoding this part as a " +
"string.\n" +
"SELECT 'deep nest' AS n1;\n" +
"/* Second level of nesting...\n" +
"SELECT 'deeper nest' as n2;\n" +
"/* Third level of nesting...\n" +
"SELECT 'deepest nest' as n3;\n" +
"*/\n" +
"Hoo boy. Still two deep...\n" +
"*/\n" +
"Now just one deep...\n" +
"*/\n" +
"* FROM a", plan)
}
Comment thread
cloud-fan marked this conversation as resolved.

test("case insensitive") {
val plan = table("a").select(star())
assertEqual("sELEct * FroM a", plan)
Expand Down