1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
|
package tuigen
import "strings"
type Node interface {
node()
Pos() Position
}
type Comment struct {
Text string
Position Position
EndLine int
EndCol int
IsBlock bool
BlankLineBefore bool
}
type CommentGroup struct {
List []*Comment
}
func (g *CommentGroup) Text() string {
if g == nil || len(g.List) == 0 {
return ""
}
var lines []string
for _, c := range g.List {
text := c.Text
if c.IsBlock {
text = strings.TrimPrefix(text, "/*")
text = strings.TrimSuffix(text, "*/")
text = strings.TrimSpace(text)
} else {
text = strings.TrimPrefix(text, "//")
text = strings.TrimSpace(text)
}
lines = append(lines, text)
}
return strings.Join(lines, "\n")
}
type File struct {
Package string
Imports []Import
Decls []*GoDecl
Components []*Component
Funcs []*GoFunc
Position Position
LeadingComments *CommentGroup
OrphanComments []*CommentGroup
}
func (f *File) node() {}
func (f *File) Pos() Position { return f.Position }
type Import struct {
Alias string
Path string
Position Position
TrailingComments *CommentGroup
}
func (i *Import) node() {}
func (i *Import) Pos() Position { return i.Position }
type Component struct {
Name string
Params []*Param
ReturnType string
Body []Node
AcceptsChildren bool
Position Position
Receiver string
ReceiverName string
ReceiverType string
LeadingComments *CommentGroup
TrailingComments *CommentGroup
OrphanComments []*CommentGroup
}
func (c *Component) node() {}
func (c *Component) Pos() Position { return c.Position }
type Param struct {
Name string
Type string
Position Position
}
func (p *Param) node() {}
func (p *Param) Pos() Position { return p.Position }
type Element struct {
Tag string
RefExpr *GoExpr
RefKey *GoExpr
Attributes []*Attribute
Children []Node
SelfClose bool
Position Position
MultiLineAttrs bool
ClosingBracketNewLine bool
InlineChildren bool
BlankLineBefore bool
LeadingComments *CommentGroup
TrailingComments *CommentGroup
OrphanComments []*CommentGroup
}
func (e *Element) node() {}
func (e *Element) Pos() Position { return e.Position }
type Attribute struct {
Name string
Value Node
Position Position
ValuePosition Position
}
func (a *Attribute) node() {}
func (a *Attribute) Pos() Position { return a.Position }
type GoExpr struct {
Code string
Position Position
BlankLineBefore bool
LeadingComments *CommentGroup
TrailingComments *CommentGroup
}
func (g *GoExpr) node() {}
func (g *GoExpr) Pos() Position { return g.Position }
type StringLit struct {
Value string
Position Position
}
func (s *StringLit) node() {}
func (s *StringLit) Pos() Position { return s.Position }
type IntLit struct {
Value int64
Position Position
}
func (i *IntLit) node() {}
func (i *IntLit) Pos() Position { return i.Position }
type FloatLit struct {
Value float64
Position Position
}
func (f *FloatLit) node() {}
func (f *FloatLit) Pos() Position { return f.Position }
type BoolLit struct {
Value bool
Position Position
}
func (b *BoolLit) node() {}
func (b *BoolLit) Pos() Position { return b.Position }
type TextContent struct {
Text string
Position Position
BlankLineBefore bool
}
func (t *TextContent) node() {}
func (t *TextContent) Pos() Position { return t.Position }
type LetBinding struct {
Name string
Element *Element
Call *ComponentCall
Expr string
IsShortForm bool
IsVarForm bool
Position Position
BlankLineBefore bool
LeadingComments *CommentGroup
TrailingComments *CommentGroup
}
func (l *LetBinding) node() {}
func (l *LetBinding) Pos() Position { return l.Position }
type ForLoop struct {
Index string
Value string
Iterable string
Body []Node
Position Position
BlankLineBefore bool
LeadingComments *CommentGroup
TrailingComments *CommentGroup
OrphanComments []*CommentGroup
}
func (f *ForLoop) node() {}
func (f *ForLoop) Pos() Position { return f.Position }
type IfStmt struct {
Condition string
Then []Node
Else []Node
Position Position
BlankLineBefore bool
LeadingComments *CommentGroup
TrailingComments *CommentGroup
OrphanComments []*CommentGroup
}
func (i *IfStmt) node() {}
func (i *IfStmt) Pos() Position { return i.Position }
type GoCode struct {
Code string
Position Position
LeadingComments *CommentGroup
TrailingComments *CommentGroup
}
func (g *GoCode) node() {}
func (g *GoCode) Pos() Position { return g.Position }
type GoFunc struct {
Code string
Position Position
LeadingComments *CommentGroup
TrailingComments *CommentGroup
}
func (g *GoFunc) node() {}
func (g *GoFunc) Pos() Position { return g.Position }
type GoDecl struct {
Kind string
Code string
Position Position
LeadingComments *CommentGroup
TrailingComments *CommentGroup
}
func (g *GoDecl) node() {}
func (g *GoDecl) Pos() Position { return g.Position }
type RawGoExpr struct {
Code string
Position Position
}
func (r *RawGoExpr) node() {}
func (r *RawGoExpr) Pos() Position { return r.Position }
type ComponentCall struct {
Name string
Args string
ArgsPosition Position
Children []Node
IsStructMount bool
MultiLineArgs bool
Position Position
BlankLineBefore bool
LeadingComments *CommentGroup
TrailingComments *CommentGroup
}
func (c *ComponentCall) node() {}
func (c *ComponentCall) Pos() Position { return c.Position }
type ComponentExpr struct {
Expr string
Position Position
BlankLineBefore bool
LeadingComments *CommentGroup
TrailingComments *CommentGroup
}
func (c *ComponentExpr) node() {}
func (c *ComponentExpr) Pos() Position { return c.Position }
type ChildrenSlot struct {
Position Position
BlankLineBefore bool
LeadingComments *CommentGroup
TrailingComments *CommentGroup
}
func (c *ChildrenSlot) node() {}
func (c *ChildrenSlot) Pos() Position { return c.Position }
|