···9090 exprNode()
9191}
92929393-func (*BadExpr) exprNode() {}
9494-func (*Ident) exprNode() {}
9595-func (*BasicLit) exprNode() {}
9696-func (*Interpolation) exprNode() {}
9797-func (*StructLit) exprNode() {}
9898-func (*ListLit) exprNode() {}
9999-func (*Ellipsis) exprNode() {}
9393+type expr struct{}
10094101101-// func (*Comprehension) exprNode() {}
102102-func (*ListComprehension) exprNode() {}
103103-func (*ParenExpr) exprNode() {}
104104-func (*SelectorExpr) exprNode() {}
105105-func (*IndexExpr) exprNode() {}
106106-func (*SliceExpr) exprNode() {}
107107-func (*CallExpr) exprNode() {}
108108-func (*UnaryExpr) exprNode() {}
109109-func (*BinaryExpr) exprNode() {}
110110-func (*BottomLit) exprNode() {}
9595+func (expr) exprNode() {}
1119611297// A Decl node is implemented by all declarations.
11398type Decl interface {
···115100 declNode()
116101}
117102118118-func (*Field) declNode() {}
119119-func (*Comprehension) declNode() {}
120120-func (*ImportDecl) declNode() {}
121121-func (*BadDecl) declNode() {}
122122-func (*EmbedDecl) declNode() {}
123123-func (*Alias) declNode() {}
124124-func (*Ellipsis) declNode() {}
103103+type decl struct{}
125104126126-// Not technically declarations, but appearing at the same level.
127127-func (*Package) declNode() {}
128128-func (*CommentGroup) declNode() {}
105105+func (decl) declNode() {}
129106130107// A Label is any production that can be used as a LHS label.
131108type Label interface {
···143120 clauseNode()
144121}
145122123123+type clause struct{}
124124+125125+func (clause) clauseNode() {}
126126+146127func (x *ForClause) clauseNode() {}
147128func (x *IfClause) clauseNode() {}
148129func (x *Alias) clauseNode() {}
···213194 // <0> Label <1> ":" <2> Expr <3> "," <4>
214195 Position int8
215196 List []*Comment // len(List) > 0
197197+198198+ decl
216199}
217200218201func (g *CommentGroup) Pos() token.Pos { return getPos(g) }
···294277295278// An Attribute provides meta data about a field.
296279type Attribute struct {
297297- comments
298280 At token.Pos
299281 Text string // must be a valid attribute format.
282282+283283+ comments
300284}
301285302286func (a *Attribute) Pos() token.Pos { return a.At }
···305289306290// A Field represents a field declaration in a struct.
307291type Field struct {
308308- comments
309292 Label Label // must have at least one element.
310293 Optional token.Pos
311294···316299 Value Expr // the value associated with this field.
317300318301 Attrs []*Attribute
302302+303303+ comments
304304+ decl
319305}
320306321307func (d *Field) Pos() token.Pos { return d.Label.Pos() }
···332318333319// An Alias binds another field to the alias name in the current struct.
334320type Alias struct {
335335- comments
336321 Ident *Ident // field name, always an Ident
337322 Equal token.Pos // position of "="
338323 Expr Expr // An Ident or SelectorExpr
324324+325325+ comments
326326+ decl
339327}
340328341329func (a *Alias) Pos() token.Pos { return a.Ident.Pos() }
···344332345333// A Comprehension node represents a comprehension declaration.
346334type Comprehension struct {
347347- comments
348335 Clauses []Clause // There must be at least one clause.
349336 Value Expr // Must be a struct
337337+338338+ comments
339339+ decl
350340}
351341352342func (x *Comprehension) Pos() token.Pos { return getPos(x) }
···366356// created. This is different from an ErrorExpr which represents
367357// an explicitly marked error in the source.
368358type BadExpr struct {
359359+ From, To token.Pos // position range of bad expression
360360+369361 comments
370370- From, To token.Pos // position range of bad expression
362362+ expr
371363}
372364373365// A BottomLit indicates an error.
374366type BottomLit struct {
375375- comments
376367 Bottom token.Pos
368368+369369+ comments
370370+ expr
377371}
378372379373// An Ident node represents an left-hand side identifier.
380374type Ident struct {
381381- label
382382- comments
383375 NamePos token.Pos // identifier position
384376385377 // This LHS path element may be an identifier. Possible forms:
···390382391383 Scope Node // scope in which node was found or nil if referring directly
392384 Node Node
385385+386386+ comments
387387+ label
388388+ expr
393389}
394390395391// A TemplateLabel represents a field template declaration in a struct.
396392type TemplateLabel struct {
397397- label
398398- comments
399393 Langle token.Pos
400394 Ident *Ident
401395 Rangle token.Pos
396396+397397+ comments
398398+ label
402399}
403400404401// A BasicLit node represents a literal of basic type.
405402type BasicLit struct {
406406- label
407407- comments
408403 ValuePos token.Pos // literal position
409404 Kind token.Token // INT, FLOAT, DURATION, or STRING
410405 Value string // literal string; e.g. 42, 0x7f, 3.14, 1_234_567, 1e-9, 2.4i, 'a', '\x7f', "foo", or '\m\n\o'
406406+407407+ comments
408408+ expr
409409+ label
411410}
412411413412// NewString creates a new BasicLit with a string value without position.
···425424426425// A Interpolation node represents a string or bytes interpolation.
427426type Interpolation struct {
427427+ Elts []Expr // interleaving of strings and expressions.
428428+429429+ comments
430430+ expr
428431 label
429429- comments
430430- Elts []Expr // interleaving of strings and expressions.
431432}
432433433434// A StructLit node represents a literal struct.
434435type StructLit struct {
435435- comments
436436 Lbrace token.Pos // position of "{"
437437 Elts []Decl // list of elements; or nil
438438 Rbrace token.Pos // position of "}"
439439+440440+ comments
441441+ expr
439442}
440443441444// A ListLit node represents a literal list.
442445type ListLit struct {
443443- comments
444446 Lbrack token.Pos // position of "["
445447 Elts []Expr // list of composite elements; or nil
446448 Rbrack token.Pos // position of "]"
449449+450450+ comments
451451+ expr
447452}
448453449454type Ellipsis struct {
450450- comments
451455 Ellipsis token.Pos // open list if set
452456 Type Expr // type for the remaining elements
457457+458458+ comments
459459+ decl
460460+ expr
453461}
454462455463// A ListComprehension node represents as list comprehension.
456464type ListComprehension struct {
457457- comments
458465 Lbrack token.Pos // position of "["
459466 Expr Expr
460467 Clauses []Clause // Feed or Guard (TODO let)
461468 Rbrack token.Pos // position of "]"
469469+470470+ comments
471471+ expr
462472}
463473464474// A ForClause node represents a for clause in a comprehension.
465475type ForClause struct {
466466- comments
467476 For token.Pos
468477 Key *Ident // allow pattern matching?
469478 // TODO: change to Comma
···471480 Value *Ident // allow pattern matching?
472481 In token.Pos
473482 Source Expr
483483+484484+ comments
485485+ clause
474486}
475487476488// A IfClause node represents an if guard clause in a comprehension.
477489type IfClause struct {
478478- comments
479490 If token.Pos
480491 Condition Expr
492492+493493+ comments
494494+ clause
481495}
482496483497// A ParenExpr node represents a parenthesized expression.
484498type ParenExpr struct {
485485- comments
486499 Lparen token.Pos // position of "("
487500 X Expr // parenthesized expression
488501 Rparen token.Pos // position of ")"
502502+503503+ comments
504504+ expr
489505}
490506491507// A SelectorExpr node represents an expression followed by a selector.
492508type SelectorExpr struct {
493493- comments
494509 X Expr // expression
495510 Sel *Ident // field selector
511511+512512+ comments
513513+ expr
496514}
497515498516// NewSel creates a sequence of selectors.
···506524507525// An IndexExpr node represents an expression followed by an index.
508526type IndexExpr struct {
509509- comments
510527 X Expr // expression
511528 Lbrack token.Pos // position of "["
512529 Index Expr // index expression
513530 Rbrack token.Pos // position of "]"
531531+532532+ comments
533533+ expr
514534}
515535516536// An SliceExpr node represents an expression followed by slice indices.
517537type SliceExpr struct {
518518- comments
519538 X Expr // expression
520539 Lbrack token.Pos // position of "["
521540 Low Expr // begin of slice range; or nil
522541 High Expr // end of slice range; or nil
523542 Rbrack token.Pos // position of "]"
543543+544544+ comments
545545+ expr
524546}
525547526548// A CallExpr node represents an expression followed by an argument list.
527549type CallExpr struct {
528528- comments
529550 Fun Expr // function expression
530551 Lparen token.Pos // position of "("
531552 Args []Expr // function arguments; or nil
532553 Rparen token.Pos // position of ")"
554554+555555+ comments
556556+ expr
533557}
534558535559// NewCall creates a new CallExpr.
···540564541565// A UnaryExpr node represents a unary expression.
542566type UnaryExpr struct {
543543- comments
544567 OpPos token.Pos // position of Op
545568 Op token.Token // operator
546569 X Expr // operand
570570+571571+ comments
572572+ expr
547573}
548574549575// A BinaryExpr node represents a binary expression.
550576type BinaryExpr struct {
551551- comments
552577 X Expr // left operand
553578 OpPos token.Pos // position of Op
554579 Op token.Token // operator
555580 Y Expr // right operand
581581+582582+ comments
583583+ expr
556584}
557585558586// token.Pos and End implementations for expression/type nodes.
···641669// NewIdent creates a new Ident without position.
642670// Useful for ASTs generated by code other than the Go
643671func NewIdent(name string) *Ident {
644644- return &Ident{label{}, comments{}, token.NoPos, name, nil, nil}
672672+ return &Ident{token.NoPos, name, nil, nil, comments{}, label{}, expr{}}
645673}
646674647675func (id *Ident) String() string {
···656684657685// An ImportSpec node represents a single package import.
658686type ImportSpec struct {
659659- comments
660687 Name *Ident // local package name (including "."); or nil
661688 Path *BasicLit // import path
662689 EndPos token.Pos // end of spec (overrides Path.Pos if nonzero)
690690+691691+ comments
663692}
693693+694694+func (*ImportSpec) specNode() {}
664695665696func NewImport(name *Ident, importPath string) *ImportSpec {
666697 importPath = strconv.Quote(importPath)
···693724// syntax errors for which no correct declaration nodes can be
694725// created.
695726type BadDecl struct {
696696- comments
697727 From, To token.Pos // position range of bad declaration
728728+729729+ comments
730730+ decl
698731}
699732700733// A ImportDecl node represents a series of import declarations. A valid
701734// Lparen position (Lparen.Line > 0) indicates a parenthesized declaration.
702735type ImportDecl struct {
703703- comments
704736 Import token.Pos
705737 Lparen token.Pos // position of '(', if any
706738 Specs []*ImportSpec
707739 Rparen token.Pos // position of ')', if any
740740+741741+ comments
742742+ decl
708743}
709744710745type Spec interface {
···712747 specNode()
713748}
714749715715-func (*ImportSpec) specNode() {}
716716-717717-func (*Package) specNode() {}
718718-719750// An EmbedDecl node represents a single expression used as a declaration.
720751// The expressions in this declaration is what will be emitted as
721752// configuration output.
722753//
723754// An EmbedDecl may only appear at the top level.
724755type EmbedDecl struct {
756756+ Expr Expr
757757+725758 comments
726726- Expr Expr
759759+ decl
727760}
728761729762// Pos and End implementations for declaration nodes.
···757790// via Doc and Comment fields.
758791type File struct {
759792 Filename string
760760- comments
761761- Decls []Decl // top-level declarations; or nil
793793+ Decls []Decl // top-level declarations; or nil
762794763795 Imports []*ImportSpec // imports in this file
764796 Unresolved []*Ident // unresolved identifiers in this file
797797+798798+ comments
765799}
766800767801func (f *File) Pos() token.Pos {
···794828795829// A Package represents a package clause.
796830type Package struct {
797797- comments
798831 PackagePos token.Pos // position of "package" pseudo-keyword
799832 Name *Ident // package name
833833+834834+ comments
835835+ decl
800836}
801837802838func (p *Package) Pos() token.Pos { return getPos(p) }