mirror of
https://github.com/apple/pkl.git
synced 2026-03-18 15:23:58 +01:00
Format interpolated expressions as single line (#1247)
This forces iterpolated expressions to be single-line, so that newline literals within the bounds of two string delimiters can be seen as verbatime newlines in the resulting string. Edge case: in the case of a line comment, it's not possible to keep this as a single line expression. These are kept as multi-line expressions. Also: * Remove `ForceWrap`, this node is not used. * Rename `StringConstant` -> `StringChars`
This commit is contained in:
@@ -965,7 +965,7 @@ public class GenericParser {
|
||||
case STRING_PART -> {
|
||||
var tk = next();
|
||||
if (!tk.text(lexer).isEmpty()) {
|
||||
children.add(make(NodeType.STRING_CONSTANT, tk.span));
|
||||
children.add(make(NodeType.STRING_CHARS, tk.span));
|
||||
}
|
||||
}
|
||||
case STRING_ESCAPE_NEWLINE,
|
||||
@@ -1004,7 +1004,7 @@ public class GenericParser {
|
||||
case STRING_PART -> {
|
||||
var tk = next();
|
||||
if (!tk.text(lexer).isEmpty()) {
|
||||
children.add(make(NodeType.STRING_CONSTANT, tk.span));
|
||||
children.add(make(NodeType.STRING_CHARS, tk.span));
|
||||
}
|
||||
}
|
||||
case STRING_NEWLINE -> children.add(make(NodeType.STRING_NEWLINE, next().span));
|
||||
@@ -1383,7 +1383,7 @@ public class GenericParser {
|
||||
}
|
||||
}
|
||||
children.add(makeTerminal(next())); // string end
|
||||
return new Node(NodeType.STRING_CONSTANT, children);
|
||||
return new Node(NodeType.STRING_CHARS, children);
|
||||
}
|
||||
|
||||
private FullToken expect(Token type, String errorKey, Object... messageArgs) {
|
||||
|
||||
@@ -67,7 +67,7 @@ public enum NodeType {
|
||||
TYPE_ARGUMENT_LIST_ELEMENTS,
|
||||
OBJECT_PARAMETER_LIST,
|
||||
TYPE_PARAMETER,
|
||||
STRING_CONSTANT,
|
||||
STRING_CHARS,
|
||||
OPERATOR,
|
||||
STRING_NEWLINE,
|
||||
STRING_ESCAPE,
|
||||
|
||||
@@ -130,7 +130,7 @@ class GenericSexpRenderer(code: String) {
|
||||
}
|
||||
|
||||
private fun NodeType.isStringData(): Boolean =
|
||||
this == NodeType.STRING_CONSTANT || this == NodeType.STRING_ESCAPE
|
||||
this == NodeType.STRING_CHARS || this == NodeType.STRING_ESCAPE
|
||||
|
||||
private fun name(node: Node): String =
|
||||
when (node.type) {
|
||||
@@ -142,7 +142,7 @@ class GenericSexpRenderer(code: String) {
|
||||
NodeType.EXTENDS_CLAUSE,
|
||||
NodeType.AMENDS_CLAUSE -> "extendsOrAmendsClause"
|
||||
NodeType.TYPEALIAS -> "typeAlias"
|
||||
NodeType.STRING_ESCAPE -> "stringConstant"
|
||||
NodeType.STRING_ESCAPE -> "stringChars"
|
||||
NodeType.READ_EXPR -> {
|
||||
val terminal = node.children.find { it.type == NodeType.TERMINAL }!!.text(source)
|
||||
when (terminal) {
|
||||
|
||||
@@ -430,7 +430,7 @@ class SexpRenderer {
|
||||
renderExpr(part.expr)
|
||||
} else {
|
||||
buf.append('\n').append(tab)
|
||||
buf.append("(stringConstant)")
|
||||
buf.append("(stringChars)")
|
||||
}
|
||||
}
|
||||
buf.append(')')
|
||||
@@ -736,7 +736,7 @@ class SexpRenderer {
|
||||
|
||||
fun renderStringConstant(str: StringConstant) {
|
||||
buf.append(tab)
|
||||
buf.append("(stringConstant)")
|
||||
buf.append("(stringChars)")
|
||||
}
|
||||
|
||||
fun renderTypeAnnotation(typeAnnotation: TypeAnnotation) {
|
||||
|
||||
Reference in New Issue
Block a user