Go: cmd/compile/internal/syntax Index | Files

package syntax

import "cmd/compile/internal/syntax"

Index

Package Files

dumper.go nodes.go parser.go printer.go scanner.go source.go syntax.go tokens.go

Constants

const (
    // for BranchStmt
    Break       = _Break
    Continue    = _Continue
    Fallthrough = _Fallthrough
    Goto        = _Goto

    // for CallStmt
    Go    = _Go
    Defer = _Defer
)

Variables

var ImplicitOne = &BasicLit{Value: "1"}

We represent x++, x-- as assignments x += ImplicitOne, x -= ImplicitOne. ImplicitOne should not be used elsewhere.

func Fdump Uses

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 Uses

func Fprint(w io.Writer, x Node, linebreaks bool) (n int, err error)

func String Uses

func String(n Node) string

type ArrayType Uses

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 Uses

type AssertExpr struct {
    X   Expr
    // TODO(gri) consider using Name{"..."} instead of nil (permits attaching of comments)
    Type Expr
    // contains filtered or unexported fields
}

X.(Type)

type AssignStmt Uses

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 BasicLit Uses

type BasicLit struct {
    Value string
    Kind  LitKind
    // contains filtered or unexported fields
}

Value

type BlockStmt Uses

type BlockStmt struct {
    Body []Stmt
    // contains filtered or unexported fields
}

type BranchStmt Uses

type BranchStmt struct {
    Tok   token // Break, Continue, Fallthrough, or Goto
    Label *Name
    // contains filtered or unexported fields
}

type CallExpr Uses

type CallExpr struct {
    Fun     Expr
    ArgList []Expr
    HasDots bool // last argument is followed by ...
    // contains filtered or unexported fields
}

Fun(ArgList[0], ArgList[1], ...)

type CallStmt Uses

type CallStmt struct {
    Tok  token // Go or Defer
    Call *CallExpr
    // contains filtered or unexported fields
}

type CaseClause Uses

type CaseClause struct {
    Cases Expr // nil means default clause
    Body  []Stmt
    // contains filtered or unexported fields
}

func (*CaseClause) Line Uses

func (n *CaseClause) Line() uint32

type ChanDir Uses

type ChanDir uint
const (
    SendOnly ChanDir
    RecvOnly
)

type ChanType Uses

type ChanType struct {
    Dir  ChanDir // 0 means no direction
    Elem Expr
    // contains filtered or unexported fields
}
chan Elem

<-chan Elem chan<- Elem

type CommClause Uses

type CommClause struct {
    Comm SimpleStmt // send or receive stmt; nil means default clause
    Body []Stmt
    // contains filtered or unexported fields
}

func (*CommClause) Line Uses

func (n *CommClause) Line() uint32

type Comment Uses

type Comment struct {
    Kind CommentKind
    Text string
    Next *Comment
}

type CommentKind Uses

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 Uses

type CompositeLit struct {
    Type     Expr // nil means no literal type
    ElemList []Expr
    NKeys    int    // number of elements with keys
    EndLine  uint32 // TODO(mdempsky): Cleaner solution.
    // contains filtered or unexported fields
}

Type { ElemList[0], ElemList[1], ... }

type ConstDecl Uses

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 Uses

type Decl interface {
    Node
    // contains filtered or unexported methods
}

type DeclStmt Uses

type DeclStmt struct {
    DeclList []Decl
    // contains filtered or unexported fields
}

type DotsType Uses

type DotsType struct {
    Elem Expr
    // contains filtered or unexported fields
}

...Elem

type EmptyStmt Uses

type EmptyStmt struct {
    // contains filtered or unexported fields
}

type Error Uses

type Error struct {
    // TODO(gri) decide what we really need here
    Pos  int // byte offset from file start
    Line int // line (starting with 1)
    Msg  string
}

Error describes a syntax error. Error implements the error interface.

func (Error) Error Uses

func (err Error) Error() string

type ErrorHandler Uses

type ErrorHandler func(err error)

An ErrorHandler is called for each error encountered reading a .go file.

type Expr Uses

type Expr interface {
    Node
    // contains filtered or unexported methods
}

type ExprStmt Uses

type ExprStmt struct {
    X Expr
    // contains filtered or unexported fields
}

type Field Uses

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 (*Field) Line Uses

func (n *Field) Line() uint32

type File Uses

type File struct {
    PkgName  *Name
    DeclList []Decl
    Lines    int
    // contains filtered or unexported fields
}

package PkgName; DeclList[0], DeclList[1], ...

func Parse Uses

func Parse(src io.Reader, errh ErrorHandler, pragh PragmaHandler, mode Mode) (_ *File, err error)

Parse parses a single Go source file from src and returns the corresponding syntax tree. If there are syntax errors, Parse will return the first error encountered.

If errh != nil, it is called with each error encountered, and Parse will process as much source as possible. If errh is nil, Parse will terminate immediately upon encountering an error.

If a PragmaHandler is provided, it is called with each pragma encountered.

The Mode argument is currently ignored.

func ParseBytes Uses

func ParseBytes(src []byte, errh ErrorHandler, pragh PragmaHandler, mode Mode) (*File, error)

