...
1
2
3
4
5 package syntax
6
7
8
9
10 type Node interface {
11
12
13
14
15
16
17
18
19 Pos() Pos
20 SetPos(Pos)
21 aNode()
22 }
23
24 type node struct {
25
26
27 pos Pos
28 }
29
30 func (n *node) Pos() Pos { return n.pos }
31 func (n *node) SetPos(pos Pos) { n.pos = pos }
32 func (*node) aNode() {}
33
34
35
36
37
38 type File struct {
39 Pragma Pragma
40 PkgName *Name
41 DeclList []Decl
42 EOF Pos
43 GoVersion string
44 node
45 }
46
47
48
49
50 type (
51 Decl interface {
52 Node
53 aDecl()
54 }
55
56
57
58 ImportDecl struct {
59 Group *Group
60 Pragma Pragma
61 LocalPkgName *Name
62 Path *BasicLit
63 decl
64 }
65
66
67
68
69 ConstDecl struct {
70 Group *Group
71 Pragma Pragma
72 NameList []*Name
73 Type Expr
74 Values Expr
75 decl
76 }
77
78
79 TypeDecl struct {
80 Group *Group
81 Pragma Pragma
82 Name *Name
83 TParamList []*Field
84 Alias bool
85 Type Expr
86 decl
87 }
88
89
90
91
92 VarDecl struct {
93 Group *Group
94 Pragma Pragma
95 NameList []*Name
96 Type Expr
97 Values Expr
98 decl
99 }
100
101
102
103
104
105 FuncDecl struct {
106 Pragma Pragma
107 Recv *Field
108 Name *Name
109 TParamList []*Field
110 Type *FuncType
111 Body *BlockStmt
112 decl
113 }
114 )
115
116 type decl struct{ node }
117
118 func (*decl) aDecl() {}
119
120
121 type Group struct {
122 _ int
123 }
124
125
126
127
128 func NewName(pos Pos, value string) *Name {
129 n := new(Name)
130 n.pos = pos
131 n.Value = value
132 return n
133 }
134
135 type (
136 Expr interface {
137 Node
138 typeInfo
139 aExpr()
140 }
141
142
143
144 BadExpr struct {
145 expr
146 }
147
148
149 Name struct {
150 Value string
151 expr
152 }
153
154
155 BasicLit struct {
156 Value string
157 Kind LitKind
158 Bad bool
159 expr
160 }
161
162
163 CompositeLit struct {
164 Type Expr
165 ElemList []Expr
166 NKeys int
167 Rbrace Pos
168 expr
169 }
170
171
172 KeyValueExpr struct {
173 Key, Value Expr
174 expr
175 }
176
177
178 FuncLit struct {
179 Type *FuncType
180 Body *BlockStmt
181 expr
182 }
183
184
185 ParenExpr struct {
186 X Expr
187 expr
188 }
189
190
191 SelectorExpr struct {
192 X Expr
193 Sel *Name
194 expr
195 }
196
197
198
199 IndexExpr struct {
200 X Expr
201 Index Expr
202 expr
203 }
204
205
206 SliceExpr struct {
207 X Expr
208 Index [3]Expr
209
210
211
212
213 Full bool
214 expr
215 }
216
217
218 AssertExpr struct {
219 X Expr
220 Type Expr
221 expr
222 }
223
224
225
226 TypeSwitchGuard struct {
227 Lhs *Name
228 X Expr
229 expr
230 }
231
232 Operation struct {
233 Op Operator
234 X, Y Expr
235 expr
236 }
237
238
239 CallExpr struct {
240 Fun Expr
241 ArgList []Expr
242 HasDots bool
243 expr
244 }
245
246
247 ListExpr struct {
248 ElemList []Expr
249 expr
250 }
251
252
253 ArrayType struct {
254
255 Len Expr
256 Elem Expr
257 expr
258 }
259
260
261 SliceType struct {
262 Elem Expr
263 expr
264 }
265
266
267 DotsType struct {
268 Elem Expr
269 expr
270 }
271
272
273 StructType struct {
274 FieldList []*Field
275 TagList []*BasicLit
276 expr
277 }
278
279
280
281 Field struct {
282 Name *Name
283 Type Expr
284 node
285 }
286
287
288 InterfaceType struct {
289 MethodList []*Field
290 expr
291 }
292
293 FuncType struct {
294 ParamList []*Field
295 ResultList []*Field
296 expr
297 }
298
299
300 MapType struct {
301 Key, Value Expr
302 expr
303 }
304
305
306
307
308 ChanType struct {
309 Dir ChanDir
310 Elem Expr
311 expr
312 }
313 )
314
315 type expr struct {
316 node
317 typeAndValue
318 }
319
320 func (*expr) aExpr() {}
321
322 type ChanDir uint
323
324 const (
325 _ ChanDir = iota
326 SendOnly
327 RecvOnly
328 )
329
330
331
332
333 type (
334 Stmt interface {
335 Node
336 aStmt()
337 }
338
339 SimpleStmt interface {
340 Stmt
341 aSimpleStmt()
342 }
343
344 EmptyStmt struct {
345 simpleStmt
346 }
347
348 LabeledStmt struct {
349 Label *Name
350 Stmt Stmt
351 stmt
352 }
353
354 BlockStmt struct {
355 List []Stmt
356 Rbrace Pos
357 stmt
358 }
359
360 ExprStmt struct {
361 X Expr
362 simpleStmt
363 }
364
365 SendStmt struct {
366 Chan, Value Expr
367 simpleStmt
368 }
369
370 DeclStmt struct {
371 DeclList []Decl
372 stmt
373 }
374
375 AssignStmt struct {
376 Op Operator
377 Lhs, Rhs Expr
378 simpleStmt
379 }
380
381 BranchStmt struct {
382 Tok token
383 Label *Name
384
385
386
387
388
389 Target Stmt
390 stmt
391 }
392
393 CallStmt struct {
394 Tok token
395 Call Expr
396 DeferAt Expr
397 stmt
398 }
399
400 ReturnStmt struct {
401 Results Expr
402 stmt
403 }
404
405 IfStmt struct {
406 Init SimpleStmt
407 Cond Expr
408 Then *BlockStmt
409 Else Stmt
410 stmt
411 }
412
413 ForStmt struct {
414 Init SimpleStmt
415 Cond Expr
416 Post SimpleStmt
417 Body *BlockStmt
418 stmt
419 }
420
421 SwitchStmt struct {
422 Init SimpleStmt
423 Tag Expr
424 Body []*CaseClause
425 Rbrace Pos
426 stmt
427 }
428
429 SelectStmt struct {
430 Body []*CommClause
431 Rbrace Pos
432 stmt
433 }
434 )
435
436 type (
437 RangeClause struct {
438 Lhs Expr
439 Def bool
440 X Expr
441 simpleStmt
442 }
443
444 CaseClause struct {
445 Cases Expr
446 Body []Stmt
447 Colon Pos
448 node
449 }
450
451 CommClause struct {
452 Comm SimpleStmt
453 Body []Stmt
454 Colon Pos
455 node
456 }
457 )
458
459 type stmt struct{ node }
460
461 func (stmt) aStmt() {}
462
463 type simpleStmt struct {
464 stmt
465 }
466
467 func (simpleStmt) aSimpleStmt() {}
468
469
470
471
472
473
474 type CommentKind uint
475
476 const (
477 Above CommentKind = iota
478 Below
479 Left
480 Right
481 )
482
483 type Comment struct {
484 Kind CommentKind
485 Text string
486 Next *Comment
487 }
488
View as plain text