ast

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2020 License: BSD-3-Clause Imports: 3 Imported by: 0

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

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.

func (*ArrayType) String

func (n *ArrayType) String() string

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 Block

type Block struct {
	*Position
	Nodes []Node
}

Block node represents a block { ... } with his own scope.

func NewBlock

func NewBlock(pos *Position, nodes []Node) *Block

NewBlock returns a new block statement.

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.

func (*Call) String

func (n *Call) String() string

type Case

type Case struct {
	*Position
	Expressions []Expression
	Body        []Node
}

Case node represents a statement {% case ... %} or {% default %}.

func NewCase

func NewCase(pos *Position, expressions []Expression, body []Node) *Case

NewCase returns a new Case node.

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.

func (*ChanType) String

func (n *ChanType) String() string

type Comment

type Comment struct {
	*Position        // position in the source.
	Text      string // comment text.
}

Comment node represents a statement {# ... #}.

func NewComment

func NewComment(pos *Position, text string) *Comment

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.

const (
	ContextText Context = iota
	ContextHTML
	ContextCSS
	ContextJavaScript
	ContextGo // TODO(marco): move in first position.
	ContextTag
	ContextAttribute
	ContextUnquotedAttribute
	ContextCSSString
	ContextJavaScriptString
)

func (Context) String

func (ctx Context) String() string

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

type Cut struct {
	Left  int
	Right int
}

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

func (*Defer) String

func (n *Defer) String() string

type Expression

type Expression interface {
	Parenthesis() int
	SetParenthesis(int)
	Node
	String() string
}

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 ... %}.

func NewExtends

func NewExtends(pos *Position, path string, ctx Context) *Extends

func (*Extends) String

func (n *Extends) String() string

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.

func (*Field) String

func (n *Field) String() string

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 ... %}.

func NewFor

func NewFor(pos *Position, init Node, condition Expression, post Node, body []Node) *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 NewFunc

func NewFunc(pos *Position, name *Identifier, typ *FuncType, body *Block) *Func

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.

func (*Func) String

func (n *Func) String() string

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 NewFuncType(pos *Position, parameters []*Parameter, result []*Parameter, isVariadic bool) *FuncType

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.

func (*FuncType) String

func (n *FuncType) String() string

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

func (*Go) String

func (n *Go) String() string

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

func (*Goto) String

func (n *Goto) String() string

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 ... %}.

func NewIf

func NewIf(pos *Position, init Node, cond Expression, then *Block, els Node) *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 ... %}.

func NewImport

func NewImport(pos *Position, ident *Identifier, path string, ctx Context) *Import

func (*Import) String

func (n *Import) String() string

type Include

type Include struct {
	*Position         // position in the source.
	Path      string  // path of the source to include.
	Context   Context // context.
	Tree      *Tree   // expanded tree of <path>.
}

Include node represents a statement {% include <path> %}.

func NewInclude

func NewInclude(pos *Position, path string, ctx Context) *Include

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.

func (*Index) String

func (n *Index) String() string

type Interface

type Interface struct {
	*Position // position in the source.
	// contains filtered or unexported fields
}

Interface node represents an interface type.

func NewInterface

func NewInterface(pos *Position) *Interface

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.

func (*Interface) String

func (n *Interface) String() string

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.

func (KeyValue) String

func (kv KeyValue) String() string

type Label

type Label struct {
	*Position             // position in the source.
	Ident     *Identifier // identifier.
	Statement Node        // statement.
}

Label node represents a label statement.

func NewLabel

func NewLabel(pos *Position, ident *Identifier, statement Node) *Label

type Language

type Language int

A Language represents a source language.

const (
	LanguageText Language = iota
	LanguageHTML
	LanguageCSS
	LanguageJavaScript
	LanguageGo // TODO(marco): move in first position.
)

func (Language) String

func (lang Language) String() string

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.
	Upvars    []Upvar     // Upvars of macro.
	Context   Context     // context.
}

Macro node represents a statement {% macro ... %}.

func NewMacro

func NewMacro(pos *Position, name *Identifier, typ *FuncType, body []Node, ctx Context) *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.

func (*MapType) String

func (n *MapType) String() string

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                         // >>
	OperatorReceive                            // <-
	OperatorAddress                            // &
	OperatorPointer                            // *
	OperatorRelaxedAnd                         // and
	OperatorRelaxedOr                          // or
	OperatorRelaxedNot                         // not
)

func (OperatorType) String

func (op OperatorType) String() string

type Package

type Package struct {
	*Position
	Name         string // name.
	Declarations []Node
}

Package node represents a package.

func NewPackage

func NewPackage(pos *Position, name string, nodes []Node) *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

func (*Parameter) String

func (n *Parameter) String() string

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.

func (*Position) Pos

func (p *Position) Pos() *Position

func (Position) String

func (p Position) String() string

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 ... %}.

func NewSelect

func NewSelect(pos *Position, leadingText *Text, cases []*SelectCase) *Select

NewSelect returns a new Select node.

type SelectCase

type SelectCase struct {
	*Position
	Comm Node
	Body []Node
}

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.

func (*Selector) String

func (n *Selector) String() string

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

func (*Send) String

func (n *Send) String() string

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 a statement {{ ... }}.

func NewShow

func NewShow(pos *Position, expr Expression, ctx Context) *Show

func (*Show) String

func (n *Show) String() string

type ShowMacro

type ShowMacro struct {
	*Position               // position in the source.
	Macro      Expression   // macro.
	Args       []Expression // arguments.
	IsVariadic bool         // reports whether it is variadic.
	Or         ShowMacroOr  // when macro is not defined.
	Context    Context      // context.
}

ShowMacro node represents a statement {% show <macro> %}.

func NewShowMacro

func NewShowMacro(pos *Position, macro Expression, args []Expression, isVariadic bool, or ShowMacroOr, ctx Context) *ShowMacro

type ShowMacroOr

type ShowMacroOr int8

ShowMacroOr specifies behavior when macro is not defined.

const (
	// ShowMacroOrIgnore ignores if not defined.
	ShowMacroOrIgnore ShowMacroOr = iota
	// ShowMacroOrTodo returns error if compiled with "fail on todo" option.
	ShowMacroOrTodo
	// ShowMacroOrError is the default behavior: returns an error.
	ShowMacroOrError
)

func (ShowMacroOr) String

func (s ShowMacroOr) String() string

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.

func (*SliceType) String

func (n *SliceType) String() string

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.

func (*Slicing) String

func (n *Slicing) String() string

type StructType

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

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 ... %}.

func NewSwitch

func NewSwitch(pos *Position, init Node, expr Expression, leadingText *Text, cases []*Case) *Switch

NewSwitch returns a new Switch node.

type Text

type Text struct {
	*Position        // position in the source.
	Text      []byte // text.
	Cut       Cut    // cut.
}

Text node represents a text in the source.

func NewText

func NewText(pos *Position, text []byte, cut Cut) *Text

func (*Text) String

func (n *Text) String() string

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.

func NewTree

func NewTree(path string, nodes []Node, language Language) *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.

func NewURL

func NewURL(pos *Position, tag, attribute string, value []Node, ctx Context) *URL

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

func (*Var) String

func (n *Var) String() string

Directories

Path Synopsis
Package astutil implements methods to walk and dump a tree.
Package astutil implements methods to walk and dump a tree.

Jump to

Keyboard shortcuts

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