Structs
ArrayType
struct
#
[Len]Elem
type ArrayType struct {
Len Expr
Elem Expr
expr
}
AssertExpr
struct
#
X.(Type)
type AssertExpr struct {
X Expr
Type Expr
expr
}
AssignStmt
struct
#
type AssignStmt struct {
Op Operator
Lhs Expr
Rhs Expr
simpleStmt
}
BadExpr
struct
#
Placeholder for an expression that failed to parse
correctly and where we can't provide a better node.
type BadExpr struct {
expr
}
BasicLit
struct
#
Value
type BasicLit struct {
Value string
Kind LitKind
Bad bool
expr
}
BlockStmt
struct
#
type BlockStmt struct {
List []Stmt
Rbrace Pos
stmt
}
BranchStmt
struct
#
type BranchStmt struct {
Tok token
Label *Name
Target Stmt
stmt
}
CallExpr
struct
#
Fun(ArgList[0], ArgList[1], ...)
type CallExpr struct {
Fun Expr
ArgList []Expr
HasDots bool
expr
}
CallStmt
struct
#
type CallStmt struct {
Tok token
Call Expr
DeferAt Expr
stmt
}
CaseClause
struct
#
type CaseClause struct {
Cases Expr
Body []Stmt
Colon Pos
node
}
ChanType
struct
#
chan Elem
<-chan Elem
chan<- Elem
type ChanType struct {
Dir ChanDir
Elem Expr
expr
}
CommClause
struct
#
type CommClause struct {
Comm SimpleStmt
Body []Stmt
Colon Pos
node
}
CompositeLit
struct
#
Type { ElemList[0], ElemList[1], ... }
type CompositeLit struct {
Type Expr
ElemList []Expr
NKeys int
Rbrace Pos
expr
}
ConstDecl
struct
#
NameList
NameList = Values
NameList Type = Values
type ConstDecl struct {
Group *Group
Pragma Pragma
NameList []*Name
Type Expr
Values Expr
decl
}
DeclStmt
struct
#
type DeclStmt struct {
DeclList []Decl
stmt
}
DotsType
struct
#
...Elem
type DotsType struct {
Elem Expr
expr
}
EmptyStmt
struct
#
type EmptyStmt struct {
simpleStmt
}
Error
struct
#
Error describes a syntax error. Error implements the error interface.
type Error struct {
Pos Pos
Msg string
}
ExprStmt
struct
#
type ExprStmt struct {
X Expr
simpleStmt
}
Field
struct
#
Name Type
Type
type Field struct {
Name *Name
Type Expr
node
}
File
struct
#
package PkgName; DeclList[0], DeclList[1], ...
type File struct {
Pragma Pragma
PkgName *Name
DeclList []Decl
EOF Pos
GoVersion string
node
}
ForStmt
struct
#
type ForStmt struct {
Init SimpleStmt
Cond Expr
Post SimpleStmt
Body *BlockStmt
stmt
}
FuncDecl
struct
#
func Name Type { Body }
func Name Type
func Receiver Name Type { Body }
func Receiver Name Type
type FuncDecl struct {
Pragma Pragma
Recv *Field
Name *Name
TParamList []*Field
Type *FuncType
Body *BlockStmt
decl
}
FuncLit
struct
#
func Type { Body }
type FuncLit struct {
Type *FuncType
Body *BlockStmt
expr
}
FuncType
struct
#
type FuncType struct {
ParamList []*Field
ResultList []*Field
expr
}
Group
struct
#
All declarations belonging to the same group point to the same Group node.
type Group struct {
_ int
}
IfStmt
struct
#
type IfStmt struct {
Init SimpleStmt
Cond Expr
Then *BlockStmt
Else Stmt
stmt
}
ImportDecl
struct
#
Path
LocalPkgName Path
type ImportDecl struct {
Group *Group
Pragma Pragma
LocalPkgName *Name
Path *BasicLit
decl
}
IndexExpr
struct
#
X[Index]
X[T1, T2, ...] (with Ti = Index.(*ListExpr).ElemList[i])
type IndexExpr struct {
X Expr
Index Expr
expr
}
InterfaceType
struct
#
interface { MethodList[0]; MethodList[1]; ... }
type InterfaceType struct {
MethodList []*Field
expr
}
KeyValueExpr
struct
#
Key: Value
type KeyValueExpr struct {
Key Expr
Value Expr
expr
}
LabeledStmt
struct
#
type LabeledStmt struct {
Label *Name
Stmt Stmt
stmt
}
ListExpr
struct
#
ElemList[0], ElemList[1], ...
type ListExpr struct {
ElemList []Expr
expr
}
MapType
struct
#
map[Key]Value
type MapType struct {
Key Expr
Value Expr
expr
}
Name
struct
#
Value
type Name struct {
Value string
expr
}
Operation
struct
#
type Operation struct {
Op Operator
X Expr
Y Expr
expr
}
ParenExpr
struct
#
(X)
type ParenExpr struct {
X Expr
expr
}
Pos
struct
#
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.
type Pos struct {
base *PosBase
line uint32
col uint32
}
PosBase
struct
#
A PosBase represents the base for relative position information:
At position pos, the relative position is filename:line:col.
type PosBase struct {
pos Pos
filename string
line uint32
col uint32
trimmed bool
}
RangeClause
struct
#
type RangeClause struct {
Lhs Expr
Def bool
X Expr
simpleStmt
}
ReturnStmt
struct
#
type ReturnStmt struct {
Results Expr
stmt
}
SelectStmt
struct
#
type SelectStmt struct {
Body []*CommClause
Rbrace Pos
stmt
}
SelectorExpr
struct
#
X.Sel
type SelectorExpr struct {
X Expr
Sel *Name
expr
}
SendStmt
struct
#
type SendStmt struct {
Chan Expr
Value Expr
simpleStmt
}
SliceExpr
struct
#
X[Index[0] : Index[1] : Index[2]]
type SliceExpr struct {
X Expr
Index [3]Expr
Full bool
expr
}
SliceType
struct
#
[]Elem
type SliceType struct {
Elem Expr
expr
}
StructType
struct
#
struct { FieldList[0] TagList[0]; FieldList[1] TagList[1]; ... }
type StructType struct {
FieldList []*Field
TagList []*BasicLit
expr
}
SwitchStmt
struct
#
type SwitchStmt struct {
Init SimpleStmt
Tag Expr
Body []*CaseClause
Rbrace Pos
stmt
}
TypeAndValue
struct
#
A TypeAndValue records the type information, constant
value if known, and various other flags associated with
an expression.
This type is similar to types2.TypeAndValue, but exposes
none of types2's internals.
type TypeAndValue struct {
Type Type
Value constant.Value
exprFlags
}
TypeDecl
struct
#
Name Type
type TypeDecl struct {
Group *Group
Pragma Pragma
Name *Name
TParamList []*Field
Alias bool
Type Expr
decl
}
TypeSwitchGuard
struct
#
X.(type)
Lhs := X.(type)
type TypeSwitchGuard struct {
Lhs *Name
X Expr
expr
}
VarDecl
struct
#
NameList Type
NameList Type = Values
NameList = Values
type VarDecl struct {
Group *Group
Pragma Pragma
NameList []*Name
Type Expr
Values Expr
decl
}
block
struct
#
type block struct {
parent *block
start Pos
lstmt *LabeledStmt
}
decl
struct
#
type decl struct {
node
}
dumper
struct
#
type dumper struct {
output io.Writer
ptrmap map[Node]int
indent int
last byte
line int
}
expr
struct
#
type expr struct {
node
typeAndValue
}
label
struct
#
type label struct {
parent *block
lstmt *LabeledStmt
used bool
}
labelScope
struct
#
type labelScope struct {
errh ErrorHandler
labels map[string]*label
}
node
struct
#
type node struct {
pos Pos
}
parser
struct
#
type parser struct {
file *PosBase
errh ErrorHandler
mode Mode
pragh PragmaHandler
scanner
base *PosBase
first error
errcnt int
pragma Pragma
goVersion string
top bool
fnest int
xnest int
indent []byte
}
position_
struct
#
TODO(gri) cleanup: find better name, avoid conflict with position in error_test.go
type position_ struct {
filename string
line uint
col uint
}
printGroup
struct
#
type printGroup struct {
node
Tok token
Decls []Decl
}
printer
struct
#
type printer struct {
output io.Writer
written int
form Form
linebreaks bool
indent int
nlcount int
pending []whitespace
lastTok token
}
scanner
struct
#
type scanner struct {
source
mode uint
nlsemi bool
line uint
col uint
blank bool
tok token
lit string
bad bool
kind LitKind
op Operator
prec int
}
simpleStmt
struct
#
type simpleStmt struct {
stmt
}
source
struct
#
type source struct {
in io.Reader
errh func(line uint, col uint, msg string)
buf []byte
ioerr error
b int
r int
e int
line uint
col uint
ch rune
chw int
}
stmt
struct
#
type stmt struct {
node
}
targets
struct
#
targets describes the target statements within which break
or continue statements are valid.
type targets struct {
breaks Stmt
continues *ForStmt
caseIndex int
}
typeAndValue
struct
#
a typeAndValue contains the results of typechecking an expression.
It is embedded in expression nodes.
type typeAndValue struct {
tv TypeAndValue
}
walker
struct
#
type walker struct {
v Visitor
}
whitespace
struct
#
type whitespace struct {
last token
kind ctrlSymbol
}
writeError
struct
#
writeError wraps locally caught write errors so we can distinguish
them from genuine panics which we don't want to return as errors.
type writeError struct {
err error
}
Functions
Addressable
method
#
func (f exprFlags) Addressable() bool
Assignable
method
#
func (f exprFlags) Assignable() bool
Base
method
#
func (pos Pos) Base() *PosBase
Cmp
method
#
Cmp compares the positions p and q and returns a result r as follows:
r < 0: p is before q
r == 0: p and q are the same position (but may not be identical)
r > 0: p is after q
If p and q are in different files, p is before q if the filename
of p sorts lexicographically before the filename of q.
func (p Pos) Cmp(q Pos) int
Col
method
#
func (pos Pos) Col() uint
Col
method
#
func (base *PosBase) Col() uint
EndPos
function
#
EndPos returns the approximate end position of n in the source.
For some nodes (*Name, *BasicLit) it returns the position immediately
following the node; for others (*BlockStmt, *SwitchStmt, etc.) it
returns the position of the closing '}'; and for some (*ParenExpr)
the returned position is the end position of the last enclosed
expression.
Thus, EndPos should not be used for exact demarcation of the
end of a node in the source; it is mostly useful to determine
scope ranges where there is some leeway.
func EndPos(n Node) Pos
Error
method
#
func (err Error) Error() string
Fdump
function
#
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 Fdump(w io.Writer, n Node) (err error)
FileBase
method
#
FileBase returns the PosBase of the file containing pos,
skipping over intermediate PosBases from //line directives.
The result is nil if pos doesn't have a file base.
func (pos Pos) FileBase() *PosBase
Filename
method
#
func (base *PosBase) Filename() string
Fprint
function
#
Fprint prints node x to w in the specified form.
It returns the number of bytes written, and whether there was an error.
func Fprint(w io.Writer, x Node, form Form) (n int, err error)
GetTypeInfo
method
#
func (x *typeAndValue) GetTypeInfo() TypeAndValue
HasOk
method
#
func (f exprFlags) HasOk() bool
Inspect
function
#
Inspect traverses an AST in pre-order: it starts by calling f(root);
root must not be nil. If f returns true, Inspect invokes f recursively
for each of the non-nil children of root, followed by a call of f(nil).
See Walk for caveats about shared nodes.
func Inspect(root Node, f func(Node) bool)
IsBuiltin
method
#
func (f exprFlags) IsBuiltin() bool
IsFileBase
method
#
func (base *PosBase) IsFileBase() bool
IsKnown
method
#
func (pos Pos) IsKnown() bool
IsNil
method
#
func (f exprFlags) IsNil() bool
IsRuntimeHelper
method
#
func (f exprFlags) IsRuntimeHelper() bool
IsType
method
#
func (f exprFlags) IsType() bool
IsValue
method
#
func (f exprFlags) IsValue() bool
IsVoid
method
#
func (f exprFlags) IsVoid() bool
Line
method
#
func (pos Pos) Line() uint
Line
method
#
func (base *PosBase) Line() uint
MakePos
function
#
MakePos returns a new Pos for the given PosBase, line and column.
func MakePos(base *PosBase, line uint, col uint) Pos
NewFileBase
function
#
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 NewFileBase(filename string) *PosBase
NewLineBase
function
#
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 NewLineBase(pos Pos, filename string, trimmed bool, line uint, col uint) *PosBase
NewName
function
#
func NewName(pos Pos, value string) *Name
NewTrimmedFileBase
function
#
NewTrimmedFileBase is like NewFileBase, but allows specifying Trimmed.
func NewTrimmedFileBase(filename string, trimmed bool) *PosBase
Parse
function
#
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 Parse(base *PosBase, src io.Reader, errh ErrorHandler, pragh PragmaHandler, mode Mode) (_ *File, first error)
ParseFile
function
#
ParseFile behaves like Parse but it reads the source from the named file.
func ParseFile(filename string, errh ErrorHandler, pragh PragmaHandler, mode Mode) (*File, error)
Pos
method
#
func (n *node) Pos() Pos
Pos
method
#
func (base *PosBase) Pos() (_ Pos)
Pos
method
#
func (pos Pos) Pos() Pos
RelCol
method
#
func (pos Pos) RelCol() uint
RelFilename
method
#
func (pos Pos) RelFilename() string
RelLine
method
#
func (pos Pos) RelLine() uint
SetAddressable
method
#
func (f *exprFlags) SetAddressable()
SetAssignable
method
#
func (f *exprFlags) SetAssignable()
SetHasOk
method
#
func (f *exprFlags) SetHasOk()
SetIsBuiltin
method
#
func (f *exprFlags) SetIsBuiltin()
SetIsNil
method
#
func (f *exprFlags) SetIsNil()
SetIsRuntimeHelper
method
#
func (f *exprFlags) SetIsRuntimeHelper()
SetIsType
method
#
func (f *exprFlags) SetIsType()
SetIsValue
method
#
func (f *exprFlags) SetIsValue()
SetIsVoid
method
#
func (f *exprFlags) SetIsVoid()
SetPos
method
#
func (n *node) SetPos(pos Pos)
SetTypeInfo
method
#
func (x *typeAndValue) SetTypeInfo(tv TypeAndValue)
StartPos
function
#
StartPos returns the start position of n.
func StartPos(n Node) Pos
String
method
#
func (pos Pos) String() string
String
method
#
func (i token) String() string
String
function
#
String is a convenience function that prints n in ShortForm
and returns the printed string.
func String(n Node) string
String
method
#
func (i Operator) String() string
String
method
#
func (p position_) String() string
Trimmed
method
#
func (base *PosBase) Trimmed() bool
UnpackListExpr
function
#
UnpackListExpr unpacks a *ListExpr into a []Expr.
func UnpackListExpr(x Expr) []Expr
Unparen
function
#
Unparen returns e with any enclosing parentheses stripped.
func Unparen(x Expr) Expr
Visit
method
#
func (v inspector) Visit(node Node) Visitor
Walk
function
#
Walk traverses an AST in pre-order: It starts by calling
v.Visit(node); node must not be nil. If the visitor w returned by
v.Visit(node) is not nil, Walk is invoked recursively with visitor
w for each of the non-nil children of node, followed by a call of
w.Visit(nil).
Some nodes may be shared among multiple parent nodes (e.g., types in
field lists such as type T in "a, b, c T"). Such shared nodes are
walked multiple times.
TODO(gri) Revisit this design. It may make sense to walk those nodes
only once. A place where this matters is types2.TestResolveIdents.
func Walk(root Node, v Visitor)
Write
method
#
func (p *dumper) Write(data []byte) (n int, err error)
_
function
#
func _()
_
function
#
func _()
aDecl
method
#
func (*decl) aDecl()
aExpr
method
#
func (*expr) aExpr()
aNode
method
#
func (*node) aNode()
aSimpleStmt
method
#
func (simpleStmt) aSimpleStmt()
aStmt
method
#
func (stmt) aStmt()
addField
method
#
func (p *parser) addField(styp *StructType, pos Pos, name *Name, typ Expr, tag *BasicLit)
addWhitespace
method
#
func (p *printer) addWhitespace(kind ctrlSymbol, text string)
advance
method
#
advance consumes tokens until it finds a token of the stopset or followlist.
The stopset is only considered if we are inside a function (p.fnest > 0).
The followlist is the list of valid tokens that can follow a production;
if it is empty, exactly one (non-EOF) token is consumed to ensure progress.
func (p *parser) advance(followlist ...token)
appendGroup
method
#
appendGroup(f) = f | "(" { f ";" } ")" . // ";" is optional before ")"
func (p *parser) appendGroup(list []Decl, f func(*Group) Decl) []Decl
argList
method
#
argList parses a possibly empty, comma-separated list of arguments,
optionally followed by a comma (if not empty), and closed by ")".
The last argument may be followed by "...".
argList = [ arg { "," arg } [ "..." ] [ "," ] ] ")" .
func (p *parser) argList() (list []Expr, hasDots bool)
arrayOrTArgs
method
#
func (p *parser) arrayOrTArgs() Expr
arrayType
method
#
"[" has already been consumed, and pos is its position.
If len != nil it is the already consumed array length.
func (p *parser) arrayType(pos Pos, len Expr) Expr
atIdentChar
method
#
func (s *scanner) atIdentChar(first bool) bool
badExpr
method
#
func (p *parser) badExpr() *BadExpr
bare_complitexpr
method
#
Element = Expression | LiteralValue .
func (p *parser) bare_complitexpr() Expr
baseName
function
#
func baseName(base int) string
binaryExpr
method
#
Expression = UnaryExpr | Expression binary_op Expression .
func (p *parser) binaryExpr(x Expr, prec int) Expr
blockBranches
method
#
blockBranches processes a block's body starting at start and returns the
list of unresolved (forward) gotos. parent is the immediately enclosing
block (or nil), ctxt provides information about the enclosing statements,
and lstmt is the labeled statement associated with this block, or nil.
func (ls *labelScope) blockBranches(parent *block, ctxt targets, lstmt *LabeledStmt, start Pos, body []Stmt) []*BranchStmt
blockStmt
method
#
context must be a non-empty string unless we know that p.tok == _Lbrace.
func (p *parser) blockStmt(context string) *BlockStmt
callStmt
method
#
callStmt parses call-like statements that can be preceded by 'defer' and 'go'.
func (p *parser) callStmt() *CallStmt
caseClause
method
#
func (p *parser) caseClause() *CaseClause
chanElem
method
#
func (p *parser) chanElem() Expr
checkBranches
function
#
checkBranches checks correct use of labels and branch
statements (break, continue, fallthrough, goto) in a function body.
It catches:
- misplaced breaks, continues, and fallthroughs
- bad labeled breaks and continues
- invalid, unused, duplicate, and missing labels
- gotos jumping over variable declarations and into blocks
func checkBranches(body *BlockStmt, errh ErrorHandler)
clearPragma
method
#
clearPragma is called at the end of a statement or
other Go form that does NOT accept a pragma.
It sends the pragma back to the pragma handler
to be reported as unused.
func (p *parser) clearPragma()
combinesWithName
function
#
combinesWithName reports whether a name followed by the expression x
syntactically combines to another valid (value) expression. For instance
using *T for x, "name *T" syntactically appears as the expression x*T.
On the other hand, using P|Q or *P|~Q for x, "name P|Q" or "name *P|~Q"
cannot be combined into a valid (value) expression.
func combinesWithName(x Expr) bool
commClause
method
#
func (p *parser) commClause() *CommClause
complitexpr
method
#
LiteralValue = "{" [ ElementList [ "," ] ] "}" .
func (p *parser) complitexpr() *CompositeLit
constDecl
method
#
ConstSpec = IdentifierList [ [ Type ] "=" ExpressionList ] .
func (p *parser) constDecl(group *Group) Decl
contains
function
#
contains reports whether tok is in tokset.
func contains(tokset uint64, tok token) bool
declList
method
#
func (w walker) declList(list []Decl)
declStmt
method
#
func (p *parser) declStmt(f func(*Group) Decl) *DeclStmt
declare
method
#
declare declares the label introduced by s in block b and returns
the new label. If the label was already declared, declare reports
and error and the existing label is returned instead.
func (ls *labelScope) declare(b *block, s *LabeledStmt) *label
digits
method
#
digits accepts the sequence { digit | '_' }.
If base <= 10, digits accepts any decimal digit but records
the index (relative to the literal start) of a digit >= base
in *invalid, if *invalid < 0.
digits returns a bitset describing whether the sequence contained
digits (bit 0 is set), or separators '_' (bit 1 is set).
func (s *scanner) digits(base int, invalid *int) (digsep int)
dump
method
#
dump prints the contents of x.
If x is the reflect.Value of a struct s, where &s
implements Node, then &s should be passed for n -
this permits printing of the unexported span and
comments fields of the embedded isNode field by
calling the Span() and Comment() instead of using
reflection.
func (p *dumper) dump(x reflect.Value, n Node)
embeddedElem
method
#
EmbeddedElem = MethodSpec | EmbeddedTerm { "|" EmbeddedTerm } .
func (p *parser) embeddedElem(f *Field) *Field
embeddedTerm
method
#
EmbeddedTerm = [ "~" ] Type .
func (p *parser) embeddedTerm() Expr
emphasize
function
#
emphasize returns a string representation of x, with (top-level)
binary expressions emphasized by enclosing them in parentheses.
func emphasize(x Expr) string
enclosingTarget
method
#
enclosingTarget returns the innermost enclosing labeled statement matching
the given name. The result is nil if the label is not defined, and invalid
if the label is defined but doesn't label a valid labeled statement.
func (ls *labelScope) enclosingTarget(b *block, name string) *LabeledStmt
errf
method
#
func (ls *labelScope) errf(pos Pos, format string, args ...interface{})
error
method
#
func (p *parser) error(msg string)
error
method
#
error reports the error msg at source position s.pos().
func (s *source) error(msg string)
errorAt
method
#
errorAt reports an error at the given position.
func (p *parser) errorAt(pos Pos, msg string)
errorAtf
method
#
errorAtf reports an error at a byte column offset relative to the current token start.
func (s *scanner) errorAtf(offset int, format string, args ...interface{})
errorf
method
#
errorf reports an error at the most recently read character position.
func (s *scanner) errorf(format string, args ...interface{})
escape
method
#
func (s *scanner) escape(quote rune) bool
expr
method
#
func (p *parser) expr() Expr
exprList
method
#
ExpressionList = Expression { "," Expression } .
func (p *parser) exprList() Expr
exprList
method
#
func (w walker) exprList(list []Expr)
fieldDecl
method
#
FieldDecl = (IdentifierList Type | AnonymousField) [ Tag ] .
AnonymousField = [ "*" ] TypeName .
Tag = string_lit .
func (p *parser) fieldDecl(styp *StructType)
fieldList
method
#
func (w walker) fieldList(list []*Field)
fileOrNil
method
#
SourceFile = PackageClause ";" { ImportDecl ";" } { TopLevelDecl ";" } .
func (p *parser) fileOrNil() *File
fill
method
#
fill reads more source bytes into s.buf.
It returns with at least one more byte in the buffer, or with s.ioerr != nil.
func (s *source) fill()
flush
method
#
func (p *printer) flush(next token)
forStmt
method
#
func (p *parser) forStmt() Stmt
funcBody
method
#
func (p *parser) funcBody() *BlockStmt
funcDeclOrNil
method
#
FunctionDecl = "func" FunctionName [ TypeParams ] ( Function | Signature ) .
FunctionName = identifier .
Function = Signature FunctionBody .
MethodDecl = "func" Receiver MethodName ( Function | Signature ) .
Receiver = Parameters .
func (p *parser) funcDeclOrNil() *FuncDecl
funcResult
method
#
Result = Parameters | Type .
func (p *parser) funcResult() []*Field
funcType
method
#
If context != "", type parameters are not permitted.
func (p *parser) funcType(context string) ([]*Field, *FuncType)
got
method
#
func (p *parser) got(tok token) bool
gotAssign
method
#
gotAssign is like got(_Assign) but it also accepts ":="
(and reports an error) for better parser error recovery.
func (p *parser) gotAssign() bool
gotoTarget
method
#
gotoTarget returns the labeled statement matching the given name and
declared in block b or any of its enclosing blocks. The result is nil
if the label is not defined, or doesn't match a valid labeled statement.
func (ls *labelScope) gotoTarget(b *block, name string) *LabeledStmt
groupFor
function
#
func groupFor(d Decl) (token, *Group)
hash
function
#
hash is a perfect hash function for keywords.
It assumes that s has at least length 2.
func hash(s []byte) uint
ident
method
#
func (s *scanner) ident()
ifStmt
method
#
func (p *parser) ifStmt() *IfStmt
impliesSemi
function
#
If impliesSemi returns true for a non-blank line's final token tok,
a semicolon is automatically inserted. Vice versa, a semicolon may
be omitted in those cases.
func impliesSemi(tok token) bool
importDecl
method
#
ImportSpec = [ "." | PackageName ] ImportPath .
ImportPath = string_lit .
func (p *parser) importDecl(group *Group) Decl
init
method
#
func (p *parser) init(file *PosBase, r io.Reader, errh ErrorHandler, pragh PragmaHandler, mode Mode)
init
function
#
func init()
init
method
#
func (s *source) init(in io.Reader, errh func(line uint, col uint, msg string))
init
method
#
func (s *scanner) init(src io.Reader, errh func(line uint, col uint, msg string), mode uint)
interfaceType
method
#
InterfaceType = "interface" "{" { ( MethodDecl | EmbeddedElem ) ";" } "}" .
func (p *parser) interfaceType() *InterfaceType
invalidSep
function
#
invalidSep returns the index of the first invalid separator in x, or -1.
func invalidSep(x string) int
isDecimal
function
#
func isDecimal(ch rune) bool
isEmptyFuncDecl
function
#
func isEmptyFuncDecl(dcl Decl) bool
isExported
function
#
func isExported(name string) bool
isHex
function
#
func isHex(ch rune) bool
isLetter
function
#
func isLetter(ch rune) bool
isTypeElem
function
#
isTypeElem reports whether x is a (possibly parenthesized) type element expression.
The result is false if x could be a type element OR an ordinary (value) expression.
func isTypeElem(x Expr) bool
isValue
function
#
isValue reports whether x syntactically must be a value (and not a type) expression.
func isValue(x Expr) bool
labeledStmtOrNil
method
#
func (p *parser) labeledStmtOrNil(label *Name) Stmt
lastDecl
function
#
func lastDecl(list []Decl) Decl
lastExpr
function
#
func lastExpr(list []Expr) Expr
lastField
function
#
func lastField(list []*Field) *Field
lastStmt
function
#
func lastStmt(list []Stmt) Stmt
list
method
#
list parses a possibly empty, sep-separated list of elements, optionally
followed by sep, and closed by close (or EOF). sep must be one of _Comma
or _Semi, and close must be one of _Rparen, _Rbrace, or _Rbrack.
For each list element, f is called. Specifically, unless we're at close
(or EOF), f is called at least once. After f returns true, no more list
elements are accepted. list returns the position of the closing token.
list = [ f { sep f } [sep] ] close .
func (p *parser) list(context string, sep token, close token, f func() bool) Pos
lower
function
#
func lower(ch rune) rune
mayCombine
function
#
func mayCombine(prev token, next byte) (b bool)
methodDecl
method
#
MethodSpec = MethodName Signature | InterfaceTypeName .
MethodName = identifier .
InterfaceTypeName = TypeName .
func (p *parser) methodDecl() *Field
name
method
#
func (p *parser) name() *Name
nameList
method
#
func (w walker) nameList(list []*Name)
nameList
method
#
IdentifierList = identifier { "," identifier } .
The first name must be provided.
func (p *parser) nameList(first *Name) []*Name
newAssignStmt
method
#
func (p *parser) newAssignStmt(pos Pos, op Operator, lhs Expr, rhs Expr) *AssignStmt
newIndirect
function
#
func newIndirect(pos Pos, typ Expr) Expr
newRangeClause
method
#
func (p *parser) newRangeClause(lhs Expr, def bool) *RangeClause
next
method
#
next advances the scanner by reading the next token.
If a read, source encoding, or lexical error occurs, next calls
the installed error handler with the respective error position
and message. The error message is guaranteed to be non-empty and
never starts with a '/'. The error handler must exist.
If the scanner mode includes the comments flag and a comment
(including comments containing directives) is encountered, the
error handler is also called with each comment position and text
(including opening /* or // and closing */, but without a newline
at the end of line comments). Comment text always starts with a /
which can be used to distinguish these handler calls from errors.
If the scanner mode includes the directives (but not the comments)
flag, only comments containing a //line, /*line, or //go: directive
are reported, in the same way as regular comments.
func (s *scanner) next()
nextSize
function
#
nextSize returns the next bigger size for a buffer of a given size.
func nextSize(size int) int
nextch
method
#
func (s *source) nextch()
node
method
#
func (w walker) node(n Node)
number
method
#
func (s *scanner) number(seenPoint bool)
oliteral
method
#
func (p *parser) oliteral() *BasicLit
operand
method
#
Operand = Literal | OperandName | MethodExpr | "(" Expression ")" .
Literal = BasicLit | CompositeLit | FunctionLit .
BasicLit = int_lit | float_lit | imaginary_lit | rune_lit | string_lit .
OperandName = identifier | QualifiedIdent.
func (p *parser) operand(keep_parens bool) Expr
paramDeclOrNil
method
#
ParameterDecl = [ IdentifierList ] [ "..." ] Type .
func (p *parser) paramDeclOrNil(name *Name, follow token) *Field
paramList
method
#
Parameters = "(" [ ParameterList [ "," ] ] ")" .
ParameterList = ParameterDecl { "," ParameterDecl } .
"(" or "[" has already been consumed.
If name != nil, it is the first name after "(" or "[".
If typ != nil, name must be != nil, and (name, typ) is the first field in the list.
In the result list, either all fields have a name, or no field has a name.
func (p *parser) paramList(name *Name, typ Expr, close token, requireNames bool) (list []*Field)
pexpr
method
#
pexpr parses a PrimaryExpr.
PrimaryExpr =
Operand |
Conversion |
PrimaryExpr Selector |
PrimaryExpr Index |
PrimaryExpr Slice |
PrimaryExpr TypeAssertion |
PrimaryExpr Arguments .
Selector = "." identifier .
Index = "[" Expression "]" .
Slice = "[" ( [ Expression ] ":" [ Expression ] ) |
( [ Expression ] ":" Expression ":" Expression )
"]" .
TypeAssertion = "." "(" Type ")" .
Arguments = "(" [ ( ExpressionList | Type [ "," ExpressionList ] ) [ "..." ] [ "," ] ] ")" .
func (p *parser) pexpr(x Expr, keep_parens bool) Expr
pos
method
#
pos returns the (line, col) source position of s.ch.
func (s *source) pos() (line uint, col uint)
pos
method
#
Convenience methods using the current token position.
func (p *parser) pos() Pos
posAt
method
#
posAt returns the Pos value for (line, col) and the current position base.
func (p *parser) posAt(line uint, col uint) Pos
print
method
#
func (p *parser) print(msg string)
print
method
#
func (p *printer) print(args ...interface{})
printCaseClause
method
#
func (p *printer) printCaseClause(c *CaseClause, braces bool)
printCommClause
method
#
func (p *printer) printCommClause(c *CommClause, braces bool)
printDecl
method
#
func (p *printer) printDecl(list []Decl)
printDeclList
method
#
func (p *printer) printDeclList(list []Decl)
printExprLines
method
#
func (p *printer) printExprLines(list []Expr)
printExprList
method
#
func (p *printer) printExprList(list []Expr)
printFieldList
method
#
func (p *printer) printFieldList(fields []*Field, tags []*BasicLit, sep token)
printFields
method
#
func (p *printer) printFields(fields []*Field, tags []*BasicLit, i int, j int)
printMethodList
method
#
func (p *printer) printMethodList(methods []*Field)
printNameList
method
#
func (p *printer) printNameList(list []*Name)
printNode
method
#
func (p *printer) printNode(n Node)
printParameterList
method
#
If tok != 0 print a type parameter list: tok == _Type means
a type parameter list for a type, tok == _Func means a type
parameter list for a func.
func (p *printer) printParameterList(list []*Field, tok token)
printRawNode
method
#
func (p *printer) printRawNode(n Node)
printSelectBody
method
#
func (p *printer) printSelectBody(list []*CommClause)
printSignature
method
#
func (p *printer) printSignature(sig *FuncType)
printStmtList
method
#
func (p *printer) printStmtList(list []Stmt, braces bool)
printSwitchBody
method
#
func (p *printer) printSwitchBody(list []*CaseClause)
printf
method
#
printf is a convenience wrapper that takes care of print errors.
func (p *dumper) printf(format string, args ...interface{})
qualifiedName
method
#
The first name may be provided, or nil.
func (p *parser) qualifiedName(name *Name) Expr
rawString
method
#
func (s *scanner) rawString()
rewind
method
#
rewind rewinds the scanner's read position and character s.ch
to the start of the currently active segment, which must not
contain any newlines (otherwise position information will be
incorrect). Currently, rewind is only needed for handling the
source sequence ".."; it must not be called outside an active
segment.
func (s *source) rewind()
rune
method
#
func (s *scanner) rune()
sat32
function
#
func sat32(x uint) uint32
segment
method
#
func (s *source) segment() []byte
selectStmt
method
#
func (p *parser) selectStmt() *SelectStmt
setLit
method
#
setLit sets the scanner state for a recognized _Literal token.
func (s *scanner) setLit(kind LitKind, ok bool)
simpleStmt
method
#
SimpleStmt = EmptyStmt | ExpressionStmt | SendStmt | IncDecStmt | Assignment | ShortVarDecl .
func (p *parser) simpleStmt(lhs Expr, keyword token) SimpleStmt
skipLine
method
#
func (s *scanner) skipLine()
sliceType
method
#
"[" and "]" have already been consumed, and pos is the position of "[".
func (p *parser) sliceType(pos Pos) Expr
start
method
#
start starts a new active source segment (including s.ch).
As long as stop has not been called, the active segment's
bytes (excluding s.ch) may be retrieved by calling segment.
func (s *source) start()
stdString
method
#
func (s *scanner) stdString()
stmtList
method
#
StatementList = { Statement ";" } .
func (p *parser) stmtList() (l []Stmt)
stmtList
method
#
func (w walker) stmtList(list []Stmt)
stmtOrNil
method
#
stmtOrNil parses a statement if one is present, or else returns nil.
Statement =
Declaration | LabeledStmt | SimpleStmt |
GoStmt | ReturnStmt | BreakStmt | ContinueStmt | GotoStmt |
FallthroughStmt | Block | IfStmt | SwitchStmt | SelectStmt | ForStmt |
DeferStmt .
func (p *parser) stmtOrNil() Stmt
stop
method
#
func (s *source) stop()
structType
method
#
StructType = "struct" "{" { FieldDecl ";" } "}" .
func (p *parser) structType() *StructType
switchStmt
method
#
func (p *parser) switchStmt() *SwitchStmt
syntaxError
method
#
func (p *parser) syntaxError(msg string)
syntaxErrorAt
method
#
syntaxErrorAt reports a syntax error at the given position.
func (p *parser) syntaxErrorAt(pos Pos, msg string)
takePragma
method
#
takePragma returns the current parsed pragmas
and clears them from the parser state.
func (p *parser) takePragma() Pragma
tokStrFast
function
#
tokStrFast is a faster version of token.String, which assumes that tok
is one of the valid tokens - and can thus skip bounds checks.
func tokStrFast(tok token) string
tokstring
function
#
tokstring returns the English word for selected punctuation tokens
for more readable error messages. Use tokstring (not tok.String())
for user-facing (error) messages; use tok.String() for debugging
output.
func tokstring(tok token) string
trace
method
#
usage: defer p.trace(msg)()
func (p *parser) trace(msg string) func()
trailingDigits
function
#
func trailingDigits(text string) (uint, uint, bool)
trimTrailingEmptyStmts
function
#
func trimTrailingEmptyStmts(list []Stmt) []Stmt
typeDecl
method
#
TypeSpec = identifier [ TypeParams ] [ "=" ] Type .
func (p *parser) typeDecl(group *Group) Decl
typeInstance
method
#
func (p *parser) typeInstance(typ Expr) Expr
typeList
method
#
typeList parses a non-empty, comma-separated list of types,
optionally followed by a comma. If strict is set to false,
the first element may also be a (non-type) expression.
If there is more than one argument, the result is a *ListExpr.
The comma result indicates whether there was a (separating or
trailing) comma.
typeList = arg { "," arg } [ "," ] .
func (p *parser) typeList(strict bool) (x Expr, comma bool)
typeOrNil
method
#
typeOrNil is like type_ but it returns nil if there was no type
instead of reporting an error.
Type = TypeName | TypeLit | "(" Type ")" .
TypeName = identifier | QualifiedIdent .
TypeLit = ArrayType | StructType | PointerType | FunctionType | InterfaceType |
SliceType | MapType | Channel_Type .
func (p *parser) typeOrNil() Expr
type_
method
#
func (p *parser) type_() Expr
unaryExpr
method
#
UnaryExpr = PrimaryExpr | unary_op UnaryExpr .
func (p *parser) unaryExpr() Expr
updateBase
method
#
updateBase sets the current position base to a new line base at pos.
The base's filename, line, and column values are extracted from text
which is positioned at (tline, tcol) (only needed for error messages).
func (p *parser) updateBase(pos Pos, tline uint, tcol uint, text string)
varDecl
method
#
VarSpec = IdentifierList ( Type [ "=" ExpressionList ] | "=" ExpressionList ) .
func (p *parser) varDecl(group *Group) Decl
want
method
#
func (p *parser) want(tok token)
write
method
#
write is a thin wrapper around p.output.Write
that takes care of accounting and error handling.
func (p *printer) write(data []byte)
writeBytes
method
#
func (p *printer) writeBytes(data []byte)
writeString
method
#
func (p *printer) writeString(s string)