mirror of
https://github.com/apple/pkl.git
synced 2026-03-28 11:51: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:
7
pkl-formatter/src/test/files/FormatterSnippetTests/input/single-line-strings.pkl
vendored
Normal file
7
pkl-formatter/src/test/files/FormatterSnippetTests/input/single-line-strings.pkl
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
foo1 = "some string"
|
||||
|
||||
foo2 = "some string with \( new { x = 1; y = 2 }) interpolation"
|
||||
|
||||
foo3 = "some reeeeaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaally long string with \( new { x = 1; y = 2 } ) interpolation"
|
||||
|
||||
foo4 = "some reeeeaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaally long string with \( foo.bar.baz() ) qualified access"
|
||||
51
pkl-formatter/src/test/files/FormatterSnippetTests/input/string-interpolation.pkl
vendored
Normal file
51
pkl-formatter/src/test/files/FormatterSnippetTests/input/string-interpolation.pkl
vendored
Normal file
@@ -0,0 +1,51 @@
|
||||
prop1 =
|
||||
"""
|
||||
asd \(new { bar = 1 }) asd
|
||||
"""
|
||||
|
||||
prop2 =
|
||||
"""
|
||||
\(let (bar = 15) bar + new { qux = 15 }.toString())
|
||||
"""
|
||||
|
||||
prop3 =
|
||||
"""
|
||||
\(new {
|
||||
// some comment
|
||||
foo = 1
|
||||
|
||||
// some comment
|
||||
bar = 2
|
||||
})
|
||||
"""
|
||||
|
||||
prop4 =
|
||||
"""
|
||||
\(1 + /* block comment */ 2)
|
||||
"""
|
||||
|
||||
prop5 =
|
||||
"""
|
||||
\("""
|
||||
foo
|
||||
bar
|
||||
baz
|
||||
""")
|
||||
"""
|
||||
|
||||
prop6 = "\(// some line comment
|
||||
/* some block comment */
|
||||
"\("""
|
||||
one
|
||||
two
|
||||
three
|
||||
""")"
|
||||
// some line comment again
|
||||
)"
|
||||
|
||||
prop7 = "\(
|
||||
5
|
||||
// trailing line comment
|
||||
)"
|
||||
|
||||
prop8 = "\(new { foo = 1 bar = 2 baz = 3 })"
|
||||
@@ -1,8 +1,6 @@
|
||||
foo =
|
||||
"""
|
||||
asd \(new {
|
||||
bar = 1
|
||||
}) asd
|
||||
asd \(new { bar = 1 }) asd
|
||||
"""
|
||||
|
||||
bar =
|
||||
|
||||
9
pkl-formatter/src/test/files/FormatterSnippetTests/output/single-line-strings.pkl
vendored
Normal file
9
pkl-formatter/src/test/files/FormatterSnippetTests/output/single-line-strings.pkl
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
foo1 = "some string"
|
||||
|
||||
foo2 = "some string with \(new { x = 1; y = 2 }) interpolation"
|
||||
|
||||
foo3 =
|
||||
"some reeeeaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaally long string with \(new { x = 1; y = 2 }) interpolation"
|
||||
|
||||
foo4 =
|
||||
"some reeeeaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaally long string with \(foo.bar.baz()) qualified access"
|
||||
52
pkl-formatter/src/test/files/FormatterSnippetTests/output/string-interpolation.pkl
vendored
Normal file
52
pkl-formatter/src/test/files/FormatterSnippetTests/output/string-interpolation.pkl
vendored
Normal file
@@ -0,0 +1,52 @@
|
||||
prop1 =
|
||||
"""
|
||||
asd \(new { bar = 1 }) asd
|
||||
"""
|
||||
|
||||
prop2 =
|
||||
"""
|
||||
\(let (bar = 15) bar + new { qux = 15 }.toString())
|
||||
"""
|
||||
|
||||
prop3 =
|
||||
"""
|
||||
\(new {
|
||||
// some comment
|
||||
foo = 1
|
||||
|
||||
// some comment
|
||||
bar = 2
|
||||
})
|
||||
"""
|
||||
|
||||
prop4 =
|
||||
"""
|
||||
\(1 + /* block comment */ 2)
|
||||
"""
|
||||
|
||||
prop5 =
|
||||
"""
|
||||
\("""
|
||||
foo
|
||||
bar
|
||||
baz
|
||||
""")
|
||||
"""
|
||||
|
||||
prop6 =
|
||||
"\( // some line comment
|
||||
/* some block comment */
|
||||
"\("""
|
||||
one
|
||||
two
|
||||
three
|
||||
""")"
|
||||
// some line comment again
|
||||
)"
|
||||
|
||||
prop7 =
|
||||
"\(5
|
||||
// trailing line comment
|
||||
)"
|
||||
|
||||
prop8 = "\(new { foo = 1; bar = 2; baz = 3 })"
|
||||
Reference in New Issue
Block a user