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.
- Loading branch information
1 parent
d112b8c
commit a8225a0
Showing
7 changed files
with
357 additions
and
24 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,13 @@ | ||
text-blocks/Invalid1.java:4: error: illegal text block open delimiter sequence, missing line terminator | ||
public static final String badOpeningDelimiter = """non-whitespace | ||
^ | ||
text-blocks/Invalid1.java:4: error: <identifier> expected | ||
public static final String badOpeningDelimiter = """non-whitespace | ||
^ | ||
text-blocks/Invalid1.java:6: error: illegal text block open delimiter sequence, missing line terminator | ||
"""; | ||
^ | ||
text-blocks/Invalid2.java:6: error: unclosed string literal | ||
foo""""; | ||
^ | ||
4 errors |
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,7 @@ | ||
// javaVersion: 15+ | ||
class Invalid1 { | ||
|
||
public static final String badOpeningDelimiter = """non-whitespace | ||
foo | ||
"""; | ||
} |
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,7 @@ | ||
// javaVersion: 15+ | ||
class Invalid2 { | ||
|
||
// Closing delimiter is first three eligible `"""`, not last | ||
public static final String closingDelimiterIsNotScalas = """ | ||
foo""""; | ||
} |
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,61 @@ | ||
==== | ||
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> | ||
|
||
==== | ||
this line has 4 tabs before it | ||
this line has 5 spaces before it and space after it | ||
this line has 2 tabs and 3 spaces before it | ||
this line has 6 spaces before it | ||
|
||
==== | ||
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,30 @@ | ||
// javaVersion: 15+ | ||
/* 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.mixedIndents.type]) | ||
println("====") | ||
println(valueOf[TextBlocks.code.type]) | ||
println("====") | ||
println(valueOf[TextBlocks.simpleString.type]) | ||
println("====") | ||
println(valueOf[TextBlocks.emptyString.type]) | ||
println("====") | ||
} |
Oops, something went wrong.