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:
@@ -75,6 +75,11 @@ final class Builder {
|
||||
OPERATOR ->
|
||||
new Text(node.text(source));
|
||||
case STRING_NEWLINE -> mustForceLine();
|
||||
case STRING_CONTINUATION -> {
|
||||
var escape = node.text(source);
|
||||
yield new Nodes(
|
||||
List.of(new Text(escape.substring(0, escape.length() - 1)), mustForceLine()));
|
||||
}
|
||||
case MODULE_DECLARATION -> formatModuleDeclaration(node);
|
||||
case MODULE_DEFINITION -> formatModuleDefinition(node);
|
||||
case SINGLE_LINE_STRING_LITERAL_EXPR -> formatSingleLineString(node);
|
||||
@@ -922,7 +927,9 @@ final class Builder {
|
||||
if (elem.type == NodeType.TERMINAL && text(elem).endsWith("(")) {
|
||||
isInStringInterpolation = true;
|
||||
}
|
||||
result.add(format(elem));
|
||||
var formatted = format(elem);
|
||||
if (formatted instanceof Nodes formattedNodes) result.addAll(formattedNodes.nodes());
|
||||
else result.add(formatted);
|
||||
prev = elem;
|
||||
}
|
||||
return result;
|
||||
|
||||
+20
@@ -48,6 +48,26 @@ quux {
|
||||
"""
|
||||
}
|
||||
|
||||
// line continuations
|
||||
corge {
|
||||
|
||||
"""
|
||||
hello \
|
||||
world
|
||||
"""
|
||||
|
||||
#"""
|
||||
hello \#
|
||||
world
|
||||
"""#
|
||||
|
||||
"""
|
||||
hello \
|
||||
\
|
||||
world
|
||||
"""
|
||||
}
|
||||
|
||||
obj {
|
||||
data {
|
||||
["bar"] = """
|
||||
|
||||
+19
@@ -52,6 +52,25 @@ quux {
|
||||
"""
|
||||
}
|
||||
|
||||
// line continuations
|
||||
corge {
|
||||
"""
|
||||
hello \
|
||||
world
|
||||
"""
|
||||
|
||||
#"""
|
||||
hello \#
|
||||
world
|
||||
"""#
|
||||
|
||||
"""
|
||||
hello \
|
||||
\
|
||||
world
|
||||
"""
|
||||
}
|
||||
|
||||
obj {
|
||||
data {
|
||||
["bar"] =
|
||||
|
||||
Reference in New Issue
Block a user