Documentation
¶
Overview ¶
package dst declares the types used to represent syntax trees for Go packages.
Index ¶
- func Fprint(w io.Writer, x interface{}, f FieldFilter) error
- func Inspect(node Node, f func(Node) bool)
- func IsExported(name string) bool
- func NotNilFilter(_ string, v reflect.Value) bool
- func Print(x interface{}) error
- func Walk(v Visitor, node Node)
- type ArrayType
- type ArrayTypeDecorations
- type AssignStmt
- type AssignStmtDecorations
- type BadDecl
- type BadDeclDecorations
- type BadExpr
- type BadExprDecorations
- type BadStmt
- type BadStmtDecorations
- type BasicLit
- type BasicLitDecorations
- type BinaryExpr
- type BinaryExprDecorations
- type BlockStmt
- type BlockStmtDecorations
- type BranchStmt
- type BranchStmtDecorations
- type CallExpr
- type CallExprDecorations
- type CaseClause
- type CaseClauseDecorations
- type ChanDir
- type ChanType
- type ChanTypeDecorations
- type CommClause
- type CommClauseDecorations
- type CompositeLit
- type CompositeLitDecorations
- type Decl
- type DeclStmt
- type DeclStmtDecorations
- type Decorated
- type Decorations
- type DeferStmt
- type DeferStmtDecorations
- type Ellipsis
- type EllipsisDecorations
- type EmptyStmt
- type EmptyStmtDecorations
- type Expr
- type ExprStmt
- type ExprStmtDecorations
- type Field
- type FieldDecorations
- type FieldFilter
- type FieldList
- type FieldListDecorations
- type File
- type FileDecorations
- type ForStmt
- type ForStmtDecorations
- type FuncDecl
- type FuncDeclDecorations
- type FuncLit
- type FuncLitDecorations
- type FuncType
- type FuncTypeDecorations
- type GenDecl
- type GenDeclDecorations
- type GoStmt
- type GoStmtDecorations
- type Ident
- type IdentDecorations
- type IfStmt
- type IfStmtDecorations
- type ImportSpec
- type ImportSpecDecorations
- type Importer
- type IncDecStmt
- type IncDecStmtDecorations
- type IndexExpr
- type IndexExprDecorations
- type InterfaceType
- type InterfaceTypeDecorations
- type KeyValueExpr
- type KeyValueExprDecorations
- type LabeledStmt
- type LabeledStmtDecorations
- type MapType
- type MapTypeDecorations
- type Node
- type ObjKind
- type Object
- type Package
- type PackageDecorations
- type ParenExpr
- type ParenExprDecorations
- type RangeStmt
- type RangeStmtDecorations
- type ReturnStmt
- type ReturnStmtDecorations
- type Scope
- type SelectStmt
- type SelectStmtDecorations
- type SelectorExpr
- type SelectorExprDecorations
- type SendStmt
- type SendStmtDecorations
- type SliceExpr
- type SliceExprDecorations
- type SpaceType
- type Spec
- type StarExpr
- type StarExprDecorations
- type Stmt
- type StructType
- type StructTypeDecorations
- type SwitchStmt
- type SwitchStmtDecorations
- type TypeAssertExpr
- type TypeAssertExprDecorations
- type TypeSpec
- type TypeSpecDecorations
- type TypeSwitchStmt
- type TypeSwitchStmtDecorations
- type UnaryExpr
- type UnaryExprDecorations
- type ValueSpec
- type ValueSpecDecorations
- type Visitor
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Fprint ¶
func Fprint(w io.Writer, x interface{}, f FieldFilter) error
Fprint prints the (sub-)tree starting at AST node x to w. If fset != nil, position information is interpreted relative to that file set. Otherwise positions are printed as integer values (file set specific offsets).
A non-nil FieldFilter f may be provided to control the output: struct fields for which f(fieldname, fieldvalue) is true are printed; all others are filtered from the output. Unexported struct fields are never printed.
func Inspect ¶
Inspect traverses an AST in depth-first order: It starts by calling f(node); node must not be nil. If f returns true, Inspect invokes f recursively for each of the non-nil children of node, followed by a call of f(nil).
Example ¶
This example demonstrates how to inspect the AST of a Go program.
package main
import (
"fmt"
"go/ast"
"go/parser"
"go/token"
)
func main() {
// src is the input for which we want to inspect the AST.
src := `
package p
const c = 1.0
var X = f(3.14)*2 + c
`
// Create the AST by parsing src.
fset := token.NewFileSet() // positions are relative to fset
f, err := parser.ParseFile(fset, "src.go", src, 0)
if err != nil {
panic(err)
}
// Inspect the AST and print all identifiers and literals.
ast.Inspect(f, func(n ast.Node) bool {
var s string
switch x := n.(type) {
case *ast.BasicLit:
s = x.Value
case *ast.Ident:
s = x.Name
}
if s != "" {
fmt.Printf("%s:\t%s\n", fset.Position(n.Pos()), s)
}
return true
})
}
Output: src.go:2:9: p src.go:3:7: c src.go:3:11: 1.0 src.go:4:5: X src.go:4:9: f src.go:4:11: 3.14 src.go:4:17: 2 src.go:4:21: c
func IsExported ¶
IsExported reports whether name is an exported Go symbol (that is, whether it begins with an upper-case letter).
func NotNilFilter ¶
NotNilFilter returns true for field values that are not nil; it returns false otherwise.
func Print ¶
func Print(x interface{}) error
Print prints x to standard output, skipping nil fields. Print(fset, x) is the same as Fprint(os.Stdout, fset, x, NotNilFilter).
Example ¶
This example shows what an AST looks like when printed for debugging.
package main
import (
"go/ast"
"go/parser"
"go/token"
)
func main() {
// src is the input for which we want to print the AST.
src := `
package main
func main() {
println("Hello, World!")
}
`
// Create the AST by parsing src.
fset := token.NewFileSet() // positions are relative to fset
f, err := parser.ParseFile(fset, "", src, 0)
if err != nil {
panic(err)
}
// Print the AST.
ast.Print(fset, f)
}
Output: 0 *ast.File { 1 . Package: 2:1 2 . Name: *ast.Ident { 3 . . NamePos: 2:9 4 . . Name: "main" 5 . } 6 . Decls: []ast.Decl (len = 1) { 7 . . 0: *ast.FuncDecl { 8 . . . Name: *ast.Ident { 9 . . . . NamePos: 3:6 10 . . . . Name: "main" 11 . . . . Obj: *ast.Object { 12 . . . . . Kind: func 13 . . . . . Name: "main" 14 . . . . . Decl: *(obj @ 7) 15 . . . . } 16 . . . } 17 . . . Type: *ast.FuncType { 18 . . . . Func: 3:1 19 . . . . Params: *ast.FieldList { 20 . . . . . Opening: 3:10 21 . . . . . Closing: 3:11 22 . . . . } 23 . . . } 24 . . . Body: *ast.BlockStmt { 25 . . . . Lbrace: 3:13 26 . . . . List: []ast.Stmt (len = 1) { 27 . . . . . 0: *ast.ExprStmt { 28 . . . . . . X: *ast.CallExpr { 29 . . . . . . . Fun: *ast.Ident { 30 . . . . . . . . NamePos: 4:2 31 . . . . . . . . Name: "println" 32 . . . . . . . } 33 . . . . . . . Lparen: 4:9 34 . . . . . . . Args: []ast.Expr (len = 1) { 35 . . . . . . . . 0: *ast.BasicLit { 36 . . . . . . . . . ValuePos: 4:10 37 . . . . . . . . . Kind: STRING 38 . . . . . . . . . Value: "\"Hello, World!\"" 39 . . . . . . . . } 40 . . . . . . . } 41 . . . . . . . Ellipsis: - 42 . . . . . . . Rparen: 4:25 43 . . . . . . } 44 . . . . . } 45 . . . . } 46 . . . . Rbrace: 5:1 47 . . . } 48 . . } 49 . } 50 . Scope: *ast.Scope { 51 . . Objects: map[string]*ast.Object (len = 1) { 52 . . . "main": *(obj @ 11) 53 . . } 54 . } 55 . Unresolved: []*ast.Ident (len = 1) { 56 . . 0: *(obj @ 29) 57 . } 58 }
Types ¶
type ArrayType ¶
type ArrayType struct {
Len Expr // Ellipsis node for [...]T array types, nil for slice types
Elt Expr // element type
Decs ArrayTypeDecorations
}
An ArrayType node represents an array or slice type.
func (*ArrayType) End ¶ added in v0.2.0
func (v *ArrayType) End() *Decorations
func (*ArrayType) Start ¶ added in v0.2.0
func (v *ArrayType) Start() *Decorations
type ArrayTypeDecorations ¶
type ArrayTypeDecorations struct {
Space SpaceType
Start Decorations
Lbrack Decorations
Len Decorations
End Decorations
After SpaceType
}
ArrayTypeDecorations holds decorations for ArrayType:
type R /*Start*/ [ /*Lbrack*/ 1] /*Len*/ int /*End*/
type AssignStmt ¶
type AssignStmt struct {
Lhs []Expr
Tok token.Token // assignment token, DEFINE
Rhs []Expr
Decs AssignStmtDecorations
}
An AssignStmt node represents an assignment or a short variable declaration.
func (*AssignStmt) After ¶ added in v0.2.0
func (v *AssignStmt) After() SpaceType
func (*AssignStmt) End ¶ added in v0.2.0
func (v *AssignStmt) End() *Decorations
func (*AssignStmt) SetAfter ¶ added in v0.2.0
func (v *AssignStmt) SetAfter(s SpaceType)
func (*AssignStmt) SetSpace ¶ added in v0.2.0
func (v *AssignStmt) SetSpace(s SpaceType)
func (*AssignStmt) Space ¶ added in v0.2.0
func (v *AssignStmt) Space() SpaceType
func (*AssignStmt) Start ¶ added in v0.2.0
func (v *AssignStmt) Start() *Decorations
type AssignStmtDecorations ¶
type AssignStmtDecorations struct {
Space SpaceType
Start Decorations
Lhs Decorations
Tok Decorations
End Decorations
After SpaceType
}
AssignStmtDecorations holds decorations for AssignStmt:
/*Start*/ i /*Lhs*/ = /*Tok*/ 1 /*End*/
type BadDecl ¶
type BadDecl struct {
Length int // position range of bad declaration
Decs BadDeclDecorations
}
A BadDecl node is a placeholder for declarations containing syntax errors for which no correct declaration nodes can be created.
func (*BadDecl) End ¶ added in v0.2.0
func (v *BadDecl) End() *Decorations
func (*BadDecl) Start ¶ added in v0.2.0
func (v *BadDecl) Start() *Decorations
type BadDeclDecorations ¶
type BadDeclDecorations struct {
Space SpaceType
Start Decorations
End Decorations
After SpaceType
}
BadDeclDecorations holds decorations for BadDecl:
type BadExpr ¶
type BadExpr struct {
Length int // position range of bad expression
Decs BadExprDecorations
}
A BadExpr node is a placeholder for expressions containing syntax errors for which no correct expression nodes can be created.
func (*BadExpr) End ¶ added in v0.2.0
func (v *BadExpr) End() *Decorations
func (*BadExpr) Start ¶ added in v0.2.0
func (v *BadExpr) Start() *Decorations
type BadExprDecorations ¶
type BadExprDecorations struct {
Space SpaceType
Start Decorations
End Decorations
After SpaceType
}
BadExprDecorations holds decorations for BadExpr:
type BadStmt ¶
type BadStmt struct {
Length int // position range of bad statement
Decs BadStmtDecorations
}
A BadStmt node is a placeholder for statements containing syntax errors for which no correct statement nodes can be created.
func (*BadStmt) End ¶ added in v0.2.0
func (v *BadStmt) End() *Decorations
func (*BadStmt) Start ¶ added in v0.2.0
func (v *BadStmt) Start() *Decorations
type BadStmtDecorations ¶
type BadStmtDecorations struct {
Space SpaceType
Start Decorations
End Decorations
After SpaceType
}
BadStmtDecorations holds decorations for BadStmt:
type BasicLit ¶
type BasicLit struct {
Kind token.Token // token.INT, token.FLOAT, token.IMAG, token.CHAR, or token.STRING
Value string // literal string; e.g. 42, 0x7f, 3.14, 1e-9, 2.4i, 'a', '\x7f', "foo" or `\m\n\o`
Decs BasicLitDecorations
}
A BasicLit node represents a literal of basic type.
func (*BasicLit) End ¶ added in v0.2.0
func (v *BasicLit) End() *Decorations
func (*BasicLit) Start ¶ added in v0.2.0
func (v *BasicLit) Start() *Decorations
type BasicLitDecorations ¶
type BasicLitDecorations struct {
Space SpaceType
Start Decorations
End Decorations
After SpaceType
}
BasicLitDecorations holds decorations for BasicLit:
type BinaryExpr ¶
type BinaryExpr struct {
X Expr // left operand
Op token.Token // operator
Y Expr // right operand
Decs BinaryExprDecorations
}
A BinaryExpr node represents a binary expression.
func (*BinaryExpr) After ¶ added in v0.2.0
func (v *BinaryExpr) After() SpaceType
func (*BinaryExpr) End ¶ added in v0.2.0
func (v *BinaryExpr) End() *Decorations
func (*BinaryExpr) SetAfter ¶ added in v0.2.0
func (v *BinaryExpr) SetAfter(s SpaceType)
func (*BinaryExpr) SetSpace ¶ added in v0.2.0
func (v *BinaryExpr) SetSpace(s SpaceType)
func (*BinaryExpr) Space ¶ added in v0.2.0
func (v *BinaryExpr) Space() SpaceType
func (*BinaryExpr) Start ¶ added in v0.2.0
func (v *BinaryExpr) Start() *Decorations
type BinaryExprDecorations ¶
type BinaryExprDecorations struct {
Space SpaceType
Start Decorations
X Decorations
Op Decorations
End Decorations
After SpaceType
}
BinaryExprDecorations holds decorations for BinaryExpr:
var P = /*Start*/ 1 /*X*/ & /*Op*/ 2 /*End*/
type BlockStmt ¶
type BlockStmt struct {
List []Stmt
Decs BlockStmtDecorations
}
A BlockStmt node represents a braced statement list.
func (*BlockStmt) End ¶ added in v0.2.0
func (v *BlockStmt) End() *Decorations
func (*BlockStmt) Start ¶ added in v0.2.0
func (v *BlockStmt) Start() *Decorations
type BlockStmtDecorations ¶
type BlockStmtDecorations struct {
Space SpaceType
Start Decorations
Lbrace Decorations
End Decorations
After SpaceType
}
BlockStmtDecorations holds decorations for BlockStmt:
if true /*Start*/ { /*Lbrace*/
i++
} /*End*/
func() /*Start*/ { /*Lbrace*/ i++ } /*End*/ ()
type BranchStmt ¶
type BranchStmt struct {
Tok token.Token // keyword token (BREAK, CONTINUE, GOTO, FALLTHROUGH)
Label *Ident // label name; or nil
Decs BranchStmtDecorations
}
A BranchStmt node represents a break, continue, goto, or fallthrough statement.
func (*BranchStmt) After ¶ added in v0.2.0
func (v *BranchStmt) After() SpaceType
func (*BranchStmt) End ¶ added in v0.2.0
func (v *BranchStmt) End() *Decorations
func (*BranchStmt) SetAfter ¶ added in v0.2.0
func (v *BranchStmt) SetAfter(s SpaceType)
func (*BranchStmt) SetSpace ¶ added in v0.2.0
func (v *BranchStmt) SetSpace(s SpaceType)
func (*BranchStmt) Space ¶ added in v0.2.0
func (v *BranchStmt) Space() SpaceType
func (*BranchStmt) Start ¶ added in v0.2.0
func (v *BranchStmt) Start() *Decorations
type BranchStmtDecorations ¶
type BranchStmtDecorations struct {
Space SpaceType
Start Decorations
Tok Decorations
End Decorations
After SpaceType
}
BranchStmtDecorations holds decorations for BranchStmt:
/*Start*/ goto /*Tok*/ A /*End*/
type CallExpr ¶
type CallExpr struct {
Fun Expr // function expression
Args []Expr // function arguments; or nil
Ellipsis bool
Decs CallExprDecorations
}
A CallExpr node represents an expression followed by an argument list.
func (*CallExpr) End ¶ added in v0.2.0
func (v *CallExpr) End() *Decorations
func (*CallExpr) Start ¶ added in v0.2.0
func (v *CallExpr) Start() *Decorations
type CallExprDecorations ¶
type CallExprDecorations struct {
Space SpaceType
Start Decorations
Fun Decorations
Lparen Decorations
Args Decorations
Ellipsis Decorations
End Decorations
After SpaceType
}
CallExprDecorations holds decorations for CallExpr:
var L = /*Start*/ C /*Fun*/ ( /*Lparen*/ 0, []int{} /*Args*/ ... /*Ellipsis*/) /*End*/
type CaseClause ¶
type CaseClause struct {
List []Expr // list of expressions or types; nil means default case
Body []Stmt // statement list; or nil
Decs CaseClauseDecorations
}
A CaseClause represents a case of an expression or type switch statement.
func (*CaseClause) After ¶ added in v0.2.0
func (v *CaseClause) After() SpaceType
func (*CaseClause) End ¶ added in v0.2.0
func (v *CaseClause) End() *Decorations
func (*CaseClause) SetAfter ¶ added in v0.2.0
func (v *CaseClause) SetAfter(s SpaceType)
func (*CaseClause) SetSpace ¶ added in v0.2.0
func (v *CaseClause) SetSpace(s SpaceType)
func (*CaseClause) Space ¶ added in v0.2.0
func (v *CaseClause) Space() SpaceType
func (*CaseClause) Start ¶ added in v0.2.0
func (v *CaseClause) Start() *Decorations
type CaseClauseDecorations ¶
type CaseClauseDecorations struct {
Space SpaceType
Start Decorations
Case Decorations
List Decorations
Colon Decorations
End Decorations
After SpaceType
}
CaseClauseDecorations holds decorations for CaseClause:
switch i {
/*Start*/ case /*Case*/ 1 /*List*/ : /*Colon*/
i++
}
type ChanDir ¶
type ChanDir int
The direction of a channel type is indicated by a bit mask including one or both of the following constants.
type ChanType ¶
type ChanType struct {
Dir ChanDir // channel direction
Value Expr // value type
Decs ChanTypeDecorations
}
A ChanType node represents a channel type.
func (*ChanType) End ¶ added in v0.2.0
func (v *ChanType) End() *Decorations
func (*ChanType) Start ¶ added in v0.2.0
func (v *ChanType) Start() *Decorations
type ChanTypeDecorations ¶
type ChanTypeDecorations struct {
Space SpaceType
Start Decorations
Begin Decorations
Arrow Decorations
End Decorations
After SpaceType
}
ChanTypeDecorations holds decorations for ChanType:
type W /*Start*/ chan /*Begin*/ int /*End*/ type X /*Start*/ <-chan /*Begin*/ int /*End*/ type Y /*Start*/ chan /*Begin*/ <- /*Arrow*/ int /*End*/
type CommClause ¶
type CommClause struct {
Comm Stmt // send or receive statement; nil means default case
Body []Stmt // statement list; or nil
Decs CommClauseDecorations
}
A CommClause node represents a case of a select statement.
func (*CommClause) After ¶ added in v0.2.0
func (v *CommClause) After() SpaceType
func (*CommClause) End ¶ added in v0.2.0
func (v *CommClause) End() *Decorations
func (*CommClause) SetAfter ¶ added in v0.2.0
func (v *CommClause) SetAfter(s SpaceType)
func (*CommClause) SetSpace ¶ added in v0.2.0
func (v *CommClause) SetSpace(s SpaceType)
func (*CommClause) Space ¶ added in v0.2.0
func (v *CommClause) Space() SpaceType
func (*CommClause) Start ¶ added in v0.2.0
func (v *CommClause) Start() *Decorations
type CommClauseDecorations ¶
type CommClauseDecorations struct {
Space SpaceType
Start Decorations
Case Decorations
Comm Decorations
Colon Decorations
End Decorations
After SpaceType
}
CommClauseDecorations holds decorations for CommClause:
select {
/*Start*/ case /*Case*/ a := <-c /*Comm*/ : /*Colon*/
print(a)
}
type CompositeLit ¶
type CompositeLit struct {
Type Expr // literal type; or nil
Elts []Expr // list of composite elements; or nil
Incomplete bool // true if (source) expressions are missing in the Elts list
Decs CompositeLitDecorations
}
A CompositeLit node represents a composite literal.
func (*CompositeLit) After ¶ added in v0.2.0
func (v *CompositeLit) After() SpaceType
func (*CompositeLit) End ¶ added in v0.2.0
func (v *CompositeLit) End() *Decorations
func (*CompositeLit) SetAfter ¶ added in v0.2.0
func (v *CompositeLit) SetAfter(s SpaceType)
func (*CompositeLit) SetSpace ¶ added in v0.2.0
func (v *CompositeLit) SetSpace(s SpaceType)
func (*CompositeLit) Space ¶ added in v0.2.0
func (v *CompositeLit) Space() SpaceType
func (*CompositeLit) Start ¶ added in v0.2.0
func (v *CompositeLit) Start() *Decorations
type CompositeLitDecorations ¶
type CompositeLitDecorations struct {
Space SpaceType
Start Decorations
Type Decorations
Lbrace Decorations
End Decorations
After SpaceType
}
CompositeLitDecorations holds decorations for CompositeLit:
var D = /*Start*/ A /*Type*/ { /*Lbrace*/ A: 0} /*End*/
type DeclStmt ¶
type DeclStmt struct {
Decl Decl // *GenDecl with CONST, TYPE, or VAR token
Decs DeclStmtDecorations
}
A DeclStmt node represents a declaration in a statement list.
func (*DeclStmt) End ¶ added in v0.2.0
func (v *DeclStmt) End() *Decorations
func (*DeclStmt) Start ¶ added in v0.2.0
func (v *DeclStmt) Start() *Decorations
type DeclStmtDecorations ¶
type DeclStmtDecorations struct {
Space SpaceType
Start Decorations
End Decorations
After SpaceType
}
DeclStmtDecorations holds decorations for DeclStmt:
type Decorated ¶ added in v0.2.0
type Decorated interface {
Space() SpaceType
SetSpace(SpaceType)
Start() *Decorations
End() *Decorations
After() SpaceType
SetAfter(SpaceType)
}
Example ¶
package main
import (
"github.com/dave/dst"
"github.com/dave/dst/decorator"
)
func main() {
code := `package main
func main() {
var i int
i++
println(i)
}`
f, err := decorator.Parse(code)
if err != nil {
panic(err)
}
list := f.Decls[0].(*dst.FuncDecl).Body.List
list[0].SetSpace(dst.EmptyLine)
list[0].End().Add("// the Decorated interface allows access to the common")
list[1].End().Add("// decoration properties (Space, Start, End and After)")
list[2].End().Add("// for all Expr, Stmt and Decl nodes.")
list[2].SetAfter(dst.EmptyLine)
if err := decorator.Print(f); err != nil {
panic(err)
}
}
Output: package main func main() { var i int // the Decorated interface allows access to the common i++ // decoration properties (Space, Start, End and After) println(i) // for all Expr, Stmt and Decl nodes. }
type Decorations ¶
type Decorations []string
Example ¶
package main
import (
"fmt"
"github.com/dave/dst"
"github.com/dave/dst/decorator"
)
func main() {
code := `package main
func main() {
var a int
a++
print(a)
}`
f, err := decorator.Parse(code)
if err != nil {
panic(err)
}
body := f.Decls[0].(*dst.FuncDecl).Body
for i, stmt := range body.List {
stmt.SetSpace(dst.EmptyLine)
stmt.Start().Add(fmt.Sprintf("// foo %d", i))
}
call := body.List[2].(*dst.ExprStmt).X.(*dst.CallExpr)
call.Args = append(call.Args, dst.NewIdent("b"), dst.NewIdent("c"))
for i, expr := range call.Args {
expr.SetSpace(dst.NewLine)
expr.SetAfter(dst.NewLine)
expr.Start().Add(fmt.Sprintf("/* bar %d */", i))
expr.End().Add(fmt.Sprintf("// baz %d", i))
}
if err := decorator.Print(f); err != nil {
panic(err)
}
}
Output: package main func main() { // foo 0 var a int // foo 1 a++ // foo 2 print( /* bar 0 */ a, // baz 0 /* bar 1 */ b, // baz 1 /* bar 2 */ c, // baz 2 ) }
func (*Decorations) Add ¶
func (d *Decorations) Add(decs ...string)
func (*Decorations) All ¶ added in v0.2.0
func (d *Decorations) All() []string
func (*Decorations) Clear ¶
func (d *Decorations) Clear()
func (*Decorations) Replace ¶
func (d *Decorations) Replace(decs ...string)
type DeferStmt ¶
type DeferStmt struct {
Call *CallExpr
Decs DeferStmtDecorations
}
A DeferStmt node represents a defer statement.
func (*DeferStmt) End ¶ added in v0.2.0
func (v *DeferStmt) End() *Decorations
func (*DeferStmt) Start ¶ added in v0.2.0
func (v *DeferStmt) Start() *Decorations
type DeferStmtDecorations ¶
type DeferStmtDecorations struct {
Space SpaceType
Start Decorations
Defer Decorations
End Decorations
After SpaceType
}
DeferStmtDecorations holds decorations for DeferStmt:
/*Start*/
defer /*Defer*/ func() {}() /*End*/
type Ellipsis ¶
type Ellipsis struct {
Elt Expr // ellipsis element type (parameter lists only); or nil
Decs EllipsisDecorations
}
An Ellipsis node stands for the "..." type in a parameter list or the "..." length in an array type.
func (*Ellipsis) End ¶ added in v0.2.0
func (v *Ellipsis) End() *Decorations
func (*Ellipsis) Start ¶ added in v0.2.0
func (v *Ellipsis) Start() *Decorations
type EllipsisDecorations ¶
type EllipsisDecorations struct {
Space SpaceType
Start Decorations
Ellipsis Decorations
End Decorations
After SpaceType
}
EllipsisDecorations holds decorations for Ellipsis:
func B(a /*Start*/ ... /*Ellipsis*/ int /*End*/) {}
type EmptyStmt ¶
type EmptyStmt struct {
Implicit bool // if set, ";" was omitted in the source
Decs EmptyStmtDecorations
}
An EmptyStmt node represents an empty statement. The "position" of the empty statement is the position of the immediately following (explicit or implicit) semicolon.
func (*EmptyStmt) End ¶ added in v0.2.0
func (v *EmptyStmt) End() *Decorations
func (*EmptyStmt) Start ¶ added in v0.2.0
func (v *EmptyStmt) Start() *Decorations
type EmptyStmtDecorations ¶
type EmptyStmtDecorations struct {
Space SpaceType
Start Decorations
End Decorations
After SpaceType
}
EmptyStmtDecorations holds decorations for EmptyStmt:
type ExprStmt ¶
type ExprStmt struct {
X Expr // expression
Decs ExprStmtDecorations
}
An ExprStmt node represents a (stand-alone) expression in a statement list.
func (*ExprStmt) End ¶ added in v0.2.0
func (v *ExprStmt) End() *Decorations
func (*ExprStmt) Start ¶ added in v0.2.0
func (v *ExprStmt) Start() *Decorations
type ExprStmtDecorations ¶
type ExprStmtDecorations struct {
Space SpaceType
Start Decorations
End Decorations
After SpaceType
}
ExprStmtDecorations holds decorations for ExprStmt:
type Field ¶
type Field struct {
Names []*Ident // field/method/parameter names; or nil
Type Expr // field/method/parameter type
Tag *BasicLit // field tag; or nil
Decs FieldDecorations
}
A Field represents a Field declaration list in a struct type, a method list in an interface type, or a parameter/result declaration in a signature. Field.Names is nil for unnamed parameters (parameter lists which only contain types) and embedded struct fields. In the latter case, the field name is the type name.
func (*Field) End ¶ added in v0.2.0
func (v *Field) End() *Decorations
func (*Field) Start ¶ added in v0.2.0
func (v *Field) Start() *Decorations
type FieldDecorations ¶
type FieldDecorations struct {
Space SpaceType
Start Decorations
Names Decorations
Type Decorations
End Decorations
After SpaceType
}
FieldDecorations holds decorations for Field:
type A struct {
/*Start*/ A /*Names*/ int /*Type*/ `a:"a"` /*End*/
}
type FieldFilter ¶
A FieldFilter may be provided to Fprint to control the output.
type FieldList ¶
type FieldList struct {
Opening bool
List []*Field // field list; or nil
Closing bool
Decs FieldListDecorations
}
A FieldList represents a list of Fields, enclosed by parentheses or braces.
func (*FieldList) End ¶ added in v0.2.0
func (v *FieldList) End() *Decorations
func (*FieldList) NumFields ¶
NumFields returns the number of parameters or struct fields represented by a FieldList.
func (*FieldList) Start ¶ added in v0.2.0
func (v *FieldList) Start() *Decorations
type FieldListDecorations ¶
type FieldListDecorations struct {
Space SpaceType
Start Decorations
Opening Decorations
End Decorations
After SpaceType
}
FieldListDecorations holds decorations for FieldList:
type A1 struct /*Start*/ { /*Opening*/
a, b int
c string
} /*End*/
type File ¶
type File struct {
Name *Ident // package name
Decls []Decl // top-level declarations; or nil
Scope *Scope // package scope (this file only)
Imports []*ImportSpec // imports in this file
Unresolved []*Ident // unresolved identifiers in this file
Decs FileDecorations
}
A File node represents a Go source file.
The Comments list contains all comments in the source file in order of appearance, including the comments that are pointed to from other nodes via Doc and Comment fields.
For correct printing of source code containing comments (using packages go/format and go/printer), special care must be taken to update comments when a File's syntax tree is modified: For printing, comments are interspersed between tokens based on their position. If syntax tree nodes are removed or moved, relevant comments in their vicinity must also be removed (from the File.Comments list) or moved accordingly (by updating their positions). A CommentMap may be used to facilitate some of these operations.
Whether and how a comment is associated with a node depends on the interpretation of the syntax tree by the manipulating program: Except for Doc and Comment comments directly associated with nodes, the remaining comments are "free-floating" (see also issues #18593, #20744).
func (*File) Start ¶ added in v0.2.0
func (v *File) Start() *Decorations
type FileDecorations ¶
type FileDecorations struct {
Space SpaceType
Start Decorations
Package Decorations
Name Decorations
After SpaceType
}
FileDecorations holds decorations for File:
/*Start*/ package /*Package*/ postests /*Name*/
type ForStmt ¶
type ForStmt struct {
Init Stmt // initialization statement; or nil
Cond Expr // condition; or nil
Post Stmt // post iteration statement; or nil
Body *BlockStmt
Decs ForStmtDecorations
}
A ForStmt represents a for statement.
func (*ForStmt) End ¶ added in v0.2.0
func (v *ForStmt) End() *Decorations
func (*ForStmt) Start ¶ added in v0.2.0
func (v *ForStmt) Start() *Decorations
type ForStmtDecorations ¶
type ForStmtDecorations struct {
Space SpaceType
Start Decorations
For Decorations
Init Decorations
Cond Decorations
Post Decorations
End Decorations
After SpaceType
}
ForStmtDecorations holds decorations for ForStmt:
/*Start*/
for /*For*/ {
i++
} /*End*/
/*Start*/
for /*For*/ i < 1 /*Cond*/ {
i++
} /*End*/
/*Start*/
for /*For*/ i = 0; /*Init*/ i < 10; /*Cond*/ i++ /*Post*/ {
i++
} /*End*/
type FuncDecl ¶
type FuncDecl struct {
Recv *FieldList // receiver (methods); or nil (functions)
Name *Ident // function/method name
Type *FuncType // function signature: parameters, results, and position of "func" keyword
Body *BlockStmt // function body; or nil for external (non-Go) function
Decs FuncDeclDecorations
}
A FuncDecl node represents a function declaration.
func (*FuncDecl) End ¶ added in v0.2.0
func (v *FuncDecl) End() *Decorations
func (*FuncDecl) Start ¶ added in v0.2.0
func (v *FuncDecl) Start() *Decorations
type FuncDeclDecorations ¶
type FuncDeclDecorations struct {
Space SpaceType
Start Decorations
Func Decorations
Recv Decorations
Name Decorations
Params Decorations
Results Decorations
End Decorations
After SpaceType
}
FuncDeclDecorations holds decorations for FuncDecl:
/*Start*/
func /*Func*/ d /*Name*/ (d, e int) /*Params*/ {
return
} /*End*/
/*Start*/
func /*Func*/ (a *A) /*Recv*/ e /*Name*/ (d, e int) /*Params*/ {
return
} /*End*/
/*Start*/
func /*Func*/ (a *A) /*Recv*/ f /*Name*/ (d, e int) /*Params*/ (f, g int) /*Results*/ {
return
}
type FuncLit ¶
type FuncLit struct {
Type *FuncType // function type
Body *BlockStmt // function body
Decs FuncLitDecorations
}
A FuncLit node represents a function literal.
func (*FuncLit) End ¶ added in v0.2.0
func (v *FuncLit) End() *Decorations
func (*FuncLit) Start ¶ added in v0.2.0
func (v *FuncLit) Start() *Decorations
type FuncLitDecorations ¶
type FuncLitDecorations struct {
Space SpaceType
Start Decorations
Type Decorations
End Decorations
After SpaceType
}
FuncLitDecorations holds decorations for FuncLit:
var C = /*Start*/ func(a int, b ...int) (c int) /*Type*/ { return 0 } /*End*/
type FuncType ¶
type FuncType struct {
Func bool
Params *FieldList // (incoming) parameters; non-nil
Results *FieldList // (outgoing) results; or nil
Decs FuncTypeDecorations
}
A FuncType node represents a function type.
func (*FuncType) End ¶ added in v0.2.0
func (v *FuncType) End() *Decorations
func (*FuncType) Start ¶ added in v0.2.0
func (v *FuncType) Start() *Decorations
type FuncTypeDecorations ¶
type FuncTypeDecorations struct {
Space SpaceType
Start Decorations
Func Decorations
Params Decorations
End Decorations
After SpaceType
}
FuncTypeDecorations holds decorations for FuncType:
type T /*Start*/ func /*Func*/ (a int) /*Params*/ (b int) /*End*/
type GenDecl ¶
type GenDecl struct {
Tok token.Token // IMPORT, CONST, TYPE, VAR
Lparen bool
Specs []Spec
Rparen bool
Decs GenDeclDecorations
}
A GenDecl node (generic declaration node) represents an import, constant, type or variable declaration. A valid Lparen position (Lparen.IsValid()) indicates a parenthesized declaration.
Relationship between Tok value and Specs element type:
token.IMPORT *ImportSpec token.CONST *ValueSpec token.TYPE *TypeSpec token.VAR *ValueSpec
func (*GenDecl) End ¶ added in v0.2.0
func (v *GenDecl) End() *Decorations
func (*GenDecl) Start ¶ added in v0.2.0
func (v *GenDecl) Start() *Decorations
type GenDeclDecorations ¶
type GenDeclDecorations struct {
Space SpaceType
Start Decorations
Tok Decorations
Lparen Decorations
End Decorations
After SpaceType
}
GenDeclDecorations holds decorations for GenDecl:
/*Start*/ const /*Tok*/ ( /*Lparen*/ a, b = 1, 2 c = 3 ) /*End*/ /*Start*/ const /*Tok*/ d = 1 /*End*/
}
type GoStmt ¶
type GoStmt struct {
Call *CallExpr
Decs GoStmtDecorations
}
A GoStmt node represents a go statement.
func (*GoStmt) End ¶ added in v0.2.0
func (v *GoStmt) End() *Decorations
func (*GoStmt) Start ¶ added in v0.2.0
func (v *GoStmt) Start() *Decorations
type GoStmtDecorations ¶
type GoStmtDecorations struct {
Space SpaceType
Start Decorations
Go Decorations
End Decorations
After SpaceType
}
GoStmtDecorations holds decorations for GoStmt:
/*Start*/
go /*Go*/ func() {}() /*End*/
type Ident ¶
type Ident struct {
Name string // identifier name
Obj *Object // denoted object; or nil
Decs IdentDecorations
}
An Ident node represents an identifier.
func NewIdent ¶
NewIdent creates a new Ident without position. Useful for ASTs generated by code other than the Go parser.
func (*Ident) End ¶ added in v0.2.0
func (v *Ident) End() *Decorations
func (*Ident) IsExported ¶
IsExported reports whether id is an exported Go symbol (that is, whether it begins with an uppercase letter).
func (*Ident) Start ¶ added in v0.2.0
func (v *Ident) Start() *Decorations
type IdentDecorations ¶
type IdentDecorations struct {
Space SpaceType
Start Decorations
End Decorations
After SpaceType
}
IdentDecorations holds decorations for Ident:
type IfStmt ¶
type IfStmt struct {
Init Stmt // initialization statement; or nil
Cond Expr // condition
Body *BlockStmt
Else Stmt // else branch; or nil
Decs IfStmtDecorations
}
An IfStmt node represents an if statement.
func (*IfStmt) End ¶ added in v0.2.0
func (v *IfStmt) End() *Decorations
func (*IfStmt) Start ¶ added in v0.2.0
func (v *IfStmt) Start() *Decorations
type IfStmtDecorations ¶
type IfStmtDecorations struct {
Space SpaceType
Start Decorations
If Decorations
Init Decorations
Cond Decorations
Else Decorations
End Decorations
After SpaceType
}
IfStmtDecorations holds decorations for IfStmt:
/*Start*/
if /*If*/ a := b; /*Init*/ a /*Cond*/ {
i++
} else /*Else*/ {
i++
} /*End*/
type ImportSpec ¶
type ImportSpec struct {
Name *Ident // local package name (including "."); or nil
Path *BasicLit // import path
Decs ImportSpecDecorations
}
An ImportSpec node represents a single package import.
func (*ImportSpec) After ¶ added in v0.2.0
func (v *ImportSpec) After() SpaceType
func (*ImportSpec) End ¶ added in v0.2.0
func (v *ImportSpec) End() *Decorations
func (*ImportSpec) SetAfter ¶ added in v0.2.0
func (v *ImportSpec) SetAfter(s SpaceType)
func (*ImportSpec) SetSpace ¶ added in v0.2.0
func (v *ImportSpec) SetSpace(s SpaceType)
func (*ImportSpec) Space ¶ added in v0.2.0
func (v *ImportSpec) Space() SpaceType
func (*ImportSpec) Start ¶ added in v0.2.0
func (v *ImportSpec) Start() *Decorations
type ImportSpecDecorations ¶
type ImportSpecDecorations struct {
Space SpaceType
Start Decorations
Name Decorations
End Decorations
After SpaceType
}
ImportSpecDecorations holds decorations for ImportSpec:
import ( /*Start*/ fmt /*Name*/ "fmt" /*End*/ )
type Importer ¶
An Importer resolves import paths to package Objects. The imports map records the packages already imported, indexed by package id (canonical import path). An Importer must determine the canonical import path and check the map to see if it is already present in the imports map. If so, the Importer can return the map entry. Otherwise, the Importer should load the package data for the given path into a new *Object (pkg), record pkg in the imports map, and then return pkg.
type IncDecStmt ¶
type IncDecStmt struct {
X Expr
Tok token.Token // INC or DEC
Decs IncDecStmtDecorations
}
An IncDecStmt node represents an increment or decrement statement.
func (*IncDecStmt) After ¶ added in v0.2.0
func (v *IncDecStmt) After() SpaceType
func (*IncDecStmt) End ¶ added in v0.2.0
func (v *IncDecStmt) End() *Decorations
func (*IncDecStmt) SetAfter ¶ added in v0.2.0
func (v *IncDecStmt) SetAfter(s SpaceType)
func (*IncDecStmt) SetSpace ¶ added in v0.2.0
func (v *IncDecStmt) SetSpace(s SpaceType)
func (*IncDecStmt) Space ¶ added in v0.2.0
func (v *IncDecStmt) Space() SpaceType
func (*IncDecStmt) Start ¶ added in v0.2.0
func (v *IncDecStmt) Start() *Decorations
type IncDecStmtDecorations ¶
type IncDecStmtDecorations struct {
Space SpaceType
Start Decorations
X Decorations
End Decorations
After SpaceType
}
IncDecStmtDecorations holds decorations for IncDecStmt:
/*Start*/ i /*X*/ ++ /*End*/
type IndexExpr ¶
type IndexExpr struct {
X Expr // expression
Index Expr // index expression
Decs IndexExprDecorations
}
An IndexExpr node represents an expression followed by an index.
func (*IndexExpr) End ¶ added in v0.2.0
func (v *IndexExpr) End() *Decorations
func (*IndexExpr) Start ¶ added in v0.2.0
func (v *IndexExpr) Start() *Decorations
type IndexExprDecorations ¶
type IndexExprDecorations struct {
Space SpaceType
Start Decorations
X Decorations
Lbrack Decorations
Index Decorations
End Decorations
After SpaceType
}
IndexExprDecorations holds decorations for IndexExpr:
var G = /*Start*/ []int{0} /*X*/ [ /*Lbrack*/ 0 /*Index*/] /*End*/
type InterfaceType ¶
type InterfaceType struct {
Methods *FieldList // list of methods
Incomplete bool // true if (source) methods are missing in the Methods list
Decs InterfaceTypeDecorations
}
An InterfaceType node represents an interface type.
func (*InterfaceType) After ¶ added in v0.2.0
func (v *InterfaceType) After() SpaceType
func (*InterfaceType) End ¶ added in v0.2.0
func (v *InterfaceType) End() *Decorations
func (*InterfaceType) SetAfter ¶ added in v0.2.0
func (v *InterfaceType) SetAfter(s SpaceType)
func (*InterfaceType) SetSpace ¶ added in v0.2.0
func (v *InterfaceType) SetSpace(s SpaceType)
func (*InterfaceType) Space ¶ added in v0.2.0
func (v *InterfaceType) Space() SpaceType
func (*InterfaceType) Start ¶ added in v0.2.0
func (v *InterfaceType) Start() *Decorations
type InterfaceTypeDecorations ¶
type InterfaceTypeDecorations struct {
Space SpaceType
Start Decorations
Interface Decorations
End Decorations
After SpaceType
}
InterfaceTypeDecorations holds decorations for InterfaceType:
type U /*Start*/ interface /*Interface*/ {
A()
} /*End*/
type KeyValueExpr ¶
type KeyValueExpr struct {
Key Expr
Value Expr
Decs KeyValueExprDecorations
}
A KeyValueExpr node represents (key : value) pairs in composite literals.
func (*KeyValueExpr) After ¶ added in v0.2.0
func (v *KeyValueExpr) After() SpaceType
func (*KeyValueExpr) End ¶ added in v0.2.0
func (v *KeyValueExpr) End() *Decorations
func (*KeyValueExpr) SetAfter ¶ added in v0.2.0
func (v *KeyValueExpr) SetAfter(s SpaceType)
func (*KeyValueExpr) SetSpace ¶ added in v0.2.0
func (v *KeyValueExpr) SetSpace(s SpaceType)
func (*KeyValueExpr) Space ¶ added in v0.2.0
func (v *KeyValueExpr) Space() SpaceType
func (*KeyValueExpr) Start ¶ added in v0.2.0
func (v *KeyValueExpr) Start() *Decorations
type KeyValueExprDecorations ¶
type KeyValueExprDecorations struct {
Space SpaceType
Start Decorations
Key Decorations
Colon Decorations
End Decorations
After SpaceType
}
KeyValueExprDecorations holds decorations for KeyValueExpr:
var Q = map[string]string{
/*Start*/ "a" /*Key*/ : /*Colon*/ "a", /*End*/
}
type LabeledStmt ¶
type LabeledStmt struct {
Label *Ident
Stmt Stmt
Decs LabeledStmtDecorations
}
A LabeledStmt node represents a labeled statement.
func (*LabeledStmt) After ¶ added in v0.2.0
func (v *LabeledStmt) After() SpaceType
func (*LabeledStmt) End ¶ added in v0.2.0
func (v *LabeledStmt) End() *Decorations
func (*LabeledStmt) SetAfter ¶ added in v0.2.0
func (v *LabeledStmt) SetAfter(s SpaceType)
func (*LabeledStmt) SetSpace ¶ added in v0.2.0
func (v *LabeledStmt) SetSpace(s SpaceType)
func (*LabeledStmt) Space ¶ added in v0.2.0
func (v *LabeledStmt) Space() SpaceType
func (*LabeledStmt) Start ¶ added in v0.2.0
func (v *LabeledStmt) Start() *Decorations
type LabeledStmtDecorations ¶
type LabeledStmtDecorations struct {
Space SpaceType
Start Decorations
Label Decorations
Colon Decorations
End Decorations
After SpaceType
}
LabeledStmtDecorations holds decorations for LabeledStmt:
/*Start*/
A /*Label*/ : /*Colon*/
print("Stmt") /*End*/
type MapType ¶
type MapType struct {
Key Expr
Value Expr
Decs MapTypeDecorations
}
A MapType node represents a map type.
func (*MapType) End ¶ added in v0.2.0
func (v *MapType) End() *Decorations
func (*MapType) Start ¶ added in v0.2.0
func (v *MapType) Start() *Decorations
type MapTypeDecorations ¶
type MapTypeDecorations struct {
Space SpaceType
Start Decorations
Map Decorations
Key Decorations
End Decorations
After SpaceType
}
MapTypeDecorations holds decorations for MapType:
type V /*Start*/ map[ /*Map*/ int] /*Key*/ int /*End*/
type Node ¶
type Node interface {
// contains filtered or unexported methods
}
All node types implement the Node interface.
type ObjKind ¶
type ObjKind int
ObjKind describes what an object represents.
type Object ¶
type Object struct {
Kind ObjKind
Name string // declared name
Decl interface{} // corresponding Field, XxxSpec, FuncDecl, LabeledStmt, AssignStmt, Scope; or nil
Data interface{} // object-specific data; or nil
Type interface{} // placeholder for type information; may be nil
}
An Object describes a named language entity such as a package, constant, type, variable, function (incl. methods), or label.
The Data fields contains object-specific data:
Kind Data type Data value Pkg *Scope package scope Con int iota for the respective declaration
type Package ¶
type Package struct {
Name string // package name
Scope *Scope // package scope across all files
Imports map[string]*Object // map of package id -> package object
Files map[string]*File // Go source files by filename
}
A Package node represents a set of source files collectively building a Go package.
func NewPackage ¶
func NewPackage(fset *token.FileSet, files map[string]*File, importer Importer, universe *Scope) (*Package, error)
NewPackage creates a new Package node from a set of File nodes. It resolves unresolved identifiers across files and updates each file's Unresolved list accordingly. If a non-nil importer and universe scope are provided, they are used to resolve identifiers not declared in any of the package files. Any remaining unresolved identifiers are reported as undeclared. If the files belong to different packages, one package name is selected and files with different package names are reported and then ignored. The result is a package node and a scanner.ErrorList if there were errors.
type PackageDecorations ¶ added in v0.1.0
PackageDecorations holds decorations for Package:
type ParenExpr ¶
type ParenExpr struct {
X Expr // parenthesized expression
Decs ParenExprDecorations
}
A ParenExpr node represents a parenthesized expression.
func (*ParenExpr) End ¶ added in v0.2.0
func (v *ParenExpr) End() *Decorations
func (*ParenExpr) Start ¶ added in v0.2.0
func (v *ParenExpr) Start() *Decorations
type ParenExprDecorations ¶
type ParenExprDecorations struct {
Space SpaceType
Start Decorations
Lparen Decorations
X Decorations
End Decorations
After SpaceType
}
ParenExprDecorations holds decorations for ParenExpr:
var E = /*Start*/ ( /*Lparen*/ 1 + 1 /*X*/) /*End*/ / 2
type RangeStmt ¶
type RangeStmt struct {
Key, Value Expr // Key, Value may be nil
Tok token.Token // ILLEGAL if Key == nil, ASSIGN, DEFINE
X Expr // value to range over
Body *BlockStmt
Decs RangeStmtDecorations
}
A RangeStmt represents a for statement with a range clause.
func (*RangeStmt) End ¶ added in v0.2.0
func (v *RangeStmt) End() *Decorations
func (*RangeStmt) Start ¶ added in v0.2.0
func (v *RangeStmt) Start() *Decorations
type RangeStmtDecorations ¶
type RangeStmtDecorations struct {
Space SpaceType
Start Decorations
For Decorations
Key Decorations
Value Decorations
Range Decorations
X Decorations
End Decorations
After SpaceType
}
RangeStmtDecorations holds decorations for RangeStmt:
/*Start*/
for range /*Range*/ a /*X*/ {
} /*End*/
/*Start*/
for /*For*/ k /*Key*/ := range /*Range*/ a /*X*/ {
print(k)
} /*End*/
/*Start*/
for /*For*/ k /*Key*/, v /*Value*/ := range /*Range*/ a /*X*/ {
print(k, v)
} /*End*/
type ReturnStmt ¶
type ReturnStmt struct {
Results []Expr // result expressions; or nil
Decs ReturnStmtDecorations
}
A ReturnStmt node represents a return statement.
func (*ReturnStmt) After ¶ added in v0.2.0
func (v *ReturnStmt) After() SpaceType
func (*ReturnStmt) End ¶ added in v0.2.0
func (v *ReturnStmt) End() *Decorations
func (*ReturnStmt) SetAfter ¶ added in v0.2.0
func (v *ReturnStmt) SetAfter(s SpaceType)
func (*ReturnStmt) SetSpace ¶ added in v0.2.0
func (v *ReturnStmt) SetSpace(s SpaceType)
func (*ReturnStmt) Space ¶ added in v0.2.0
func (v *ReturnStmt) Space() SpaceType
func (*ReturnStmt) Start ¶ added in v0.2.0
func (v *ReturnStmt) Start() *Decorations
type ReturnStmtDecorations ¶
type ReturnStmtDecorations struct {
Space SpaceType
Start Decorations
Return Decorations
End Decorations
After SpaceType
}
ReturnStmtDecorations holds decorations for ReturnStmt:
func() int {
/*Start*/ return /*Return*/ 1 /*End*/
}()
type Scope ¶
A Scope maintains the set of named language entities declared in the scope and a link to the immediately surrounding (outer) scope.
func (*Scope) Insert ¶
Insert attempts to insert a named object obj into the scope s. If the scope already contains an object alt with the same name, Insert leaves the scope unchanged and returns alt. Otherwise it inserts obj and returns nil.
type SelectStmt ¶
type SelectStmt struct {
Body *BlockStmt // CommClauses only
Decs SelectStmtDecorations
}
An SelectStmt node represents a select statement.
func (*SelectStmt) After ¶ added in v0.2.0
func (v *SelectStmt) After() SpaceType
func (*SelectStmt) End ¶ added in v0.2.0
func (v *SelectStmt) End() *Decorations
func (*SelectStmt) SetAfter ¶ added in v0.2.0
func (v *SelectStmt) SetAfter(s SpaceType)
func (*SelectStmt) SetSpace ¶ added in v0.2.0
func (v *SelectStmt) SetSpace(s SpaceType)
func (*SelectStmt) Space ¶ added in v0.2.0
func (v *SelectStmt) Space() SpaceType
func (*SelectStmt) Start ¶ added in v0.2.0
func (v *SelectStmt) Start() *Decorations
type SelectStmtDecorations ¶
type SelectStmtDecorations struct {
Space SpaceType
Start Decorations
Select Decorations
End Decorations
After SpaceType
}
SelectStmtDecorations holds decorations for SelectStmt:
/*Start*/
select /*Select*/ {
} /*End*/
type SelectorExpr ¶
type SelectorExpr struct {
X Expr // expression
Sel *Ident // field selector
Decs SelectorExprDecorations
}
A SelectorExpr node represents an expression followed by a selector.
func (*SelectorExpr) After ¶ added in v0.2.0
func (v *SelectorExpr) After() SpaceType
func (*SelectorExpr) End ¶ added in v0.2.0
func (v *SelectorExpr) End() *Decorations
func (*SelectorExpr) SetAfter ¶ added in v0.2.0
func (v *SelectorExpr) SetAfter(s SpaceType)
func (*SelectorExpr) SetSpace ¶ added in v0.2.0
func (v *SelectorExpr) SetSpace(s SpaceType)
func (*SelectorExpr) Space ¶ added in v0.2.0
func (v *SelectorExpr) Space() SpaceType
func (*SelectorExpr) Start ¶ added in v0.2.0
func (v *SelectorExpr) Start() *Decorations
type SelectorExprDecorations ¶
type SelectorExprDecorations struct {
Space SpaceType
Start Decorations
X Decorations
End Decorations
After SpaceType
}
SelectorExprDecorations holds decorations for SelectorExpr:
var F = /*Start*/ fmt. /*X*/ Sprint /*End*/ (0)
type SendStmt ¶
type SendStmt struct {
Chan Expr
Value Expr
Decs SendStmtDecorations
}
A SendStmt node represents a send statement.
func (*SendStmt) End ¶ added in v0.2.0
func (v *SendStmt) End() *Decorations
func (*SendStmt) Start ¶ added in v0.2.0
func (v *SendStmt) Start() *Decorations
type SendStmtDecorations ¶
type SendStmtDecorations struct {
Space SpaceType
Start Decorations
Chan Decorations
Arrow Decorations
End Decorations
After SpaceType
}
SendStmtDecorations holds decorations for SendStmt:
/*Start*/ c /*Chan*/ <- /*Arrow*/ 0 /*End*/
type SliceExpr ¶
type SliceExpr struct {
X Expr // expression
Low Expr // begin of slice range; or nil
High Expr // end of slice range; or nil
Max Expr // maximum capacity of slice; or nil
Slice3 bool // true if 3-index slice (2 colons present)
Decs SliceExprDecorations
}
An SliceExpr node represents an expression followed by slice indices.
func (*SliceExpr) End ¶ added in v0.2.0
func (v *SliceExpr) End() *Decorations
func (*SliceExpr) Start ¶ added in v0.2.0
func (v *SliceExpr) Start() *Decorations
type SliceExprDecorations ¶
type SliceExprDecorations struct {
Space SpaceType
Start Decorations
X Decorations
Lbrack Decorations
Low Decorations
High Decorations
Max Decorations
End Decorations
After SpaceType
}
SliceExprDecorations holds decorations for SliceExpr:
var H = /*Start*/ []int{0} /*X*/ [ /*Lbrack*/ 1: /*Low*/ 2: /*High*/ 3 /*Max*/] /*End*/
var H1 = /*Start*/ []int{0} /*X*/ [ /*Lbrack*/ 1: /*Low*/ 2 /*High*/] /*End*/
var H2 = /*Start*/ []int{0} /*X*/ [: /*Low*/] /*End*/
var H3 = /*Start*/ []int{0} /*X*/ [ /*Lbrack*/ 1: /*Low*/] /*End*/
var H4 = /*Start*/ []int{0} /*X*/ [: /*Low*/ 2 /*High*/] /*End*/
var H5 = /*Start*/ []int{0} /*X*/ [: /*Low*/ 2: /*High*/ 3 /*Max*/] /*End*/
type Spec ¶
type Spec interface {
Node
// contains filtered or unexported methods
}
The Spec type stands for any of *ImportSpec, *ValueSpec, and *TypeSpec.
type StarExpr ¶
type StarExpr struct {
X Expr // operand
Decs StarExprDecorations
}
A StarExpr node represents an expression of the form "*" Expression. Semantically it could be a unary "*" expression, or a pointer type.
func (*StarExpr) End ¶ added in v0.2.0
func (v *StarExpr) End() *Decorations
func (*StarExpr) Start ¶ added in v0.2.0
func (v *StarExpr) Start() *Decorations
type StarExprDecorations ¶
type StarExprDecorations struct {
Space SpaceType
Start Decorations
Star Decorations
End Decorations
After SpaceType
}
StarExprDecorations holds decorations for StarExpr:
var N = /*Start*/ * /*Star*/ p /*End*/
type StructType ¶
type StructType struct {
Fields *FieldList // list of field declarations
Incomplete bool // true if (source) fields are missing in the Fields list
Decs StructTypeDecorations
}
A StructType node represents a struct type.
func (*StructType) After ¶ added in v0.2.0
func (v *StructType) After() SpaceType
func (*StructType) End ¶ added in v0.2.0
func (v *StructType) End() *Decorations
func (*StructType) SetAfter ¶ added in v0.2.0
func (v *StructType) SetAfter(s SpaceType)
func (*StructType) SetSpace ¶ added in v0.2.0
func (v *StructType) SetSpace(s SpaceType)
func (*StructType) Space ¶ added in v0.2.0
func (v *StructType) Space() SpaceType
func (*StructType) Start ¶ added in v0.2.0
func (v *StructType) Start() *Decorations
type StructTypeDecorations ¶
type StructTypeDecorations struct {
Space SpaceType
Start Decorations
Struct Decorations
End Decorations
After SpaceType
}
StructTypeDecorations holds decorations for StructType:
type S /*Start*/ struct /*Struct*/ {
A int
} /*End*/
type SwitchStmt ¶
type SwitchStmt struct {
Init Stmt // initialization statement; or nil
Tag Expr // tag expression; or nil
Body *BlockStmt // CaseClauses only
Decs SwitchStmtDecorations
}
A SwitchStmt node represents an expression switch statement.
func (*SwitchStmt) After ¶ added in v0.2.0
func (v *SwitchStmt) After() SpaceType
func (*SwitchStmt) End ¶ added in v0.2.0
func (v *SwitchStmt) End() *Decorations
func (*SwitchStmt) SetAfter ¶ added in v0.2.0
func (v *SwitchStmt) SetAfter(s SpaceType)
func (*SwitchStmt) SetSpace ¶ added in v0.2.0
func (v *SwitchStmt) SetSpace(s SpaceType)
func (*SwitchStmt) Space ¶ added in v0.2.0
func (v *SwitchStmt) Space() SpaceType
func (*SwitchStmt) Start ¶ added in v0.2.0
func (v *SwitchStmt) Start() *Decorations
type SwitchStmtDecorations ¶
type SwitchStmtDecorations struct {
Space SpaceType
Start Decorations
Switch Decorations
Init Decorations
Tag Decorations
End Decorations
After SpaceType
}
SwitchStmtDecorations holds decorations for SwitchStmt:
/*Start*/
switch /*Switch*/ i /*Tag*/ {
} /*End*/
/*Start*/
switch /*Switch*/ a := i; /*Init*/ a /*Tag*/ {
} /*End*/
type TypeAssertExpr ¶
type TypeAssertExpr struct {
X Expr // expression
Type Expr // asserted type; nil means type switch X.(type)
Decs TypeAssertExprDecorations
}
A TypeAssertExpr node represents an expression followed by a type assertion.
func (*TypeAssertExpr) After ¶ added in v0.2.0
func (v *TypeAssertExpr) After() SpaceType
func (*TypeAssertExpr) End ¶ added in v0.2.0
func (v *TypeAssertExpr) End() *Decorations
func (*TypeAssertExpr) SetAfter ¶ added in v0.2.0
func (v *TypeAssertExpr) SetAfter(s SpaceType)
func (*TypeAssertExpr) SetSpace ¶ added in v0.2.0
func (v *TypeAssertExpr) SetSpace(s SpaceType)
func (*TypeAssertExpr) Space ¶ added in v0.2.0
func (v *TypeAssertExpr) Space() SpaceType
func (*TypeAssertExpr) Start ¶ added in v0.2.0
func (v *TypeAssertExpr) Start() *Decorations
type TypeAssertExprDecorations ¶
type TypeAssertExprDecorations struct {
Space SpaceType
Start Decorations
X Decorations
Lparen Decorations
Type Decorations
End Decorations
After SpaceType
}
TypeAssertExprDecorations holds decorations for TypeAssertExpr:
var J = /*Start*/ f. /*X*/ ( /*Lparen*/ int /*Type*/) /*End*/
type TypeSpec ¶
type TypeSpec struct {
Name *Ident // type name
Assign bool // position of '=', if any
Type Expr // *Ident, *ParenExpr, *SelectorExpr, *StarExpr, or any of the *XxxTypes
Decs TypeSpecDecorations
}
A TypeSpec node represents a type declaration (TypeSpec production).
func (*TypeSpec) End ¶ added in v0.2.0
func (v *TypeSpec) End() *Decorations
func (*TypeSpec) Start ¶ added in v0.2.0
func (v *TypeSpec) Start() *Decorations
type TypeSpecDecorations ¶
type TypeSpecDecorations struct {
Space SpaceType
Start Decorations
Name Decorations
End Decorations
After SpaceType
}
TypeSpecDecorations holds decorations for TypeSpec:
type ( /*Start*/ T1 /*Name*/ []int /*End*/ ) type ( /*Start*/ T2 = /*Name*/ T1 /*End*/ )
type TypeSwitchStmt ¶
type TypeSwitchStmt struct {
Init Stmt // initialization statement; or nil
Assign Stmt // x := y.(type) or y.(type)
Body *BlockStmt // CaseClauses only
Decs TypeSwitchStmtDecorations
}
An TypeSwitchStmt node represents a type switch statement.
func (*TypeSwitchStmt) After ¶ added in v0.2.0
func (v *TypeSwitchStmt) After() SpaceType
func (*TypeSwitchStmt) End ¶ added in v0.2.0
func (v *TypeSwitchStmt) End() *Decorations
func (*TypeSwitchStmt) SetAfter ¶ added in v0.2.0
func (v *TypeSwitchStmt) SetAfter(s SpaceType)
func (*TypeSwitchStmt) SetSpace ¶ added in v0.2.0
func (v *TypeSwitchStmt) SetSpace(s SpaceType)
func (*TypeSwitchStmt) Space ¶ added in v0.2.0
func (v *TypeSwitchStmt) Space() SpaceType
func (*TypeSwitchStmt) Start ¶ added in v0.2.0
func (v *TypeSwitchStmt) Start() *Decorations
type TypeSwitchStmtDecorations ¶
type TypeSwitchStmtDecorations struct {
Space SpaceType
Start Decorations
Switch Decorations
Init Decorations
Assign Decorations
End Decorations
After SpaceType
}
TypeSwitchStmtDecorations holds decorations for TypeSwitchStmt:
/*Start*/
switch /*Switch*/ f.(type) /*Assign*/ {
} /*End*/
/*Start*/
switch /*Switch*/ g := f.(type) /*Assign*/ {
case int:
print(g)
} /*End*/
/*Start*/
switch /*Switch*/ g := f; /*Init*/ g := g.(type) /*Assign*/ {
case int:
print(g)
} /*End*/
type UnaryExpr ¶
type UnaryExpr struct {
Op token.Token // operator
X Expr // operand
Decs UnaryExprDecorations
}
A UnaryExpr node represents a unary expression. Unary "*" expressions are represented via StarExpr nodes.
func (*UnaryExpr) End ¶ added in v0.2.0
func (v *UnaryExpr) End() *Decorations
func (*UnaryExpr) Start ¶ added in v0.2.0
func (v *UnaryExpr) Start() *Decorations
type UnaryExprDecorations ¶
type UnaryExprDecorations struct {
Space SpaceType
Start Decorations
Op Decorations
End Decorations
After SpaceType
}
UnaryExprDecorations holds decorations for UnaryExpr:
var O = /*Start*/ ^ /*Op*/ 1 /*End*/
type ValueSpec ¶
type ValueSpec struct {
Names []*Ident // value names (len(Names) > 0)
Type Expr // value type; or nil
Values []Expr // initial values; or nil
Decs ValueSpecDecorations
}
A ValueSpec node represents a constant or variable declaration (ConstSpec or VarSpec production).
func (*ValueSpec) End ¶ added in v0.2.0
func (v *ValueSpec) End() *Decorations
func (*ValueSpec) Start ¶ added in v0.2.0
func (v *ValueSpec) Start() *Decorations
type ValueSpecDecorations ¶
type ValueSpecDecorations struct {
Space SpaceType
Start Decorations
Names Decorations
Assign Decorations
End Decorations
After SpaceType
}
ValueSpecDecorations holds decorations for ValueSpec:
var ( /*Start*/ j = /*Assign*/ 1 /*End*/ ) var ( /*Start*/ k, l = /*Assign*/ 1, 2 /*End*/ ) var ( /*Start*/ m, n /*Names*/ int = /*Assign*/ 1, 2 /*End*/ )