Documentation
¶
Overview ¶
Package ast declares the types used to define program and template trees.
For example, the source in a template file named "articles.html":
{% for article in articles %}
<div>{{ article.Title }}</div>
{% end %}
is represented with the tree:
ast.NewTree("articles.txt", []ast.Node{
ast.NewForIn(
&ast.Position{Line: 1, Column: 1, Start: 0, End: 69},
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"),
[]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.Expression{
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.FormatHTML)
Index ¶
- func StringWithParenthesis(expr Expression) string
- 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 Default
- type Defer
- type Expression
- type Extends
- type Fallthrough
- type Field
- type For
- type ForIn
- type ForRange
- type Format
- type Func
- type FuncType
- type Go
- type Goto
- type Identifier
- type If
- type Import
- type Index
- type Interface
- type KeyValue
- type Label
- type LiteralType
- type MapType
- type Node
- type Operator
- type OperatorType
- type Package
- type Parameter
- type Placeholder
- type Position
- type Raw
- type Render
- type Return
- type Select
- type SelectCase
- type Selector
- type Send
- type Show
- 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 Using
- type Var
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func StringWithParenthesis ¶ added in v0.53.5
func StringWithParenthesis(expr Expression) string
StringWithParenthesis returns the string representation of the given expression, surrounding it by parenthesis if necessary.
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
NewArrayType returns a new ArrayType node.
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
NewAssignment returns a new Assignment node.
func (*Assignment) String ¶
func (n *Assignment) String() string
String returns the string representation of n.
type AssignmentType ¶
type AssignmentType int
AssignmentType represents a type of assignment.
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
}
BasicLiteral represents integer, floating-point, imaginary, rune and string literals.
func NewBasicLiteral ¶
func NewBasicLiteral(pos *Position, typ LiteralType, value string) *BasicLiteral
NewBasicLiteral returns a new BasicLiteral node.
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
String returns the string representation of n.
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
NewBinaryOperator returns a new binary operator.
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
String returns the string representation of n.
type Block ¶
Block node represents a block with his own scope.
type Break ¶
type Break struct {
*Position // position in the source.
Label *Identifier // label.
}
Break node represents a "break" statement.
type Call ¶
type Call struct {
*Position // position in the source.
Func Expression // function.
Args []Expression // arguments.
IsVariadic bool // reports whether it is variadic.
IR struct {
// AppendArg1, in transformed calls to the builtin function 'append',
// is the argument with index 1.
AppendArg1 *Call
}
// 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
NewCall returns a new Call node.
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 "case" and "default" statements.
type ChanDirection ¶
type ChanDirection int
ChanDirection represents the direction of a channel type.
const ( NoDirection ChanDirection = iota ReceiveDirection SendDirection )
func (ChanDirection) String ¶
func (dir ChanDirection) String() string
String returns the name of the direction dir or "no direction" if there is no direction.
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
NewChanType returns a new ChanType node.
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 represents a composite literal.
func NewCompositeLiteral ¶
func NewCompositeLiteral(pos *Position, typ Expression, keyValues []KeyValue) *CompositeLiteral
NewCompositeLiteral returns a new CompositeLiteral node.
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
String returns the string representation of n.
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 represents a "const" declaration.
func NewConst ¶
func NewConst(pos *Position, lhs []*Identifier, typ Expression, rhs []Expression, index int) *Const
NewConst returns a new Const node.
type Context ¶
type Context int
Context indicates the context in which a show statement is evaluated.
type Continue ¶
type Continue struct {
*Position // position in the source.
Label *Identifier // label.
}
Continue node represents a "continue" statement.
func NewContinue ¶
func NewContinue(pos *Position, label *Identifier) *Continue
NewContinue returns a new Continue node.
type Cut ¶
Cut indicates, in a Text node, how many bytes should be cut from the left and the right of the text before rendering the Text node.
type Default ¶
type Default struct {
*Position // position in the source.
Expr1 Expression // left hand expression.
Expr2 Expression // right hand expression.
// contains filtered or unexported fields
}
Default node represents a default expression.
func NewDefault ¶
func NewDefault(pos *Position, expr1, expr2 Expression) *Default
NewDefault returns a new Default node.
func (*Default) Parenthesis ¶
func (e *Default) Parenthesis() int
Parenthesis returns the number of parenthesis around the expression.
func (*Default) SetParenthesis ¶
func (e *Default) SetParenthesis(n int)
SetParenthesis sets the number of parenthesis around the expression.
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.
type Expression ¶
Expression node represents an expression.
type Extends ¶
type Extends struct {
*Position // position in the source.
Path string // path to extend.
Format Format // format.
Tree *Tree // expanded tree of extends.
}
Extends node represents an "extends" declaration.
func NewExtends ¶
NewExtends returns a new Extends node.
type Fallthrough ¶
type Fallthrough struct {
*Position
}
Fallthrough node represents a "fallthrough" statement.
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 Field 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 "for" statement.
type ForIn ¶
type ForIn struct {
*Position // position in the source.
Ident *Identifier // identifier.
Expr Expression // range expression.
Body []Node // nodes of the body.
Else *Block // nodes to run if the body is not executed.
}
ForIn node represents a "for in" statement.
func NewForIn ¶
func NewForIn(pos *Position, ident *Identifier, expr Expression, body []Node, els *Block) *ForIn
NewForIn represents a new ForIn node.
type ForRange ¶
type ForRange struct {
*Position // position in the source.
Assignment *Assignment // assignment.
Body []Node // nodes of the body.
Else *Block // nodes to run if the body is not executed.
}
ForRange node represents the "for range" statement.
func NewForRange ¶
func NewForRange(pos *Position, assignment *Assignment, body []Node, els *Block) *ForRange
NewForRange returns a new ForRange node.
type Func ¶
type Func struct {
*Position
Ident *Identifier // name, nil for function literals.
Type *FuncType // type.
Body *Block // body.
DistFree bool // reports whether it is distraction free.
Upvars []Upvar // Upvars of func.
Format Format // macro format.
// contains filtered or unexported fields
}
Func node represents a function declaration or literal.
func NewFunc ¶
func NewFunc(pos *Position, name *Identifier, typ *FuncType, body *Block, distFree bool, format Format) *Func
NewFunc returns a new Func node.
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.
Macro bool // indicates whether it is declared as macro.
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 NewFuncType(pos *Position, macro bool, parameters []*Parameter, result []*Parameter, isVariadic bool) *FuncType
NewFuncType returns a new FuncType node.
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.
type Goto ¶
type Goto struct {
*Position // position in the source.
Label *Identifier // label.
}
Goto node represents a "goto" statement.
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
NewIdentifier returns a new Identifier node.
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
String returns the string representation of n.
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 an "if" statement.
type Import ¶
type Import struct {
*Position // position in the source.
Ident *Identifier // name (including "." and "_") or nil.
Path string // path to import.
For []*Identifier // exported identifiers that are enable for access.
Tree *Tree // expanded tree of import.
}
Import node represents a "import" declaration.
func NewImport ¶
func NewImport(pos *Position, ident *Identifier, path string, forIdents []*Identifier) *Import
NewImport returns a new Import node.
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
NewIndex returns a new Index node.
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 ¶
NewInterface returns a new Interface node.
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
LiteralType represents the type of a literal.
const ( StringLiteral LiteralType = iota RuneLiteral IntLiteral FloatLiteral ImaginaryLiteral )
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
NewMapType returns a new MapType node.
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 // position in the original source
}
Node is a node of the tree.
type Operator ¶
type Operator interface {
Expression
Operator() OperatorType
Precedence() int
}
Operator represents an operator expression. It is implemented by the UnaryOperator and BinaryOperator nodes.
type OperatorType ¶
type OperatorType int
OperatorType represents an operator type in a 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 // * OperatorExtendedAnd // and OperatorExtendedOr // or OperatorExtendedNot // not )
Operators.
func (OperatorType) String ¶
func (op OperatorType) String() string
String returns the string representation of the operator type.
type Package ¶
type Package struct {
*Position
Name string // name.
Declarations []Node
IR struct {
// IteaNameToVarIdents maps the name of the transformed 'itea'
// identifier to the identifiers on the left side of a 'var'
// declarations with an 'using' statement at package level.
//
// For example a package containing this declaration:
//
// {% var V1, V2 = $itea2, len($itea2) using %} ... {% end using %}
//
// will have a mapping in the form:
//
// "$itea2" => [V1, V2]
//
IteaNameToVarIdents map[string][]*Identifier
}
}
Package node represents a package.
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
NewParameter returns a new Parameter node.
type Placeholder ¶
type Placeholder struct {
*Position // position in the source.
// contains filtered or unexported fields
}
Placeholder node represents a special placeholder node.
func NewPlaceholder ¶
func NewPlaceholder() *Placeholder
NewPlaceholder returns a new Placeholder node.
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
String returns the string representation of n.
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 Raw ¶
type Raw struct {
*Position // position in the source.
Marker string // marker.
Tag string // tag.
Text *Text // text.
}
Raw node represents a "raw" statement.
type Render ¶
type Render struct {
*Position // position in the source.
Path string // path of the file to render.
Tree *Tree // expanded tree of <path>.
// IR holds the internal representation. The type checker transforms the
// 'render' expression into a macro call, where the macro body is the
// rendered file.
IR struct {
// Import is the 'import' declaration that imports the dummy file
// declaring the dummy macro.
Import *Import
// Call is the call to the dummy macro.
Call *Call
}
// contains filtered or unexported fields
}
Render node represents a "render <path>" expression.
func (*Render) Parenthesis ¶
func (e *Render) Parenthesis() int
Parenthesis returns the number of parenthesis around the expression.
func (*Render) SetParenthesis ¶
func (e *Render) SetParenthesis(n int)
SetParenthesis sets the number of parenthesis around the expression.
type Return ¶
type Return struct {
*Position
Values []Expression // return values.
}
Return node represents a "return" statement.
type Select ¶
type Select struct {
*Position
LeadingText *Text
Cases []*SelectCase
}
Select node represents a "select" statement.
type SelectCase ¶
SelectCase represents a "case" statement 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
NewSelector returns a new Selector node.
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
NewSend returns a new Send node.
type Show ¶
type Show struct {
*Position // position in the source.
Expressions []Expression // expressions that once evaluated return the values to show.
Context Context // context.
}
Show node represents the "show <expr>" statement and its short syntax "{{ ... }}".
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
NewSliceType returns a new SliceType node.
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
NewSlicing returns a new Slicing node.
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 ¶
Statements node represents a "{%% ... %%} statement.
func NewStatements ¶
func NewStatements(pos *Position, nodes []Node) *Statements
NewStatements returns a new Statements node.
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
String returns the string representation of n.
type Switch ¶
type Switch struct {
*Position
Init Node
Expr Expression
LeadingText *Text
Cases []*Case
}
Switch node represents a "switch" statement.
type Text ¶
Text node represents a text in a template source.
type Tree ¶
type Tree struct {
*Position
Path string // path of the tree.
Nodes []Node // nodes of the first level of the tree.
Format Format // content format.
}
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
NewTypeAssertion returns a new TypeAssertion node.
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
String returns the string representation of n.
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
String returns the string representation of n.
type TypeSwitch ¶
type TypeSwitch struct {
*Position
Init Node
Assignment *Assignment
LeadingText *Text
Cases []*Case
}
TypeSwitch node represents a "switch" statement 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.
}
URL node represents a URL in an attribute value or Markdown. "show" nodes that are children of a 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
NewUnaryOperator returns a new UnaryOperator node.
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
String returns the string representation of n.
type Upvar ¶
type Upvar struct {
// NativePkg is the name of the native package which holds a native Upvar.
// If Upvar is not a native Upvar then NativeName is an empty string.
NativePkg string
// NativeName is the name of the native declaration of a native Upvar. If
// Upvar is not a native Upvar then NativeName is an empty string.
NativeName string
// NativeValue is the value of the native variable Upvar. If Upvar is not
// native then Upvar is nil.
NativeValue *reflect.Value
// NativeValueType, in case of Upvar refers to a native variable, contains
// the type of such variable. If not then NativeValueType is nil.
//
// NativeValueType is necessary because the type cannot be stored into
// the NativeValue, as if the upvar is not initialized in the compiler
// then NativeValue contains an invalid reflect.Value.
NativeValueType reflect.Type
// Declaration is the ast node where Upvar is defined. If Upvar is a
// native var then Declaration is nil.
Declaration Node
}
Upvar represents a variable defined outside function body. Even package level variables (native or not) are considered upvars.
type Using ¶
type Using struct {
*Position // position in the source.
Statement Node // statement preceding the using statement.
Type Expression // type, can be a format identifier or a macro.
Body *Block // body.
Format Format // using content format.
}
Using node represents a "using" statement.
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 represents a "var" declaration.
func NewVar ¶
func NewVar(pos *Position, lhs []*Identifier, typ Expression, rhs []Expression) *Var
NewVar returns a new Var node.