ast

package
v0.57.1 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2024 License: BSD-3-Clause Imports: 4 Imported by: 0

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

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.

func (*ArrayType) String

func (n *ArrayType) String() string

String returns the string representation of n.

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

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.

func (*Block) String added in v0.54.0

func (n *Block) String() string

String returns the string representation of n.

type Break

type Break struct {
	*Position             // position in the source.
	Label     *Identifier // label.
}

Break node represents a "break" statement.

func NewBreak

func NewBreak(pos *Position, label *Identifier) *Break

NewBreak returns a new Break node.

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.

func (*Call) String

func (n *Call) String() string

String returns the string representation of n.

type Case

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

Case node represents "case" and "default" statements.

func NewCase

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

NewCase returns a new Case node.

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.

func (*ChanType) String

func (n *ChanType) String() string

String returns the string representation of n.

type Comment

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

Comment node represents a comment statement in the form {# ... #}.

func NewComment

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

NewComment returns a new Comment node.

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.

const (
	ContextText Context = iota
	ContextHTML
	ContextCSS
	ContextJS
	ContextJSON
	ContextMarkdown
	ContextTag
	ContextQuotedAttr
	ContextUnquotedAttr
	ContextCSSString
	ContextJSString
	ContextJSONString
	ContextTabCodeBlock
	ContextSpacesCodeBlock
)

func (Context) String

func (ctx Context) String() string

String returns the name of the context.

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

type Cut struct {
	Left  int
	Right int
}

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.

func (*Default) String

func (n *Default) String() string

String returns the string representation of n.

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

NewDefer returns a new Defer node.

func (*Defer) String

func (n *Defer) String() string

String returns the string representation of n.

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.
	Format    Format // format.
	Tree      *Tree  // expanded tree of extends.
}

Extends node represents an "extends" declaration.

func NewExtends

func NewExtends(pos *Position, path string, format Format) *Extends

NewExtends returns a new Extends node.

func (*Extends) String

func (n *Extends) String() string

String returns the string representation of n.

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.

func (*Field) String

func (n *Field) String() string

String returns the string representation of n.

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.

func NewFor

func NewFor(pos *Position, init Node, condition Expression, post Node, body []Node) *For

NewFor returns a new For node.

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 Format

type Format int

A Format represents a content format.

const (
	FormatText Format = iota
	FormatHTML
	FormatCSS
	FormatJS
	FormatJSON
	FormatMarkdown
)

Formats.

func (Format) String

func (format Format) String() string

String returns the name of the format.

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.

func (*Func) String

func (n *Func) String() string

String returns the string representation of n.

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.

func (*FuncType) String

func (n *FuncType) String() string

String returns the string representation of n.

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

NewGo returns a new Go node.

func (*Go) String

func (n *Go) String() string

String returns the string representation of n.

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

NewGoto returns a new Goto node.

func (*Goto) String

func (n *Goto) String() string

String returns the string representation of n.

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.

func NewIf

func NewIf(pos *Position, init Node, cond Expression, then *Block, els Node) *If

NewIf returns a new If node.

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.

func (*Import) String

func (n *Import) String() string

String returns the string representation of n.

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.

func (*Index) String

func (n *Index) String() string

String returns the string representation of n.

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

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.

func (*Interface) String

func (n *Interface) String() string

String returns the string representation of n.

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

String returns the string representation of kv.

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

NewLabel returns a new Label node.

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.

func (*MapType) String

func (n *MapType) String() string

String returns the string representation of n.

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.

func NewPackage

func NewPackage(pos *Position, name string, nodes []Node) *Package

NewPackage returns a new Package node.

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.

func (*Parameter) String

func (n *Parameter) String() string

String returns the string representation of n.

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.

func (*Position) Pos

func (p *Position) Pos() *Position

Pos returns the position p.

func (Position) String

func (p Position) String() string

String returns the line and column separated by a colon, for example "37:18".

func (*Position) WithEnd

func (p *Position) WithEnd(end int) *Position

WithEnd returns a copy of the position but with the given end index.

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.

func NewRaw

func NewRaw(pos *Position, marker, tag string, text *Text) *Raw

NewRaw returns a new Raw node.

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 NewRender

func NewRender(pos *Position, path string) *Render

NewRender returns a new Render node.

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.

func (*Render) String

func (n *Render) String() string

String returns the string representation of n.

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

NewReturn returns a new Return node.

type Select

type Select struct {
	*Position
	LeadingText *Text
	Cases       []*SelectCase
}

Select node represents a "select" statement.

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
}

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.

func (*Selector) String

func (n *Selector) String() string

String returns the string representation of n.

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.

func (*Send) String

func (n *Send) String() string

String returns the string representation of n.

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 "{{ ... }}".

func NewShow

func NewShow(pos *Position, expressions []Expression, ctx Context) *Show

NewShow returns a new Show node.

func (*Show) String

func (n *Show) String() string

String returns the string representation of n.

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.

func (*SliceType) String

func (n *SliceType) String() string

String returns the string representation of n.

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.

func (*Slicing) String

func (n *Slicing) String() string

String returns the string representation of n.

type Statements

type Statements struct {
	*Position
	Nodes []Node // nodes.
}

Statements node represents a "{%% ... %%} statement.

func NewStatements

func NewStatements(pos *Position, nodes []Node) *Statements

NewStatements returns a new Statements node.

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

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.

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 a template source.

func NewText

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

NewText returns a new Text node.

func (*Text) String

func (n *Text) String() string

String returns the string representation of n.

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.

func NewTree

func NewTree(path string, nodes []Node, format Format) *Tree

NewTree returns a new Tree node.

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.

func NewURL

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

NewURL returns a new URL node.

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.

func NewUsing

func NewUsing(pos *Position, stmt Node, typ Expression, body *Block, format Format) *Using

NewUsing returns a new Using node.

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.

func (*Var) String

func (n *Var) String() string

String returns the string representation of n.

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