mirror of
https://github.com/apple/pkl.git
synced 2026-05-25 16:19:20 +02:00
SPICE-0028: Add support for multi-line string line continuations (#1507)
SPICE: https://github.com/apple/pkl-evolution/pull/31
This commit is contained in:
@@ -18,6 +18,7 @@ package org.pkl.core.util;
|
||||
import static org.pkl.parser.Token.FALSE;
|
||||
import static org.pkl.parser.Token.NULL;
|
||||
import static org.pkl.parser.Token.STRING_ESCAPE_BACKSLASH;
|
||||
import static org.pkl.parser.Token.STRING_ESCAPE_CONTINUATION;
|
||||
import static org.pkl.parser.Token.STRING_ESCAPE_NEWLINE;
|
||||
import static org.pkl.parser.Token.STRING_ESCAPE_QUOTE;
|
||||
import static org.pkl.parser.Token.STRING_ESCAPE_RETURN;
|
||||
@@ -41,7 +42,8 @@ public final class SyntaxHighlighter {
|
||||
STRING_ESCAPE_RETURN,
|
||||
STRING_ESCAPE_QUOTE,
|
||||
STRING_ESCAPE_BACKSLASH,
|
||||
STRING_ESCAPE_UNICODE);
|
||||
STRING_ESCAPE_UNICODE,
|
||||
STRING_ESCAPE_CONTINUATION);
|
||||
|
||||
private static final EnumSet<Token> constant = EnumSet.of(TRUE, FALSE, NULL);
|
||||
|
||||
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
amends "../snippetTest.pkl"
|
||||
|
||||
examples {
|
||||
["string continuation"] {
|
||||
"""
|
||||
hello \
|
||||
world
|
||||
"""
|
||||
|
||||
#"""
|
||||
hello \#
|
||||
world
|
||||
"""#
|
||||
|
||||
"""
|
||||
hello \
|
||||
\
|
||||
world
|
||||
"""
|
||||
}
|
||||
}
|
||||
+1
@@ -0,0 +1 @@
|
||||
res1 = "xxx\ xxx"
|
||||
@@ -0,0 +1,5 @@
|
||||
foo = """
|
||||
hello \
|
||||
\
|
||||
world
|
||||
"""
|
||||
@@ -0,0 +1,2 @@
|
||||
foo = "hello \
|
||||
world"
|
||||
@@ -0,0 +1,5 @@
|
||||
foo =
|
||||
"""
|
||||
hello \
|
||||
world
|
||||
"""
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
examples {
|
||||
["string continuation"] {
|
||||
"hello world"
|
||||
"hello world"
|
||||
"hello world"
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
–– Pkl Error ––
|
||||
Invalid character escape sequence `\a`.
|
||||
|
||||
Valid character escape sequences are: \n \r \t \" \\
|
||||
Valid character escape sequences are: \n \r \t \" \\ \<newline>
|
||||
|
||||
x | res1 = "xxx\axxx"
|
||||
^^
|
||||
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
–– Pkl Error ––
|
||||
Invalid character escape sequence `\ `.
|
||||
|
||||
Valid character escape sequences are: \n \r \t \" \\ \<newline>
|
||||
|
||||
x | res1 = "xxx\ xxx"
|
||||
^^
|
||||
at invalidCharacterEscape2 (file:///$snippetsDir/input/errors/invalidCharacterEscape2.pkl)
|
||||
@@ -0,0 +1,6 @@
|
||||
–– Pkl Error ––
|
||||
Line must match or exceed indentation of the String's last line.
|
||||
|
||||
x | \
|
||||
^
|
||||
at parser19 (file:///$snippetsDir/input/errors/parser19.pkl)
|
||||
@@ -0,0 +1,8 @@
|
||||
–– Pkl Error ––
|
||||
Invalid line continuation escape sequence.
|
||||
|
||||
Line continuations are only allowed in multi-line strings.
|
||||
|
||||
x | foo = "hello \
|
||||
^^
|
||||
at parser20 (file:///$snippetsDir/input/errors/parser20.pkl)
|
||||
@@ -0,0 +1,8 @@
|
||||
–– Pkl Error ––
|
||||
Invalid line continuation escape sequence.
|
||||
|
||||
Whitespace between the continuation escape and following newline is not allowed.
|
||||
|
||||
x | hello \
|
||||
^^^^^
|
||||
at parser21 (file:///$snippetsDir/input/errors/parser21.pkl)
|
||||
Reference in New Issue
Block a user