const ( SendOnly RecvOnly )
const ( // for BranchStmt Break = _Break Continue = _Continue Fallthrough = _Fallthrough Goto = _Goto // for CallStmt Go = _Go Defer = _Defer )
const ( // Def is the : in := Def // : Not // ! Recv // <- // precOrOr OrOr // || // precAndAnd AndAnd // && // precCmp Eql // == Neq // != Lss // < Leq // <= Gtr // > Geq // >= // precAdd Add // + Sub // - Or // | Xor // ^ // precMul Mul // * Div // / Rem // % And // & AndNot // &^ Shl // << Shr // >> )
const PosMax = 1 << 30
PosMax is the largest line or column value that can be represented without loss. Incoming values (arguments) larger than PosMax will be set to PosMax.
var ImplicitOne = &BasicLit{Value: "1"}
We represent x++, x-- as assignments x += ImplicitOne, x -= ImplicitOne. ImplicitOne should not be used elsewhere.
func Fdump(w io.Writer, n Node) (err error)
Fdump dumps the structure of the syntax tree rooted at n to w. It is intended for debugging purposes; no specific output format is guaranteed.
func Fprint(w io.Writer, x Node, linebreaks bool) (n int, err error)
func String(n Node) string
type ArrayType struct { // TODO(gri) consider using Name{"..."} instead of nil (permits attaching of comments) Len Expr // nil means Len is ... Elem Expr // contains filtered or unexported fields }
[Len]Elem
type AssertExpr struct { X Expr Type Expr // contains filtered or unexported fields }
X.(Type)
type AssignStmt struct { Op Operator // 0 means no operation Lhs, Rhs Expr // Rhs == ImplicitOne means Lhs++ (Op == Add) or Lhs-- (Op == Sub) // contains filtered or unexported fields }
type BadExpr struct {
// contains filtered or unexported fields
}
Placeholder for an expression that failed to parse correctly and where we can't provide a better node.
type BasicLit struct { Value string Kind LitKind // contains filtered or unexported fields }
Value
type BlockStmt struct { List []Stmt Rbrace Pos // contains filtered or unexported fields }
type BranchStmt struct { Tok token // Break, Continue, Fallthrough, or Goto Label *Name // Target is the continuation of the control flow after executing // the branch; it is computed by the parser if CheckBranches is set. // Target is a *LabeledStmt for gotos, and a *SwitchStmt, *SelectStmt, // or *ForStmt for breaks and continues, depending on the context of // the branch. Target is not set for fallthroughs. Target Stmt // contains filtered or unexported fields }
type CallExpr struct { Fun Expr ArgList []Expr // nil means no arguments HasDots bool // last argument is followed by ... // contains filtered or unexported fields }
Fun(ArgList[0], ArgList[1], ...)
type CallStmt struct { Tok token // Go or Defer Call *CallExpr // contains filtered or unexported fields }
type CaseClause struct { Cases Expr // nil means default clause Body []Stmt Colon Pos // contains filtered or unexported fields }
func (n *CaseClause) Pos() Pos
type ChanDir uint
type ChanType struct { Dir ChanDir // 0 means no direction Elem Expr // contains filtered or unexported fields }
chan Elem
<-chan Elem chan<- Elem
type CommClause struct { Comm SimpleStmt // send or receive stmt; nil means default clause Body []Stmt Colon Pos // contains filtered or unexported fields }
func (n *CommClause) Pos() Pos
type Comment struct { Kind CommentKind Text string Next *Comment }
type CommentKind uint
TODO(gri) Consider renaming to CommentPos, CommentPlacement, etc.
Kind = Above doesn't make much sense.
const ( Above CommentKind = iota Below Left Right )
type CompositeLit struct { Type Expr // nil means no literal type ElemList []Expr NKeys int // number of elements with keys Rbrace Pos // contains filtered or unexported fields }
Type { ElemList[0], ElemList[1], ... }
type ConstDecl struct { NameList []*Name Type Expr // nil means no type Values Expr // nil means no values Group *Group // nil means not part of a group // contains filtered or unexported fields }
NameList NameList = Values NameList Type = Values
type Decl interface { Node // contains filtered or unexported methods }
type DeclStmt struct { DeclList []Decl // contains filtered or unexported fields }
type DotsType struct { Elem Expr // contains filtered or unexported fields }
...Elem
type EmptyStmt struct {
// contains filtered or unexported fields
}
type Error struct { Pos Pos Msg string }
Error describes a syntax error. Error implements the error interface.
func (err Error) Error() string
type ErrorHandler func(err error)
An ErrorHandler is called for each error encountered reading a .go file.
type Expr interface { Node // contains filtered or unexported methods }
type ExprStmt struct { X Expr // contains filtered or unexported fields }
type Field struct { Name *Name // nil means anonymous field/parameter (structs/parameters), or embedded interface (interfaces) Type Expr // field names declared in a list share the same Type (identical pointers) // contains filtered or unexported fields }
Name Type
Type
func (n *Field) Pos() Pos
type File struct { PkgName *Name DeclList []Decl Lines uint // contains filtered or unexported fields }
package PkgName; DeclList[0], DeclList[1], ...
func Parse(base *PosBase, src io.Reader, errh ErrorHandler, pragh PragmaHandler, mode Mode) (_ *File, first error)
Parse parses a single Go source file from src and returns the corresponding syntax tree. If there are errors, Parse will return the first error found, and a possibly partially constructed syntax tree, or nil.
If errh != nil, it is called with each error encountered, and Parse will process as much source as possible. In this case, the returned syntax tree is only nil if no correct package clause was found. If errh is nil, Parse will terminate immediately upon encountering the first error, and the returned syntax tree is nil.
If pragh != nil, it is called with each pragma encountered.
func ParseFile(filename string, errh ErrorHandler, pragh PragmaHandler, mode Mode) (*File, error)
ParseFile behaves like Parse but it reads the source from the named file.
func (n *File) Pos() Pos
type ForStmt struct { Init SimpleStmt // incl. *RangeClause Cond Expr Post SimpleStmt Body *BlockStmt // contains filtered or unexported fields }
type FuncDecl struct { Attr map[string]bool // go:attr map Recv *Field // nil means regular function Name *Name Type *FuncType Body *BlockStmt // nil means no body (forward declaration) Pragma Pragma // TODO(mdempsky): Cleaner solution. // contains filtered or unexported fields }
func Name Type { Body } func Name Type func Receiver Name Type { Body } func Receiver Name Type
type FuncLit struct { Type *FuncType Body *BlockStmt // contains filtered or unexported fields }
func Type { Body }
type FuncType struct { ParamList []*Field ResultList []*Field // contains filtered or unexported fields }
type Group struct {
// contains filtered or unexported fields
}
All declarations belonging to the same group point to the same Group node.
type IfStmt struct { Init SimpleStmt Cond Expr Then *BlockStmt Else Stmt // either nil, *IfStmt, or *BlockStmt // contains filtered or unexported fields }
type ImportDecl struct { LocalPkgName *Name // including "."; nil means no rename present Path *BasicLit Group *Group // nil means not part of a group // contains filtered or unexported fields }
Path
LocalPkgName Path
type IndexExpr struct { X Expr Index Expr // contains filtered or unexported fields }
X[Index]
type InterfaceType struct { MethodList []*Field // contains filtered or unexported fields }
interface { MethodList[0]; MethodList[1]; ... }
type KeyValueExpr struct { Key, Value Expr // contains filtered or unexported fields }
Key: Value
type LabeledStmt struct { Label *Name Stmt Stmt // contains filtered or unexported fields }
type ListExpr struct { ElemList []Expr // contains filtered or unexported fields }
ElemList[0], ElemList[1], ...
type LitKind uint
const ( IntLit LitKind = iota FloatLit ImagLit RuneLit StringLit )
TODO(gri) With the 'i' (imaginary) suffix now permitted on integer
and floating-point numbers, having a single ImagLit does not represent the literal kind well anymore. Remove it?
type MapType struct { Key, Value Expr // contains filtered or unexported fields }
map[Key]Value
type Mode uint
Mode describes the parser mode.
const ( CheckBranches Mode = 1 << iota // check correct use of labels, break, continue, and goto statements )
Modes supported by the parser.
type Name struct { Value string // contains filtered or unexported fields }
Value
type Node interface { // Pos() returns the position associated with the node as follows: // 1) The position of a node representing a terminal syntax production // (Name, BasicLit, etc.) is the position of the respective production // in the source. // 2) The position of a node representing a non-terminal production // (IndexExpr, IfStmt, etc.) is the position of a token uniquely // associated with that production; usually the left-most one // ('[' for IndexExpr, 'if' for IfStmt, etc.) Pos() Pos // contains filtered or unexported methods }
type Operation struct { Op Operator X, Y Expr // Y == nil means unary expression // contains filtered or unexported fields }
type Operator uint
func (i Operator) String() string
type ParenExpr struct { X Expr // contains filtered or unexported fields }
(X)
type Pos struct {
// contains filtered or unexported fields
}
A Pos represents an absolute (line, col) source position with a reference to position base for computing relative (to a file, or line directive) position information. Pos values are intentionally light-weight so that they can be created without too much concern about space use.
func MakePos(base *PosBase, line, col uint) Pos
MakePos returns a new Pos for the given PosBase, line and column.
func (pos Pos) Base() *PosBase
func (pos Pos) Col() uint
func (pos Pos) IsKnown() bool
func (pos Pos) Line() uint
func (pos Pos) RelCol() uint
func (pos Pos) RelFilename() string
func (pos Pos) RelLine() uint
func (pos Pos) String() string
type PosBase struct {
// contains filtered or unexported fields
}
A PosBase represents the base for relative position information: At position pos, the relative position is filename:line:col.
func NewFileBase(filename string) *PosBase
NewFileBase returns a new PosBase for the given filename. A file PosBase's position is relative to itself, with the position being filename:1:1.
func NewLineBase(pos Pos, filename string, line, col uint) *PosBase
NewLineBase returns a new PosBase for a line directive "line filename:line:col" relative to pos, which is the position of the character immediately following the comment containing the line directive. For a directive in a line comment, that position is the beginning of the next line (i.e., the newline character belongs to the line comment).
func (base *PosBase) Col() uint
func (base *PosBase) Filename() string
func (base *PosBase) IsFileBase() bool
func (base *PosBase) Line() uint
func (base *PosBase) Pos() (_ Pos)
type Pragma uint16
A Pragma value is a set of flags that augment a function or type declaration. Callers may assign meaning to the flags as appropriate.
type PragmaHandler func(pos Pos, text string) Pragma
A PragmaHandler is used to process //go: directives as they're scanned. The returned Pragma value will be unioned into the next FuncDecl node.
type RangeClause struct { Lhs Expr // nil means no Lhs = or Lhs := Def bool // means := X Expr // range X // contains filtered or unexported fields }
type ReturnStmt struct { Results Expr // nil means no explicit return values // contains filtered or unexported fields }
type SelectStmt struct { Body []*CommClause Rbrace Pos // contains filtered or unexported fields }
type SelectorExpr struct { X Expr Sel *Name // contains filtered or unexported fields }
X.Sel
type SendStmt struct { Chan, Value Expr // Chan <- Value // contains filtered or unexported fields }
type SimpleStmt interface { Stmt // contains filtered or unexported methods }
type SliceExpr struct { X Expr Index [3]Expr // Full indicates whether this is a simple or full slice expression. // In a valid AST, this is equivalent to Index[2] != nil. // TODO(mdempsky): This is only needed to report the "3-index // slice of string" error when Index[2] is missing. Full bool // contains filtered or unexported fields }
X[Index[0] : Index[1] : Index[2]]
type SliceType struct { Elem Expr // contains filtered or unexported fields }
[]Elem
type Stmt interface { Node // contains filtered or unexported methods }
type StructType struct { FieldList []*Field TagList []*BasicLit // i >= len(TagList) || TagList[i] == nil means no tag for field i // contains filtered or unexported fields }
struct { FieldList[0] TagList[0]; FieldList[1] TagList[1]; ... }
type SwitchStmt struct { Init SimpleStmt Tag Expr // incl. *TypeSwitchGuard Body []*CaseClause Rbrace Pos // contains filtered or unexported fields }
type TypeDecl struct { Name *Name Alias bool Type Expr Group *Group // nil means not part of a group Pragma Pragma // contains filtered or unexported fields }
Name Type
type TypeSwitchGuard struct { Lhs *Name // nil means no Lhs := X Expr // X.(type) // contains filtered or unexported fields }
X.(type) Lhs := X.(type)
type VarDecl struct { NameList []*Name Type Expr // nil means no type Values Expr // nil means no values Group *Group // nil means not part of a group // contains filtered or unexported fields }
NameList Type NameList Type = Values NameList = Values