Documentation ¶
Index ¶
- Constants
- func GenGo(f *File) (*ast.File, error)
- func Inspect(node Node, f func(Node) bool)
- func PassScopeChain(f *File)
- func PrintError(w io.Writer, err error)
- func Walk(v Visitor, node Node)
- type AssignStmt
- type BadDecl
- type BadExpr
- type BadStmt
- type BasicLit
- type BinaryExpr
- type BlockStmt
- type CallExpr
- type Comment
- type CommentGroup
- type CompositeLit
- type Decl
- type DeclStmt
- type EmptyStmt
- type Error
- type ErrorHandler
- type ErrorList
- type ErrorVector
- type Expr
- type ExprStmt
- type Field
- type FieldList
- type File
- type GenDecl
- type Ident
- type ImportSpec
- type Importer
- type IndexExpr
- type InterfaceDecl
- type InterfaceType
- type KeyValueExpr
- type KindSpec
- type ModelDecl
- type ModelType
- type Node
- type ObjKind
- type Object
- type ObjectKind
- type Package
- type PairExpr
- type ParenExpr
- type RefExpr
- type Scope
- type SelectorExpr
- type Spec
- type Stmt
- type TableExpr
- type TableForwardExpr
- type UnaryExpr
- type UnitExpr
- type VarDecl
- 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.
const FN_CALL = 57357
const UMINUS = 57356
const YIDENT = 57353
const YIMPORT = 57346
const YINTERFACE = 57351
const YKIND = 57347
const YKIND_DECL = 57348
const YLITERAL = 57354
const YMODEL = 57352
const YNUMBER = 57355
const YPACKAGE = 57349
const YSPECIALIZES = 57350
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 PassScopeChain ¶
func PassScopeChain(f *File)
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 AssignStmt ¶
type AssignStmt struct { Lhs *VarDecl TokPos token.Pos // position of Tok Tok token.Token // assignment token, DEFINE Rhs Expr }
An AssignStmt node represents an assignment or a short variable declaration.
func (*AssignStmt) End ¶
func (s *AssignStmt) End() token.Pos
func (*AssignStmt) Name ¶
func (s *AssignStmt) Name() string
func (*AssignStmt) Pos ¶
func (s *AssignStmt) Pos() token.Pos
type BadDecl ¶
A BadDecl node is a placeholder for declarations containing syntax errors for which no correct declaration nodes can be created.
type BadExpr ¶
A BadExpr node is a placeholder for expressions containing syntax errors for which no correct expression nodes can be created.
type BadStmt ¶
A BadStmt node is a placeholder for statements containing syntax errors for which no correct statement 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
func (*BinaryExpr) String ¶
func (x *BinaryExpr) String() string
type BlockStmt ¶
type BlockStmt struct { Lbrace token.Pos // position of "{" List []Stmt Rbrace token.Pos // position of "}" }
A BlockStmt node represents a braced statement list.
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 Comment ¶
type Comment struct { Slash token.Pos // position of "/" starting the comment Text string // comment text (excluding '\n' for //-style comments) }
A Comment node represents a single //-style or /*-style comment.
type CommentGroup ¶
type CommentGroup struct {
List []*Comment // len(List) > 0
}
A CommentGroup represents a sequence of comments with no other tokens and no empty lines between.
func (*CommentGroup) End ¶
func (g *CommentGroup) End() token.Pos
func (*CommentGroup) Pos ¶
func (g *CommentGroup) Pos() token.Pos
type CompositeLit ¶
type CompositeLit struct { Type Expr // literal type; or nil Lbrace token.Pos // position of "{" Elts []Expr // list of composite elements; or nil Rbrace token.Pos // position of "}" }
A CompositeLit node represents a composite literal.
func (*CompositeLit) End ¶
func (x *CompositeLit) End() token.Pos
func (*CompositeLit) Pos ¶
func (x *CompositeLit) Pos() token.Pos
type Decl ¶
type Decl interface { Node // contains filtered or unexported methods }
All declaration nodes implement the Decl interface.
type DeclStmt ¶
type DeclStmt struct {
Decl *VarDecl
}
A DeclStmt node represents a declaration in a statement list.
type EmptyStmt ¶
An EmptyStmt node represents an empty statement. The "position" of the empty statement is the position of the immediately preceding semicolon.
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 Expr ¶
type Expr interface { Node // contains filtered or unexported methods }
All expression nodes implement the Expr interface.
type ExprStmt ¶
type ExprStmt struct {
X Expr // expression
}
An ExprStmt node represents a (stand-alone) expression in a statement list.
type Field ¶
type Field struct { Doc *CommentGroup // associated documentation; or nil Names []*Ident // field/method/parameter names; or nil if anonymous field Type Expr // field/method/parameter type Value Expr // field/method/parameter value Tag *BasicLit // field tag; or nil Comment *CommentGroup // line comments; or nil }
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.
type FieldList ¶
type FieldList struct { Opening token.Pos // position of opening parenthesis/brace, if any List []*Field // field list; or nil Closing token.Pos // position of closing parenthesis/brace, if any }
A FieldList represents a list of Fields, enclosed by parentheses or braces.
type File ¶
type File struct { Doc *CommentGroup // associated documentation; or nil Package token.Pos // position of "package" keyword 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 Comments []*CommentGroup // list of all comments in the source file NErrors int // number of errors }
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.
type GenDecl ¶
type GenDecl struct { Doc *CommentGroup // associated documentation; or nil TokPos token.Pos // position of Tok Tok token.Token // IMPORT, CONST, TYPE, VAR Lparen token.Pos // position of '(', if any Specs []Spec Rparen token.Pos // position of ')', if any }
A GenDecl node (generic declaration node) represents an import, constant, type or variable declaration. A valid Lparen position (Lparen.Line > 0) indicates a parenthesized declaration.
Relationship between Tok value and Specs element type:
token.IMPORT *ImportSpec token.CONST *ValueSpec token.TYPE *TypeSpec token.VAR *ValueSpec
type Ident ¶
type Ident struct { NamePos token.Pos // identifier position Name string // identifier name Obj *Object // denoted object; or nil }
An Ident node represents an identifier.
type ImportSpec ¶
type ImportSpec struct { Doc *CommentGroup // associated documentation; or nil Name *Ident // local package name (including "."); or nil Path *BasicLit // import path Comment *CommentGroup // line comments; or nil EndPos token.Pos // end of spec (overrides Path.Pos if nonzero) }
An ImportSpec node represents a single package import.
func (*ImportSpec) End ¶
func (s *ImportSpec) End() token.Pos
func (*ImportSpec) Pos ¶
func (s *ImportSpec) Pos() token.Pos
Pos and End implementations for spec nodes.
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 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 InterfaceDecl ¶
type InterfaceDecl struct { Doc *CommentGroup // associated documentation; or nil Name *Ident // function/method name Super *Ident // function/method name Units *BasicLit // position of Func keyword, parameters and results Body *BlockStmt // function body; or nil (forward declaration) }
A InterfaceDecl node represents an interface declaration.
func (*InterfaceDecl) End ¶
func (d *InterfaceDecl) End() token.Pos
func (*InterfaceDecl) Pos ¶
func (d *InterfaceDecl) Pos() token.Pos
type InterfaceType ¶
type InterfaceType struct { Interface token.Pos // position of "interface" keyword Methods *FieldList // list of methods Incomplete bool // true if (source) methods are missing in the Methods list }
An InterfaceType node represents an interface type.
func (*InterfaceType) End ¶
func (x *InterfaceType) End() token.Pos
func (*InterfaceType) Pos ¶
func (x *InterfaceType) Pos() token.Pos
type KeyValueExpr ¶
A KeyValueExpr node represents (key : value) pairs in composite literals.
func (*KeyValueExpr) End ¶
func (x *KeyValueExpr) End() token.Pos
func (*KeyValueExpr) Pos ¶
func (x *KeyValueExpr) Pos() token.Pos
type KindSpec ¶
type KindSpec struct { Doc *CommentGroup // associated documentation; or nil Names []*Ident // value names (len(Names) > 0) Type Expr // value type; or nil Values []Expr // initial values; or nil Comment *CommentGroup // line comments; or nil }
A ValueSpec node represents a constant or variable declaration (ConstSpec or VarSpec production).
type ModelDecl ¶
type ModelDecl struct { Objects *Scope // all declared variables Doc *CommentGroup // associated documentation; or nil Recv *FieldList // receiver (methods); or nil (functions) Name *Ident // function/method name Super *Ident // function/method name Units *BasicLit // position of Func keyword, parameters and results Body *BlockStmt // function body; or nil (forward declaration) Virtual bool // if the model has decls which require initialization Errors int // number of errors, such as unresolvable refs }
A ModelDecl node represents a model declaration.
type ModelType ¶
type ModelType struct { Model token.Pos // position of "struct" keyword Fields *FieldList // list of field declarations Incomplete bool // true if (source) fields are missing in the Fields list }
A ModelType node represents a model type.
type Node ¶
type Node interface { Pos() token.Pos // position of first character belonging to the node End() token.Pos // position of first character immediately after the node }
All node types implement the Node interface.
type ObjKind ¶
type ObjKind int
ObKind describes what an object represents.
type Object ¶
type Object struct { Kind ObjKind Name string // declared name Decl interface{} // corresponding Field, XxxSpec, FuncDecl, or LabeledStmt; or nil Data interface{} // object-specific data; or nil Type interface{} // place holder 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 Con != nil constant value
type ObjectKind ¶
type ObjectKind int
const ( ObjModel ObjectKind = iota ObjInterface ObjKynd ObjFlow ObjStock ObjTime ObjAux ObjString )
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 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 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 SelectorExpr ¶
A SelectorExpr node represents an expression followed by a selector.
func (*SelectorExpr) End ¶
func (x *SelectorExpr) End() token.Pos
func (*SelectorExpr) Pos ¶
func (x *SelectorExpr) Pos() token.Pos
type Spec ¶
type Spec interface { Node // contains filtered or unexported methods }
The Spec type stands for any of *ImportSpec, *ValueSpec, and *TypeSpec.
type TableExpr ¶
type TableExpr struct { Lbrack token.Pos Pairs []*PairExpr // function arguments; or nil Rbrack token.Pos }
A CallExpr node represents an expression followed by an argument list.
type TableForwardExpr ¶
type TableForwardExpr struct {
Ys []*BasicLit
}
An expression is represented by a tree consisting of one or more of the following concrete expression nodes.
type UnaryExpr ¶
type UnaryExpr struct { OpPos token.Pos // position of Op Op token.Token // operator X Expr // operand }
A UnaryExpr node represents a unary expression. Unary "*" expressions are represented via StarExpr nodes.
type UnitExpr ¶
An expression is represented by a tree consisting of one or more of the following concrete expression nodes.