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:
Daniel Chao
2025-10-24 03:23:41 -07:00
committed by GitHub
parent cce49a40fa
commit 3223083324
12 changed files with 355 additions and 126 deletions

View File

@@ -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) {

View File

@@ -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,