File tree Expand file tree Collapse file tree 2 files changed +77
-8
lines changed Expand file tree Collapse file tree 2 files changed +77
-8
lines changed Original file line number Diff line number Diff line change @@ -223,19 +223,38 @@ func (e *exporter) adt(expr adt.Expr, conjuncts []adt.Conjunct) ast.Expr {
223
223
return & ast.SliceExpr {X : e .expr (x .X ), Low : lo , High : hi }
224
224
225
225
case * adt.Interpolation :
226
+ var (
227
+ tripple = `"""`
228
+ openQuote = `"`
229
+ closeQuote = `"`
230
+ f = literal .String
231
+ )
232
+ if x .K & adt .BytesKind != 0 {
233
+ tripple = `'''`
234
+ openQuote = `'`
235
+ closeQuote = `'`
236
+ f = literal .Bytes
237
+ }
238
+ toString := func (v adt.Expr ) string {
239
+ str := ""
240
+ switch x := v .(type ) {
241
+ case * adt.String :
242
+ str = x .Str
243
+ case * adt.Bytes :
244
+ str = string (x .B )
245
+ }
246
+ return str
247
+ }
226
248
t := & ast.Interpolation {}
227
- f := literal .String .WithGraphicOnly () // TODO: also support bytes
228
- openQuote := `"`
229
- closeQuote := `"`
249
+ f = f .WithGraphicOnly ()
230
250
indent := ""
231
251
// TODO: mark formatting in interpolation itself.
232
252
for i := 0 ; i < len (x .Parts ); i += 2 {
233
- str := x .Parts [i ].(* adt.String ).Str
234
- if strings .IndexByte (str , '\n' ) >= 0 {
253
+ if strings .IndexByte (toString (x .Parts [i ]), '\n' ) >= 0 {
235
254
f = f .WithTabIndent (len (e .stack ))
236
255
indent = strings .Repeat ("\t " , len (e .stack ))
237
- openQuote = `"""` + "\n " + indent
238
- closeQuote = `"""`
256
+ openQuote = tripple + "\n " + indent
257
+ closeQuote = tripple
239
258
break
240
259
}
241
260
}
@@ -247,7 +266,7 @@ func (e *exporter) adt(expr adt.Expr, conjuncts []adt.Conjunct) ast.Expr {
247
266
} else {
248
267
// b := strings.Builder{}
249
268
buf := []byte (prefix )
250
- str := elem .( * adt. String ). Str
269
+ str := toString ( elem )
251
270
buf = f .AppendEscaped (buf , str )
252
271
if i == len (x .Parts )- 1 {
253
272
if len (closeQuote ) > 1 {
Original file line number Diff line number Diff line change @@ -8,6 +8,13 @@ b: "message: \(a)!"
8
8
9
9
c: d: a
10
10
11
+ bin1: '\(a)'
12
+
13
+ bin2: '''
14
+ multi
15
+ \(b)
16
+ '''
17
+
11
18
-- out/definition --
12
19
a: """
13
20
multi
@@ -17,12 +24,19 @@ b: "message: \(a)!"
17
24
c: {
18
25
d: a
19
26
}
27
+ bin1: '\(a)'
28
+ bin2: '''
29
+ multi
30
+ \(b)
31
+ '''
20
32
-- out/doc --
21
33
[]
22
34
[a]
23
35
[b]
24
36
[c]
25
37
[c d]
38
+ [bin1]
39
+ [bin2]
26
40
-- out/value --
27
41
== Simplified
28
42
{
40
54
line
41
55
"""
42
56
}
57
+ bin1: '''
58
+ multi
59
+ line
60
+ '''
61
+ bin2: '''
62
+ multi
63
+ message: multi
64
+ line!
65
+ '''
43
66
}
44
67
== Raw
45
68
{
57
80
line
58
81
"""
59
82
}
83
+ bin1: '''
84
+ multi
85
+ line
86
+ '''
87
+ bin2: '''
88
+ multi
89
+ message: multi
90
+ line!
91
+ '''
60
92
}
61
93
== Final
62
94
{
74
106
line
75
107
"""
76
108
}
109
+ bin1: '''
110
+ multi
111
+ line
112
+ '''
113
+ bin2: '''
114
+ multi
115
+ message: multi
116
+ line!
117
+ '''
77
118
}
78
119
== All
79
120
{
91
132
line
92
133
"""
93
134
}
135
+ bin1: '''
136
+ multi
137
+ line
138
+ '''
139
+ bin2: '''
140
+ multi
141
+ message: multi
142
+ line!
143
+ '''
94
144
}
You can’t perform that action at this time.
0 commit comments