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