parse

package
v0.0.0-...-8674228 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 16, 2020 License: GPL-3.0 Imports: 9 Imported by: 1

Documentation

Index

Constants

View Source
const (
	Break       = _Break
	Continue    = _Continue
	Fallthrough = _Fallthrough
	Goto        = _Goto

	//for CallStmt
	CX    = _CX
	Green = _Green
)
View Source
const PosMax = 1 << 30
View Source
const (
	StandardScanMode = 1 << iota
)

scanner modes. Currently only one.

Variables

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

Golang is retarded and represents inc/dec as x (+/-)= ImplicitOne

Functions

func Fdump

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

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

func String

func String(n Node) string

Types

type ArrayType

type ArrayType struct {
	Len  Expr //nil means len is ellipses
	Elem Expr
	// contains filtered or unexported fields
}

type AssignStmt

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

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

placeholder for an expression failing to parse correctly and where no better one can be found.

type BasicLit

type BasicLit struct {
	Value string
	Kind  LitKind
	Bad   bool //true means literal value has syntactic errors.
	// contains filtered or unexported fields
}

type BlockPolyStmt

type BlockPolyStmt struct {
	List   []PolyStmt
	Rbrace Pos
	// contains filtered or unexported fields
}

type BlockStmt

type BlockStmt struct {
	List   []Stmt
	Rbrace Pos
	// contains filtered or unexported fields
}

type BranchStmt

type BranchStmt struct {
	Tok   token //Break, Continue, Fallthrough, or Goto
	Label *Name
	//Target is the continuation of the control folow after the branch
	//has been executed, and is computed by the parser if CheckBranches
	//is set (which is pretty much always). Target is *LabeledStmt for gotos,
	//and *SwitchStmt, *SelectStmt, or *ForStmt for breaks and continues
	//(depending on branch context). Target is unset for fallthroughs.
	Target Stmt
	// contains filtered or unexported fields
}

type CallExpr

type CallExpr struct {
	Func    Expr
	ArgList []Expr //nil means no arguments
	HasDots bool   //last argument is followed by ellipses
	// contains filtered or unexported fields
}

type CallStmt

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

type CaseClause

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

func (*CaseClause) Pos

func (n *CaseClause) Pos() Pos

type ChanDir

type ChanDir uint
const (
	SendOnly ChanDir
	RecvOnly
)

type ChanType

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

type CommClause

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

func (*CommClause) Pos

func (n *CommClause) Pos() Pos

type CompositeLit

type CompositeLit struct {
	Type     Expr //nil means no literal type
	ElemList []Expr
	NKeys    int
	Rbrace   Pos
	// contains filtered or unexported fields
}

type ConstDecl

type ConstDecl struct {
	Group    *Group
	NameList []*Name
	Type     Expr //nil means no type
	Values   Expr //nil means no values
	// contains filtered or unexported fields
}

type Decl

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

type DeclStmt

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

type DotsType

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

type EmptyStmt

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

type Error

type Error struct {
	Pos Pos
	Msg string
}

Error describes syntax error, implements error interface.

func (Error) Error

func (err Error) Error() string

type ErrorHandler

type ErrorHandler func(err error)

Called for each error encountered in reading source file.

type Expr

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

type ExprStmt

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

type Field

type Field struct {
	Name *Name //nil means anonymous field/parameter or embedded interface
	Type Expr  //field names declared in a list share the same type (identical pointers)
	// contains filtered or unexported fields
}

func (*Field) Pos

func (n *Field) Pos() Pos

type ForStmt

type ForStmt struct {
	Init SimpleStmt //includes *RangeClause
	Cond Expr
	Post SimpleStmt
	Body *BlockStmt
	// contains filtered or unexported fields
}

type FuncDecl

type FuncDecl struct {
	Recv *Field //method/caller object. Nil means regular function.
	Name *Name
	Type *FuncType
	Body *BlockStmt //nil means no body (fwd declaration)
	// contains filtered or unexported fields
}

type FuncLit

type FuncLit struct {
	Type *FuncType
	Body *BlockStmt
	// contains filtered or unexported fields
}

type FuncType

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

type GFile

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

func Parse

func Parse(base *PosBase, src io.Reader, errh ErrorHandler, mode Mode) (_ *GFile, first error)

func ParseFile

func ParseFile(filename string, errh ErrorHandler, mode Mode) (*GFile, error)

