-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SI-12290: support JDK15 text blocks in Java parser
JDK15 introduced text blocks (JEP 378) for writing multiline strings. This adds support for parsing these strings in the Java parser. The logic for interpretting the literals is a little complicated, but follows from the "3.10.6. Text Blocks" of the Java language specification. The test cases include examples from there and from the JEP. Fixes scala/bug#12290
- Loading branch information
1 parent
8a2cf63
commit af3e6fd
Showing
4 changed files
with
275 additions
and
8 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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 |
---|---|---|
@@ -0,0 +1,56 @@ | ||
==== | ||
A text | ||
|
||
==== | ||
<html> | ||
<body> | ||
<p>Hello, world</p> | ||
</body> | ||
</html> | ||
|
||
==== | ||
SELECT "EMP_ID", "LAST_NAME" FROM "EMPLOYEE_TB" | ||
WHERE "CITY" = 'INDIANAPOLIS' | ||
ORDER BY "EMP_ID", "LAST_NAME"; | ||
|
||
==== | ||
<html> | ||
<body> | ||
<p>Hello, world</p> | ||
</body> | ||
</html> | ||
|
||
==== | ||
<html> | ||
<body> | ||
<p>Hello, world</p> | ||
</body> | ||
</html> | ||
|
||
==== | ||
<html> | ||
<body> | ||
<p>Hello, world</p> | ||
</body> | ||
|
||
</html> | ||
|
||
==== | ||
<html> | ||
|
||
<body> | ||
<p>Hello, world</p> | ||
</body> | ||
</html> | ||
|
||
==== | ||
String text = """ | ||
A text block inside a text block | ||
"""; | ||
|
||
==== | ||
foo bar | ||
baz | ||
==== | ||
|
||
==== |
This file contains 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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* Using `valueOf` is a way to check that the Java string literals were properly | ||
* parsed, since the parsed value is what the Scala compiler will use when | ||
* resolving the singleton types | ||
*/ | ||
object Test extends App { | ||
println("====") | ||
println(valueOf[TextBlocks.aText.type]) | ||
println("====") | ||
println(valueOf[TextBlocks.html1.type]) | ||
println("====") | ||
println(valueOf[TextBlocks.query.type]) | ||
println("====") | ||
println(valueOf[TextBlocks.html2.type]) | ||
println("====") | ||
println(valueOf[TextBlocks.html3.type]) | ||
println("====") | ||
println(valueOf[TextBlocks.html4.type]) | ||
println("====") | ||
println(valueOf[TextBlocks.html5.type]) | ||
println("====") | ||
println(valueOf[TextBlocks.code.type]) | ||
println("====") | ||
println(valueOf[TextBlocks.simpleString.type]) | ||
println("====") | ||
println(valueOf[TextBlocks.emptyString.type]) | ||
println("====") | ||
} |
This file contains 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 |
---|---|---|
@@ -0,0 +1,68 @@ | ||
class TextBlocks { | ||
|
||
final static String aText = """ | ||
A text | ||
"""; | ||
|
||
final static String html1 = """ | ||
<html> | ||
<body> | ||
<p>Hello, world</p> | ||
</body> | ||
</html> | ||
"""; | ||
|
||
// quote characters are unescaped | ||
final static String query = """ | ||
SELECT "EMP_ID", "LAST_NAME" FROM "EMPLOYEE_TB" | ||
WHERE "CITY" = 'INDIANAPOLIS' | ||
ORDER BY "EMP_ID", "LAST_NAME"; | ||
"""; | ||
|
||
// incidental trailing spaces | ||
final static String html2 = """ | ||
<html> | ||
<body> | ||
<p>Hello, world</p> | ||
</body> | ||
</html> | ||
"""; | ||
|
||
// trailing delimiter influences | ||
final static String html3 = """ | ||
<html> | ||
<body> | ||
<p>Hello, world</p> | ||
</body> | ||
</html> | ||
"""; | ||
|
||
// blank line does not affect | ||
final static String html4 = """ | ||
<html> | ||
<body> | ||
<p>Hello, world</p> | ||
</body> | ||
</html> | ||
"""; | ||
|
||
// escape sequences | ||
final static String html5 = """ | ||
<html>\n | ||
<body> | ||
<p>Hello,\tworld</p> | ||
</body> | ||
</html> | ||
"""; | ||
final static String code = | ||
""" | ||
String text = \""" | ||
A text block inside a text block | ||
\"""; | ||
"""; | ||
|
||
final static String simpleString = "foo\tbar\nbaz"; | ||
|
||
final static String emptyString = ""; | ||
} |