ParseBytes behaves like Parse but it reads the source from the []byte slice provided.

func ParseFile Uses

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 (*File) Line Uses

func (n *File) Line() uint32

type ForStmt Uses

type ForStmt struct {
    Init SimpleStmt // incl. *RangeClause
    Cond Expr
    Post SimpleStmt
    Body []Stmt
    // contains filtered or unexported fields
}

type FuncDecl Uses

type FuncDecl struct {
    Attr    map[string]bool // go:attr map
    Recv    *Field          // nil means regular function
    Name    *Name
    Type    *FuncType
    Body    []Stmt // nil means no body (forward declaration)
    Pragma  Pragma // TODO(mdempsky): Cleaner solution.
    EndLine uint32 // 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 Uses

type FuncLit struct {
    Type    *FuncType
    Body    []Stmt
    EndLine uint32 // TODO(mdempsky): Cleaner solution.
    // contains filtered or unexported fields
}

func Type { Body }

type FuncType Uses

type FuncType struct {
    ParamList  []*Field
    ResultList []*Field
    // contains filtered or unexported fields
}

type Group Uses

type Group struct {
    // contains filtered or unexported fields
}

All declarations belonging to the same group point to the same Group node.

type IfStmt Uses

type IfStmt struct {
    Init SimpleStmt
    Cond Expr
    Then []Stmt
    Else Stmt // either *IfStmt or *BlockStmt
    // contains filtered or unexported fields
}

type ImportDecl Uses

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 Uses

type IndexExpr struct {
    X     Expr
    Index Expr
    // contains filtered or unexported fields
}

X[Index]

type InterfaceType Uses

type InterfaceType struct {
    MethodList []*Field
    // contains filtered or unexported fields
}

interface { MethodList[0]; MethodList[1]; ... }

type KeyValueExpr Uses

type KeyValueExpr struct {
    Key, Value Expr
    // contains filtered or unexported fields
}

Key: Value

type LabeledStmt Uses

type LabeledStmt struct {
    Label *Name
    Stmt  Stmt
    // contains filtered or unexported fields
}

type ListExpr Uses

type ListExpr struct {
    ElemList []Expr
    // contains filtered or unexported fields
}

ElemList[0], ElemList[1], ...

type LitKind Uses

type LitKind uint
const (
    IntLit LitKind = iota
    FloatLit
    ImagLit
    RuneLit
    StringLit
)

type MapType Uses

type MapType struct {
    Key   Expr
    Value Expr
    // contains filtered or unexported fields
}

map[Key]Value

type Mode Uses

type Mode uint

Mode describes the parser mode.

type Name Uses

type Name struct {
    Value string
    // contains filtered or unexported fields
}

Value

type Node Uses

type Node interface {
    Line() uint32
    // contains filtered or unexported methods
}

type Operation Uses

type Operation struct {
    Op   Operator
    X, Y Expr // Y == nil means unary expression
    // contains filtered or unexported fields
}

type Operator Uses

type Operator uint
const (
    Def  Operator // :=
    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    // >>
)

func (Operator) String Uses

func (op Operator) String() string

type ParenExpr Uses

type ParenExpr struct {
    X Expr
    // contains filtered or unexported fields
}

(X)

type Pragma Uses

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 Uses

type PragmaHandler func(pos, line int, text string) Pragma

A PragmaHandler is used to process //line and //go: directives as they're scanned. The returned Pragma value will be unioned into the next FuncDecl node.

type RangeClause Uses

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 Uses

type ReturnStmt struct {
    Results Expr // nil means no explicit return values
    // contains filtered or unexported fields
}

type SelectStmt Uses

type SelectStmt struct {
    Body []*CommClause
    // contains filtered or unexported fields
}

type SelectorExpr Uses

type SelectorExpr struct {
    X   Expr
    Sel *Name
    // contains filtered or unexported fields
}

X.Sel

type SendStmt Uses

type SendStmt struct {
    Chan, Value Expr // Chan <- Value
    // contains filtered or unexported fields
}

type SimpleStmt Uses

type SimpleStmt interface {
    Stmt
    // contains filtered or unexported methods
}

type SliceExpr Uses

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 Uses

type SliceType struct {
    Elem Expr
    // contains filtered or unexported fields
}

[]Elem

type Stmt Uses

type Stmt interface {
    Node
    // contains filtered or unexported methods
}

type StructType Uses

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 Uses

type SwitchStmt struct {
    Init SimpleStmt
    Tag  Expr
    Body []*CaseClause
    // contains filtered or unexported fields
}

type TypeDecl Uses

type TypeDecl struct {
    Name   *Name
    Type   Expr
    Group  *Group // nil means not part of a group
    Pragma Pragma
    // contains filtered or unexported fields
}

Name Type

type TypeSwitchGuard Uses

type TypeSwitchGuard struct {
    // TODO(gri) consider using Name{"..."} instead of nil (permits attaching of comments)
    Lhs *Name // nil means no Lhs :=
    X   Expr  // X.(type)
    // contains filtered or unexported fields
}

type VarDecl Uses

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

Package syntax imports 8 packages (graph) and is imported by 2 packages. Updated 2017-05-28. Refresh now. Tools for package owners.