Documentation
¶
Overview ¶
Package ast declares the types used to define the template trees.
For example, the source in an "articles.html" file:
{% for article in articles %}
<div>{{ article.title }}</div>
{% end %}
is represented with the tree:
ast.NewTree("articles.txt", []ast.Node{
ast.NewFor(
&ast.Position{Line: 1, Column: 1, Start: 0, End: 69},
nil,
ast.NewIdentifier(&ast.Position{Line: 1, Column: 8, Start: 7, End: 13}, "article"),
ast.NewIdentifier(&ast.Position{Line: 1, Column: 19, Start: 18, End: 25}, "articles"),
nil,
[]ast.Node{
ast.NewText(&ast.Position{Line: 1, Column: 30, Start: 29, End: 34}, []byte("\n<div>"), ast.Cut{1,0}),
ast.NewShow(
&ast.Position{Line: 2, Column: 6, Start: 35, End: 53},
ast.NewSelector(
&ast.Position{Line: 2, Column: 16, Start: 38, End: 50},
ast.NewIdentifier(
&ast.Position{Line: 2, Column: 9, Start: 38, End: 44},
"article",
),
"title"),
ast.ContextHTML),
ast.NewText(&ast.Position{Line: 2, Column: 25, Start: 54, End: 60}, []byte("</div>\n"), ast.Cut{})),
},
),
}, ast.ContextHTML)
Index ¶
- type ArrayType
- type Assignment
- type AssignmentType
- type BasicLiteral
- type BinaryOperator
- type Block
- type Break
- type Call
- type Case
- type ChanDirection
- type ChanType
- type Comment
- type CompositeLiteral
- type Const
- type Context
- type Continue
- type Cut
- type Defer
- type DollarIdentifier
- type Expression
- type Extends
- type Fallthrough
- type Field
- type For
- type ForRange
- type Func
- type FuncType
- type Go
- type Goto
- type Identifier
- type If
- type Import
- type Index
- type Interface
- type KeyValue
- type Label
- type Language
- type LiteralType
- type Macro
- type MapType
- type Node
- type Operator
- type OperatorType
- type Package
- type Parameter
- type Placeholder
- type Position
- type Return
- type Select
- type SelectCase
- type Selector
- type Send
- type Show
- type ShowMacro
- type ShowPartial
- type SliceType
- type Slicing
- type Statements
- type StructType
- type Switch
- type Text
- type Tree
- type TypeAssertion
- type TypeDeclaration
- type TypeSwitch
- type URL
- type UnaryOperator
- type Upvar
- type Var
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ArrayType ¶
type ArrayType struct {
*Position // position in the source.
Len Expression // length. It is nil for arrays specified with ... notation.
ElementType Expression // element type.
// contains filtered or unexported fields
}
ArrayType node represents an array type.
func NewArrayType ¶
func NewArrayType(pos *Position, len Expression, elementType Expression) *ArrayType
func (ArrayType) Parenthesis ¶
func (e ArrayType) Parenthesis() int
Parenthesis returns the number of parenthesis around the expression.
func (ArrayType) SetParenthesis ¶
func (e ArrayType) SetParenthesis(n int)
SetParenthesis sets the number of parenthesis around the expression.
type Assignment ¶
type Assignment struct {
*Position // position in the source.
Lhs []Expression // left hand variables.
Type AssignmentType // type.
Rhs []Expression // assigned values (nil for increment and decrement).
}
Assignment node represents an assignment statement.
func NewAssignment ¶
func NewAssignment(pos *Position, lhs []Expression, typ AssignmentType, rhs []Expression) *Assignment
func (*Assignment) String ¶
func (n *Assignment) String() string
type AssignmentType ¶
type AssignmentType int
const ( AssignmentSimple AssignmentType = iota // = AssignmentDeclaration // := AssignmentAddition // += AssignmentSubtraction // -= AssignmentMultiplication // *= AssignmentDivision // /= AssignmentModulo // %= AssignmentAnd // &= AssignmentOr // |= AssignmentXor // ^= AssignmentAndNot // &^= AssignmentLeftShift // <<= AssignmentRightShift // >>= AssignmentIncrement // ++ AssignmentDecrement // -- )
type BasicLiteral ¶
type BasicLiteral struct {
*Position // position in the source.
Type LiteralType // type.
Value string // value.
// contains filtered or unexported fields
}
func NewBasicLiteral ¶
func NewBasicLiteral(pos *Position, typ LiteralType, value string) *BasicLiteral
func (*BasicLiteral) Parenthesis ¶
func (e *BasicLiteral) Parenthesis() int
Parenthesis returns the number of parenthesis around the expression.
func (*BasicLiteral) SetParenthesis ¶
func (e *BasicLiteral) SetParenthesis(n int)
SetParenthesis sets the number of parenthesis around the expression.
func (*BasicLiteral) String ¶
func (n *BasicLiteral) String() string
type BinaryOperator ¶
type BinaryOperator struct {
*Position // position in the source.
Op OperatorType // operator.
Expr1 Expression // first expression.
Expr2 Expression // second expression.
// contains filtered or unexported fields
}
BinaryOperator node represents a binary operator expression.
func NewBinaryOperator ¶
func NewBinaryOperator(pos *Position, op OperatorType, expr1, expr2 Expression) *BinaryOperator
func (*BinaryOperator) Operator ¶
func (n *BinaryOperator) Operator() OperatorType
Operator returns the operator type of the expression.
func (BinaryOperator) Parenthesis ¶
func (e BinaryOperator) Parenthesis() int
Parenthesis returns the number of parenthesis around the expression.
func (*BinaryOperator) Precedence ¶
func (n *BinaryOperator) Precedence() int
Precedence returns a number that represents the precedence of the expression.
func (BinaryOperator) SetParenthesis ¶
func (e BinaryOperator) SetParenthesis(n int)
SetParenthesis sets the number of parenthesis around the expression.
func (*BinaryOperator) String ¶
func (n *BinaryOperator) String() string
type Break ¶
type Break struct {
*Position // position in the source.
Label *Identifier // label.
}
Break node represents a statement "break".
func NewBreak ¶
func NewBreak(pos *Position, label *Identifier) *Break
type Call ¶
type Call struct {
*Position // position in the source.
Func Expression // function.
Args []Expression // arguments.
IsVariadic bool // reports whether it is variadic.
// contains filtered or unexported fields
}
Call node represents a function call expression.
func NewCall ¶
func NewCall(pos *Position, fun Expression, args []Expression, isVariadic bool) *Call
func (Call) Parenthesis ¶
func (e Call) Parenthesis() int
Parenthesis returns the number of parenthesis around the expression.
func (Call) SetParenthesis ¶
func (e Call) SetParenthesis(n int)
SetParenthesis sets the number of parenthesis around the expression.
type Case ¶
type Case struct {
*Position
Expressions []Expression
Body []Node
}
Case node represents statements "case" and "default".
type ChanDirection ¶
type ChanDirection int
const ( NoDirection ChanDirection = iota ReceiveDirection SendDirection )
func (ChanDirection) String ¶
func (dir ChanDirection) String() string
type ChanType ¶
type ChanType struct {
*Position // position in the source.
Direction ChanDirection // direction.
ElementType Expression // type of chan elements.
// contains filtered or unexported fields
}
ChanType node represents a chan type.
func NewChanType ¶
func NewChanType(pos *Position, direction ChanDirection, elementType Expression) *ChanType
func (ChanType) Parenthesis ¶
func (e ChanType) Parenthesis() int
Parenthesis returns the number of parenthesis around the expression.
func (ChanType) SetParenthesis ¶
func (e ChanType) SetParenthesis(n int)
SetParenthesis sets the number of parenthesis around the expression.
type CompositeLiteral ¶
type CompositeLiteral struct {
*Position // position in the source.
Type Expression // type of the composite literal. nil for composite literals without type.
KeyValues []KeyValue // nil for empty composite literals.
// contains filtered or unexported fields
}
CompositeLiteral node represent a composite literal.
func NewCompositeLiteral ¶
func NewCompositeLiteral(pos *Position, typ Expression, keyValues []KeyValue) *CompositeLiteral
func (CompositeLiteral) Parenthesis ¶
func (e CompositeLiteral) Parenthesis() int
Parenthesis returns the number of parenthesis around the expression.
func (CompositeLiteral) SetParenthesis ¶
func (e CompositeLiteral) SetParenthesis(n int)
SetParenthesis sets the number of parenthesis around the expression.
func (*CompositeLiteral) String ¶
func (n *CompositeLiteral) String() string
type Const ¶
type Const struct {
*Position // position in the source.
Lhs []*Identifier // left-hand side identifiers.
Type Expression // nil for non-typed constant declarations.
Rhs []Expression // nil for implicit-value constant declarations.
Index int // index of the declaration in the constant declaration group or 0 if not in a group.
}
Const node represent a const declaration.
func NewConst ¶
func NewConst(pos *Position, lhs []*Identifier, typ Expression, rhs []Expression, index int) *Const
type Context ¶
type Context int
Context indicates the context in which a value statement must be valuated.
type Continue ¶
type Continue struct {
*Position // position in the source.
Label *Identifier // label.
}
Continue node represents a statement "continue".
func NewContinue ¶
func NewContinue(pos *Position, label *Identifier) *Continue
type Cut ¶
Cut, in a Text node, indicates how many bytes must be cut from the left and the right of the text before rendering the Text node.
type Defer ¶
type Defer struct {
*Position // position in the source.
Call Expression // function or method call (should be a Call node).
}
Defer node represents a defer statement.
func NewDefer ¶
func NewDefer(pos *Position, call Expression) *Defer
type DollarIdentifier ¶ added in v0.25.0
type DollarIdentifier struct {
*Position // position in the source.
Ident *Identifier // identifier.
IR struct {
Ident Expression
}
// contains filtered or unexported fields
}
DollarIdentifier node represents a dollar identifier $id.
func NewDollarIdentifier ¶ added in v0.25.0
func NewDollarIdentifier(pos *Position, ident *Identifier) *DollarIdentifier
func (DollarIdentifier) Parenthesis ¶ added in v0.25.0
func (e DollarIdentifier) Parenthesis() int
Parenthesis returns the number of parenthesis around the expression.
func (DollarIdentifier) SetParenthesis ¶ added in v0.25.0
func (e DollarIdentifier) SetParenthesis(n int)
SetParenthesis sets the number of parenthesis around the expression.
func (*DollarIdentifier) String ¶ added in v0.25.0
func (n *DollarIdentifier) String() string
type Expression ¶
Expression node represents an expression.
type Extends ¶
type Extends struct {
*Position // position in the source.
Path string // path to extend.
Context Context // context.
Tree *Tree // expanded tree of extends.
}
Extends node represents a statement "extends".
type Fallthrough ¶
type Fallthrough struct {
*Position
}
Fallthrough node represents a statement "fallthrough".
func NewFallthrough ¶
func NewFallthrough(pos *Position) *Fallthrough
NewFallthrough returns a new Fallthrough node.
type Field ¶
type Field struct {
Idents []*Identifier // identifiers. If nil is an embedded field.
Type Expression
Tag *string
}
Field represents a field declaration in a struct type. A field declaration can be explicit (having an identifier list and a type) or implicit (having a type only).
func NewField ¶
func NewField(idents []*Identifier, typ Expression, tag *string) *Field
NewField returns a new NewField node.
type For ¶
type For struct {
*Position // position in the source.
Init Node // initialization statement.
Condition Expression // condition expression.
Post Node // post iteration statement.
Body []Node // nodes of the body.
}
For node represents a statement "for".
type ForRange ¶
type ForRange struct {
*Position // position in the source.
Assignment *Assignment // assignment.
Body []Node // nodes of the body.
}
ForRange node represents statements "for range" and "for in".
func NewForRange ¶
func NewForRange(pos *Position, assignment *Assignment, body []Node) *ForRange
type Func ¶
type Func struct {
*Position
Ident *Identifier // name, nil for function literals.
Type *FuncType // type.
Body *Block // body.
Upvars []Upvar // Upvars of func.
// contains filtered or unexported fields
}
Func node represents a function declaration or literal.
func (*Func) Parenthesis ¶
func (e *Func) Parenthesis() int
Parenthesis returns the number of parenthesis around the expression.
func (*Func) SetParenthesis ¶
func (e *Func) SetParenthesis(n int)
SetParenthesis sets the number of parenthesis around the expression.
type FuncType ¶
type FuncType struct {
*Position // position in the source.
Parameters []*Parameter // parameters.
Result []*Parameter // result.
IsVariadic bool // reports whether it is variadic.
Reflect reflect.Type // reflect type.
// contains filtered or unexported fields
}
FuncType node represents a function type.
func NewFuncType ¶
func (*FuncType) Parenthesis ¶
func (e *FuncType) Parenthesis() int
Parenthesis returns the number of parenthesis around the expression.
func (*FuncType) SetParenthesis ¶
func (e *FuncType) SetParenthesis(n int)
SetParenthesis sets the number of parenthesis around the expression.
type Go ¶
type Go struct {
*Position // position in the source.
Call Expression // function or method call (should be a Call node).
}
Go node represents a go statement.
func NewGo ¶
func NewGo(pos *Position, call Expression) *Go
type Goto ¶
type Goto struct {
*Position // position in the source.
Label *Identifier // label.
}
Goto node represents a goto statement.
func NewGoto ¶
func NewGoto(pos *Position, label *Identifier) *Goto
type Identifier ¶
type Identifier struct {
*Position // position in the source.
Name string // name.
// contains filtered or unexported fields
}
Identifier node represents an identifier expression.
func NewIdentifier ¶
func NewIdentifier(pos *Position, name string) *Identifier
func (*Identifier) Parenthesis ¶
func (e *Identifier) Parenthesis() int
Parenthesis returns the number of parenthesis around the expression.
func (*Identifier) SetParenthesis ¶
func (e *Identifier) SetParenthesis(n int)
SetParenthesis sets the number of parenthesis around the expression.
func (*Identifier) String ¶
func (n *Identifier) String() string
type If ¶
type If struct {
*Position // position in the source.
Init Node // init simple statement.
Condition Expression // condition that once evaluated returns true or false.
Then *Block // nodes to run if the expression is evaluated to true.
Else Node // nodes to run if the expression is evaluated to false. Can be Block or If.
}
If node represents a statement "if".
type Import ¶
type Import struct {
*Position // position in the source.
Ident *Identifier // name (including "." and "_") or nil.
Path string // path to import.
Context Context // context.
Tree *Tree // expanded tree of import.
}
Import node represents a statement "import".
type Index ¶
type Index struct {
*Position // position in the source.
Expr Expression // expression.
Index Expression // index.
// contains filtered or unexported fields
}
Index node represents an index expression.
func NewIndex ¶
func NewIndex(pos *Position, expr Expression, index Expression) *Index
func (Index) Parenthesis ¶
func (e Index) Parenthesis() int
Parenthesis returns the number of parenthesis around the expression.
func (Index) SetParenthesis ¶
func (e Index) SetParenthesis(n int)
SetParenthesis sets the number of parenthesis around the expression.
type Interface ¶
type Interface struct {
*Position // position in the source.
// contains filtered or unexported fields
}
Interface node represents an interface type.
func NewInterface ¶
func (Interface) Parenthesis ¶
func (e Interface) Parenthesis() int
Parenthesis returns the number of parenthesis around the expression.
func (Interface) SetParenthesis ¶
func (e Interface) SetParenthesis(n int)
SetParenthesis sets the number of parenthesis around the expression.
type KeyValue ¶
type KeyValue struct {
Key Expression // nil for not-indexed values.
Value Expression
}
KeyValue represents a key value pair in a slice, map or struct composite literal.
type Label ¶
type Label struct {
*Position // position in the source.
Ident *Identifier // identifier.
Statement Node // statement.
}
Label node represents a label statement.
type LiteralType ¶
type LiteralType int
const ( StringLiteral LiteralType = iota RuneLiteral IntLiteral FloatLiteral ImaginaryLiteral )
type Macro ¶
type Macro struct {
*Position // position in the source.
Ident *Identifier // name.
Type *FuncType // type.
Body []Node // body.
Context Context // context.
}
Macro node represents a statement "macro".
type MapType ¶
type MapType struct {
*Position // position in the source.
KeyType Expression // type of map keys.
ValueType Expression // type of map values.
// contains filtered or unexported fields
}
MapType node represents a map type.
func NewMapType ¶
func NewMapType(pos *Position, keyType, valueType Expression) *MapType
func (MapType) Parenthesis ¶
func (e MapType) Parenthesis() int
Parenthesis returns the number of parenthesis around the expression.
func (MapType) SetParenthesis ¶
func (e MapType) SetParenthesis(n int)
SetParenthesis sets the number of parenthesis around the expression.
type Node ¶
type Node interface {
Pos() *Position // node position in the original source
}
Node is an element of the tree.
type Operator ¶
type Operator interface {
Expression
Operator() OperatorType
Precedence() int
}
Operator represents an operator expression. It is implemented by the nodes UnaryOperator and BinaryOperator.
type OperatorType ¶
type OperatorType int
OperatorType represents an operator type in an unary and binary expression.
const ( OperatorEqual OperatorType = iota // == OperatorNotEqual // != OperatorLess // < OperatorLessEqual // <= OperatorGreater // > OperatorGreaterEqual // >= OperatorNot // ! OperatorBitAnd // & OperatorBitOr // | OperatorAnd // && OperatorOr // || OperatorAddition // + OperatorSubtraction // - OperatorMultiplication // * OperatorDivision // / OperatorModulo // % OperatorXor // ^ OperatorAndNot // &^ OperatorLeftShift // << OperatorRightShift // >> OperatorContains // contains OperatorNotContains // not contains OperatorReceive // <- OperatorAddress // & OperatorPointer // * OperatorRelaxedAnd // and OperatorRelaxedOr // or OperatorRelaxedNot // not )
func (OperatorType) String ¶
func (op OperatorType) String() string
type Parameter ¶
type Parameter struct {
Ident *Identifier // name, can be nil.
Type Expression // type.
}
Parameter node represents a parameter in a function type, literal or declaration.
func NewParameter ¶
func NewParameter(ident *Identifier, typ Expression) *Parameter
type Placeholder ¶
type Placeholder struct {
*Position // position in the source.
// contains filtered or unexported fields
}
Placeholder node represent a special placeholder node.
func NewPlaceholder ¶
func NewPlaceholder() *Placeholder
func (Placeholder) Parenthesis ¶
func (e Placeholder) Parenthesis() int
Parenthesis returns the number of parenthesis around the expression.
func (Placeholder) SetParenthesis ¶
func (e Placeholder) SetParenthesis(n int)
SetParenthesis sets the number of parenthesis around the expression.
func (*Placeholder) String ¶
func (n *Placeholder) String() string
type Position ¶
type Position struct {
Line int // line starting from 1
Column int // column in characters starting from 1
Start int // index of the first byte
End int // index of the last byte
}
Position is a position of a node in the source.
type Return ¶
type Return struct {
*Position
Values []Expression // return values.
}
Return node represents a return statement.
func NewReturn ¶
func NewReturn(pos *Position, values []Expression) *Return
type Select ¶
type Select struct {
*Position
LeadingText *Text
Cases []*SelectCase
}
Select node represents a statement "select".
type SelectCase ¶
NewSelectCase represents a statement "case" in a select.
func NewSelectCase ¶
func NewSelectCase(pos *Position, comm Node, body []Node) *SelectCase
NewSelectCase returns a new SelectCase node.
type Selector ¶
type Selector struct {
*Position // position in the source.
Expr Expression // expression.
Ident string // identifier.
// contains filtered or unexported fields
}
Selector node represents a selector expression.
func NewSelector ¶
func NewSelector(pos *Position, expr Expression, ident string) *Selector
func (Selector) Parenthesis ¶
func (e Selector) Parenthesis() int
Parenthesis returns the number of parenthesis around the expression.
func (Selector) SetParenthesis ¶
func (e Selector) SetParenthesis(n int)
SetParenthesis sets the number of parenthesis around the expression.
type Send ¶
type Send struct {
*Position // position in the source.
Channel Expression // channel.
Value Expression // value to send on the channel.
}
Send node represents a send statement.
func NewSend ¶
func NewSend(pos *Position, channel Expression, value Expression) *Send
type Show ¶
type Show struct {
*Position // position in the source.
Expr Expression // expression that once evaluated returns the value to show.
Context Context // context.
}
Show node represents statements {{ ... }} and "show(<expr>)".
type ShowMacro ¶
type ShowMacro struct {
*Position // position in the source.
Macro Expression // macro.
Args []Expression // arguments.
IsVariadic bool // reports whether it is variadic.
Context Context // context.
}
ShowMacro node represents a statement "show <macro>".
func NewShowMacro ¶
func NewShowMacro(pos *Position, macro Expression, args []Expression, isVariadic bool, ctx Context) *ShowMacro
type ShowPartial ¶ added in v0.18.0
type ShowPartial struct {
*Position // position in the source.
Path string // path of the file to show.
Context Context // context.
Tree *Tree // expanded tree of <path>.
}
ShowPartial node represents a statement "show <path>".
func NewShowPartial ¶ added in v0.18.0
func NewShowPartial(pos *Position, path string, ctx Context) *ShowPartial
type SliceType ¶
type SliceType struct {
*Position // position in the source.
ElementType Expression // element type.
// contains filtered or unexported fields
}
SliceType node represents a slice type.
func NewSliceType ¶
func NewSliceType(pos *Position, elementType Expression) *SliceType
func (SliceType) Parenthesis ¶
func (e SliceType) Parenthesis() int
Parenthesis returns the number of parenthesis around the expression.
func (SliceType) SetParenthesis ¶
func (e SliceType) SetParenthesis(n int)
SetParenthesis sets the number of parenthesis around the expression.
type Slicing ¶
type Slicing struct {
*Position // position in the source.
Expr Expression // expression.
Low Expression // low bound.
High Expression // high bound.
Max Expression // max bound.
IsFull bool // reports whether is a full expression.
// contains filtered or unexported fields
}
Slicing node represents a slicing expression.
func NewSlicing ¶
func NewSlicing(pos *Position, expr, low, high Expression, max Expression, isFull bool) *Slicing
func (Slicing) Parenthesis ¶
func (e Slicing) Parenthesis() int
Parenthesis returns the number of parenthesis around the expression.
func (Slicing) SetParenthesis ¶
func (e Slicing) SetParenthesis(n int)
SetParenthesis sets the number of parenthesis around the expression.
type Statements ¶ added in v0.29.0
Statements node represents a statement {%% ... %%}
func NewStatements ¶ added in v0.29.0
func NewStatements(pos *Position, nodes []Node) *Statements
type StructType ¶
StructType node represents a struct type.
func NewStructType ¶
func NewStructType(pos *Position, fields []*Field) *StructType
NewStructType returns a new StructType node.
func (StructType) Parenthesis ¶
func (e StructType) Parenthesis() int
Parenthesis returns the number of parenthesis around the expression.
func (StructType) SetParenthesis ¶
func (e StructType) SetParenthesis(n int)
SetParenthesis sets the number of parenthesis around the expression.
func (*StructType) String ¶
func (n *StructType) String() string
type Switch ¶
type Switch struct {
*Position
Init Node
Expr Expression
LeadingText *Text
Cases []*Case
}
Switch node represents a statement "switch".
type Tree ¶
type Tree struct {
*Position
Path string // path of the tree.
Nodes []Node // nodes of the first level of the tree.
Language Language // source language.
}
Tree node represents a tree.
type TypeAssertion ¶
type TypeAssertion struct {
*Position // position in the source.
Expr Expression // expression.
Type Expression // type, is nil if it is a type switch assertion ".(type)".
// contains filtered or unexported fields
}
TypeAssertion node represents a type assertion expression.
func NewTypeAssertion ¶
func NewTypeAssertion(pos *Position, expr Expression, typ Expression) *TypeAssertion
func (TypeAssertion) Parenthesis ¶
func (e TypeAssertion) Parenthesis() int
Parenthesis returns the number of parenthesis around the expression.
func (TypeAssertion) SetParenthesis ¶
func (e TypeAssertion) SetParenthesis(n int)
SetParenthesis sets the number of parenthesis around the expression.
func (*TypeAssertion) String ¶
func (n *TypeAssertion) String() string
type TypeDeclaration ¶
type TypeDeclaration struct {
*Position // position in the source.
Ident *Identifier // identifier of the type.
Type Expression // expression representing the type.
IsAliasDeclaration bool // reports whether it is an alias declaration or a type definition.
}
TypeDeclaration node represents a type declaration, that is an alias declaration or a type definition.
func NewTypeDeclaration ¶
func NewTypeDeclaration(pos *Position, ident *Identifier, typ Expression, isAliasDeclaration bool) *TypeDeclaration
NewTypeDeclaration returns a new TypeDeclaration node.
func (*TypeDeclaration) String ¶
func (n *TypeDeclaration) String() string
type TypeSwitch ¶
type TypeSwitch struct {
*Position
Init Node
Assignment *Assignment
LeadingText *Text
Cases []*Case
}
TypeSwitch node represents a statement "switch" on types.
func NewTypeSwitch ¶
func NewTypeSwitch(pos *Position, init Node, assignment *Assignment, leadingText *Text, cases []*Case) *TypeSwitch
NewTypeSwitch returns a new TypeSwitch node.
type URL ¶
type URL struct {
*Position // position in the source.
Tag string // tag (in lowercase).
Attribute string // attribute (in lowercase).
Value []Node // value nodes.
Context Context // context.
}
URL node represents an URL in an attribute value. Show nodes that are children of an URL node are rendered accordingly.
type UnaryOperator ¶
type UnaryOperator struct {
*Position // position in the source.
Op OperatorType // operator.
Expr Expression // expression.
// contains filtered or unexported fields
}
UnaryOperator node represents an unary operator expression.
func NewUnaryOperator ¶
func NewUnaryOperator(pos *Position, op OperatorType, expr Expression) *UnaryOperator
func (*UnaryOperator) Operator ¶
func (n *UnaryOperator) Operator() OperatorType
Operator returns the operator type of the expression.
func (UnaryOperator) Parenthesis ¶
func (e UnaryOperator) Parenthesis() int
Parenthesis returns the number of parenthesis around the expression.
func (*UnaryOperator) Precedence ¶
func (n *UnaryOperator) Precedence() int
Precedence returns a number that represents the precedence of the expression.
func (UnaryOperator) SetParenthesis ¶
func (e UnaryOperator) SetParenthesis(n int)
SetParenthesis sets the number of parenthesis around the expression.
func (*UnaryOperator) String ¶
func (n *UnaryOperator) String() string
type Upvar ¶
type Upvar struct {
// PredefinedPkg is the name of the predefined package which holds a
// predefined Upvar. If Upvar is not a predefined Upvar then PredefinedName
// is an empty string.
PredefinedPkg string
// PredefinedName is the name of the predefined declaration of a predefined
// Upvar. If Upvar is not a predefined Upvar then PredefinedName is an empty
// string.
PredefinedName string
// PredefinedValue is the value of the predefined variable Upvar. If Upvar
// is not a predefined then Upvar is nil.
PredefinedValue *reflect.Value
// Declaration is the ast node where Upvar is defined. If Upvar is a
// predefined var then Declaration is nil.
Declaration Node
// Index indexes the Upvars slice of the parent function.
// As a special case, Index is -1 when the Upvar declaration node is a
// sibling of the function declaration node.
//
// Consider this example:
//
// var A
// func g() {
// func f() {
// _ = A
// }
// }
//
// g has one upvar (A) with index -1 (node which declares A is a sibling of
// the declaration of g)
// f has one upvar (A) with index 0, which is the index of A in the Upvars slice of g.
//
// Another example:
//
// func g() {
// var A
// func f() {
// _ = A
// }
// }
//
// g has no upvars
// f has one upvar (A) with index -1 (declaration of A is a sibling of
// declaration of f)
//
Index int16
}
Upvar represents a variable defined outside function body. Even package level variables (predefined or not) are considered upvars.
type Var ¶
type Var struct {
*Position // position in the source.
Lhs []*Identifier // left-hand side of assignment.
Type Expression // nil for non-typed variable declarations.
Rhs []Expression // nil for non-initialized variable declarations.
}
Var node represent a variable declaration by keyword "var".
func NewVar ¶
func NewVar(pos *Position, lhs []*Identifier, typ Expression, rhs []Expression) *Var