Documentation ¶
Index ¶
- Constants
- func Inspect(node Node, f func(Node) bool)
- func PrintError(w io.Writer, err error)
- func Walk(v Visitor, node Node)
- type BadExpr
- type BasicLit
- type BinaryExpr
- type CallExpr
- type Error
- type ErrorHandler
- type ErrorList
- type ErrorVector
- type Expr
- type Ident
- type IndexExpr
- type Node
- type ParenExpr
- type Token
- type UnaryExpr
- type Visitor
Constants ¶
const ( Raw = iota // leave error list unchanged Sorted // sort error list by file, line, and column number NoMultiples // sort error list and leave only the first error per line )
These constants control the construction of the ErrorList returned by GetErrors.
Variables ¶
This section is empty.
Functions ¶
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 for all the non-nil children of node, recursively.
func PrintError ¶
PrintError is a utility function that prints a list of errors to w, one error per line, if the err parameter is an ErrorList. Otherwise it prints the err string.
Types ¶
type BadExpr ¶
A BadExpr node is a placeholder for expressions containing syntax errors for which no correct expression nodes can be created.
type BasicLit ¶
type BasicLit struct { ValuePos token.Pos // literal position 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` }
A BasicLit node represents a literal of basic type.
type BinaryExpr ¶
type BinaryExpr struct { X Expr // left operand OpPos token.Pos // position of Op Op token.Token // operator Y Expr // right operand }
A BinaryExpr node represents a binary expression.
func (*BinaryExpr) End ¶
func (x *BinaryExpr) End() token.Pos
func (*BinaryExpr) Pos ¶
func (x *BinaryExpr) Pos() token.Pos
type CallExpr ¶
type CallExpr struct { Fun Expr // function expression Lparen token.Pos // position of "(" Args []Expr // function arguments; or nil Rparen token.Pos // position of ")" }
A CallExpr node represents an expression followed by an argument list.
type Error ¶
Within ErrorVector, an error is represented by an Error node. The position Pos, if valid, points to the beginning of the offending token, and the error condition is described by Msg.
type ErrorHandler ¶
An implementation of an ErrorHandler may be provided to the Scanner. If a syntax error is encountered and a handler was installed, Error is called with a position and an error message. The position points to the beginning of the offending token.
type ErrorVector ¶
type ErrorVector struct {
// contains filtered or unexported fields
}
ErrorVector implements the ErrorHandler interface. It maintains a list of errors which can be retrieved with GetErrorList and GetError. The zero value for an ErrorVector is an empty ErrorVector ready to use.
A common usage pattern is to embed an ErrorVector alongside a scanner in a data structure that uses the scanner. By passing a reference to an ErrorVector to the scanner's Init call, default error handling is obtained.
func (*ErrorVector) Error ¶
func (h *ErrorVector) Error(pos token.Position, msg string)
ErrorVector implements the ErrorHandler interface.
func (*ErrorVector) ErrorCount ¶
func (h *ErrorVector) ErrorCount() int
ErrorCount returns the number of errors collected.
func (*ErrorVector) GetError ¶
func (h *ErrorVector) GetError(mode int) error
GetError is like GetErrorList, but it returns an error instead so that a nil result can be assigned to an error variable and remains nil.
func (*ErrorVector) GetErrorList ¶
func (h *ErrorVector) GetErrorList(mode int) ErrorList
GetErrorList returns the list of errors collected by an ErrorVector. The construction of the ErrorList returned is controlled by the mode parameter. If there are no errors, the result is nil.
type Ident ¶
An Ident node represents an identifier.
type IndexExpr ¶
type IndexExpr struct { X Expr // expression Lbrack token.Pos // position of "[" Index Expr // index expression Rbrack token.Pos // position of "]" }
An IndexExpr node represents an expression followed by an index.
type ParenExpr ¶
type ParenExpr struct { Lparen token.Pos // position of "(" X Expr // parenthesized expression Rparen token.Pos // position of ")" }
A ParenExpr node represents a parenthesized expression.
type Token ¶
type Token struct {
// contains filtered or unexported fields
}
A Token provides information about a particular run of consecutive runes in a file.