ParseFile behaves like Parse but it reads the source from the named file.

func (*GFile) Pos

func (n *GFile) Pos() Pos

type Group

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

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

type IfStmt

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

type ImportDecl

type ImportDecl struct {
	Group        *Group //nil means not pqart of a group
	LocalPkgName *Name  //including "."; nil means no rename present
	Path         *BasicLit
	// contains filtered or unexported fields
}

type IndexExpr

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

type InterfaceType

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

type KeyValueExpr

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

type LabeledStmt

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

type ListExpr

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

type LitKind

type LitKind uint8
const (
	IntLit LitKind = iota
	FloatLit
	//RuneLit //removed since CX does not need runes.
	StringLit
)

type MapType

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

type Mode

type Mode uint
const (
	CheckBranches Mode = 1 << iota
)

type Name

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

type Node

type Node interface {
	/* Pos() will return filepath, line, and column of the syntax object. */
	Pos() Pos
	// contains filtered or unexported methods
}

type Operation

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

type Operator

type Operator uint
const (

	//Def is the : in :=
	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

func (i Operator) String() string

type ParenExpr

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

type PolyEvalDecl

type PolyEvalDecl struct {
	Name     *Name
	RecvName *Name          //name of PolyStruct type that can be the receiver
	Body     *BlockPolyStmt //nil means no body
	Type     *FuncType
	// contains filtered or unexported fields
}

type PolyExpr

type PolyExpr struct {
	Name     *Name
	ElemList []Expr
	// contains filtered or unexported fields
}

type PolyField

type PolyField struct {
	Name      *Name
	TupleType []Expr
	// contains filtered or unexported fields
}

func (*PolyField) Pos

func (n *PolyField) Pos() Pos

type PolyStmt

type PolyStmt struct {
	PType *Name
	Args  []*Name
	Block *BlockStmt
	// contains filtered or unexported fields
}

type PolyStructDecl

type PolyStructDecl struct {
	Name *Name
	Type *PolyType
	// contains filtered or unexported fields
}

type PolyType

type PolyType struct {
	FieldList []*PolyField
	// contains filtered or unexported fields
}

type Pos

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

func MakePos

func MakePos(base *PosBase, line, col uint) Pos

func (Pos) Base

func (pos Pos) Base() *PosBase

func (Pos) Col

func (pos Pos) Col() uint

func (Pos) IsKnown

func (pos Pos) IsKnown() bool

func (Pos) Line

func (pos Pos) Line() uint

func (Pos) RelCol

func (pos Pos) RelCol() uint

func (Pos) RelFilename

func (pos Pos) RelFilename() string

func (Pos) RelLine

func (pos Pos) RelLine() uint

func (Pos) String

func (pos Pos) String() string

type PosBase

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

represents base for relative position. filename:line:col

func NewFileBase

func NewFileBase(filename string) *PosBase

func NewLineBase

func NewLineBase(pos Pos, filename string, line, col uint) *PosBase

func (*PosBase) Col

func (base *PosBase) Col() uint

func (*PosBase) Filename

func (base *PosBase) Filename() string

func (*PosBase) IsFileBase

func (base *PosBase) IsFileBase() bool

func (*PosBase) Line

func (base *PosBase) Line() uint

func (*PosBase) Pos

func (base *PosBase) Pos() (_ Pos)

type RangeClause

type RangeClause struct {
	Lhs Expr //nil means no Lhs = or Lhs :=
	Def bool //is this :=?
	X   Expr //range X
	// contains filtered or unexported fields
}

type ReturnStmt

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

type SelectStmt

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

type SelectorExpr

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

type SendStmt

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

type SimpleStmt

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

type SliceExpr

type SliceExpr struct {
	X     Expr
	Index [3]Expr
	Full  bool
	// contains filtered or unexported fields
}

type SliceType

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

type Stmt

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

type StructType

type StructType struct {
	FieldList []*Field
	// contains filtered or unexported fields
}

type SwitchStmt

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

type TypeDecl

type TypeDecl struct {
	Group *Group
	Name  *Name
	Alias bool
	Type  Expr
	// contains filtered or unexported fields
}

type VarDecl

type VarDecl struct {
	Group    *Group
	NameList []*Name
	Type     Expr
	Values   Expr
	// contains filtered or unexported fields
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL