ast

package
v0.0.0-...-3b5741d Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2021 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidTokenType  = xerrors.New("invalid token type")
	ErrInvalidAnchorName = xerrors.New("invalid anchor name")
	ErrInvalidAliasName  = xerrors.New("invalid alias name")
)

Functions

func Dump

func Dump(w io.Writer, n Node) error

Dump prints a textual representation of the tree rooted at n to the given writer.

func DumpTemplate

func DumpTemplate(w io.Writer, n TemplateNode) error

DumpTemplate prints a textual representation of the tree rooted at n to the given writer.

func Merge

func Merge(dst Node, src Node) error

Merge merge document, map, sequence node.

func Walk

func Walk(v Visitor, node Node)

Walk traverses an AST in depth-first order: It starts by calling v.Visit(node); node must not be nil. If the visitor w returned by v.Visit(node) is not nil, Walk is invoked recursively with visitor w for each of the non-nil children of node, followed by a call of w.Visit(nil).

func WalkTemplate

func WalkTemplate(v TemplateVisitor, node TemplateNode)

WalkTemplate traverses a template AST in depth-first order: It starts by calling v.VisitTemplate(node); node must not be nil. If the visitor w returned by v.VisitTemplate(node) is not nil, WalkTemplate is invoked recursively with visitor w for each of the non-nil children of node, followed by a call of w.VisitTemplate(nil).

Types

type ActionNode

type ActionNode struct {
	*BaseNode
	Token *token.Token
	Pipe  *PipeNode // The pipeline in the action.
}

ActionNode holds an action (something bounded by delimiters). Control actions have their own nodes; ActionNode represents simple ones such as field evaluations and parenthesized pipelines.

func Action

func Action(tk *token.Token, pipe *PipeNode) *ActionNode

func (*ActionNode) AddColumn

func (a *ActionNode) AddColumn(col int)

AddColumn add column number to child nodes recursively

func (*ActionNode) GetToken

func (a *ActionNode) GetToken() *token.Token

GetToken returns token instance

func (*ActionNode) Read

func (a *ActionNode) Read(p []byte) (int, error)

func (*ActionNode) String

func (a *ActionNode) String() string

func (*ActionNode) Type

func (a *ActionNode) Type() NodeType

func (*ActionNode) WriteTo

func (a *ActionNode) WriteTo(sb *strings.Builder)

type AliasNode

type AliasNode struct {
	*BaseNode
	Start *token.Token
	Value Node
}

AliasNode type of alias node

func Alias

func Alias(tk *token.Token) *AliasNode

func (*AliasNode) AddColumn

func (n *AliasNode) AddColumn(col int)

AddColumn add column number to child nodes recursively

func (*AliasNode) GetToken

func (n *AliasNode) GetToken() *token.Token

GetToken returns token instance

func (*AliasNode) Read

func (n *AliasNode) Read(p []byte) (int, error)

Read implements (io.Reader).Read

func (*AliasNode) SetName

func (n *AliasNode) SetName(name string) error

func (*AliasNode) String

func (n *AliasNode) String() string

String alias to text

func (*AliasNode) Type

func (n *AliasNode) Type() NodeType

Type returns AliasType

type AnchorNode

type AnchorNode struct {
	*BaseNode
	Start *token.Token
	Name  Node
	Value Node
}

AnchorNode type of anchor node

func Anchor

func Anchor(tk *token.Token) *AnchorNode

func (*AnchorNode) AddColumn

func (n *AnchorNode) AddColumn(col int)

AddColumn add column number to child nodes recursively

func (*AnchorNode) GetToken

func (n *AnchorNode) GetToken() *token.Token

GetToken returns token instance

func (*AnchorNode) Read

func (n *AnchorNode) Read(p []byte) (int, error)

Read implements (io.Reader).Read

func (*AnchorNode) SetName

func (n *AnchorNode) SetName(name string) error

func (*AnchorNode) String

func (n *AnchorNode) String() string

String anchor to text

func (*AnchorNode) Type

func (n *AnchorNode) Type() NodeType

Type returns AnchorType

type ArrayNode

type ArrayNode interface {
	ArrayRange() *ArrayNodeIter
}

ArrayNode interface of SequenceNode

type ArrayNodeIter

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

ArrayNodeIter is an iterator for ranging over a ArrayNode

func (*ArrayNodeIter) Len

func (m *ArrayNodeIter) Len() int

Len returns length of array

func (*ArrayNodeIter) Next

func (m *ArrayNodeIter) Next() bool

Next advances the array iterator and reports whether there is another entry. It returns false when the iterator is exhausted.

func (*ArrayNodeIter) Value

func (m *ArrayNodeIter) Value() Node

Value returns the value of the iterator's current array entry.

type BaseNode

type BaseNode struct {
	Comment *token.Token
	// contains filtered or unexported fields
}

func (*BaseNode) GetComment

func (n *BaseNode) GetComment() *token.Token

GetComment returns comment token instance

func (*BaseNode) SetComment

func (n *BaseNode) SetComment(tk *token.Token) error

SetComment set comment token

type BoolNode

type BoolNode struct {
	*BaseNode
	Token *token.Token
	Value bool
}

BoolNode type of boolean node

func (*BoolNode) AddColumn

func (n *BoolNode) AddColumn(col int)

AddColumn add column number to child nodes recursively

func (*BoolNode) GetToken

func (n *BoolNode) GetToken() *token.Token

GetToken returns token instance

func (*BoolNode) GetValue

func (n *BoolNode) GetValue() interface{}

GetValue returns boolean value

func (*BoolNode) Read

func (n *BoolNode) Read(p []byte) (int, error)

Read implements (io.Reader).Read

func (*BoolNode) String

func (n *BoolNode) String() string

String boolean to text

func (*BoolNode) Type

func (n *BoolNode) Type() NodeType

Type returns BoolType

type BranchNode

type BranchNode struct {
	*BaseNode

	Token *token.Token

	Pipe     *PipeNode // The pipeline to be evaluated.
	List     *NodeList // What to execute if the value is non-empty.
	ElseList *NodeList // What to execute if the value is empty (nil if absent).
	// contains filtered or unexported fields
}

BranchNode is the common representation of if, range, and with.

func (*BranchNode) AddColumn

func (b *BranchNode) AddColumn(col int)

AddColumn add column number to child nodes recursively

func (*BranchNode) GetToken

func (b *BranchNode) GetToken() *token.Token

GetToken returns token instance

func (*BranchNode) Read

func (b *BranchNode) Read(p []byte) (int, error)

func (*BranchNode) String

func (b *BranchNode) String() string

func (*BranchNode) Type

func (b *BranchNode) Type() NodeType

func (*BranchNode) WriteTo

func (b *BranchNode) WriteTo(sb *strings.Builder)

type ChainNode

type ChainNode struct {
	Node  TemplateNode
	Field []string // The identifiers in lexical order.
}

ChainNode holds a term followed by a chain of field accesses (identifier starting with '.'). The names may be chained ('.x.y'). The periods are dropped from each ident.

func Chain

func Chain(node TemplateNode) *ChainNode

func (*ChainNode) Add

func (c *ChainNode) Add(field string)

Add adds the named field (which should start with a period) to the end of the chain.

func (*ChainNode) String

func (c *ChainNode) String() string

func (*ChainNode) Type

func (l *ChainNode) Type() TemplateNodeType

func (*ChainNode) WriteTo

func (c *ChainNode) WriteTo(sb *strings.Builder)

type CommandNode

type CommandNode struct {
	Args []TemplateNode // Arguments in lexical order: Identifier, field, or constant.
}

CommandNode holds a command (a pipeline inside an evaluating action).

func Command

func Command(args ...TemplateNode) *CommandNode

func (*CommandNode) Append

func (c *CommandNode) Append(arg TemplateNode)

func (*CommandNode) String

func (c *CommandNode) String() string

func (*CommandNode) Type

func (l *CommandNode) Type() TemplateNodeType

func (*CommandNode) WriteTo

func (c *CommandNode) WriteTo(sb *strings.Builder)

type CommentNode

type CommentNode struct {
	*BaseNode
}

CommentNode type of comment node

func Comment

func Comment(tk *token.Token) *CommentNode

Comment create node for comment

func (*CommentNode) AddColumn

func (n *CommentNode) AddColumn(col int)

AddColumn add column number to child nodes recursively

func (*CommentNode) GetToken

func (n *CommentNode) GetToken() *token.Token

GetToken returns token instance

func (*CommentNode) Read

func (n *CommentNode) Read(p []byte) (int, error)

Read implements (io.Reader).Read

func (*CommentNode) String

func (n *CommentNode) String() string

String comment to text

func (*CommentNode) Type

func (n *CommentNode) Type() NodeType

Type returns TagType

type DirectiveNode

type DirectiveNode struct {
	*BaseNode
	Start *token.Token
	Value Node
}

DirectiveNode type of directive node

func Directive

func Directive(tk *token.Token) *DirectiveNode

func (*DirectiveNode) AddColumn

func (n *DirectiveNode) AddColumn(col int)

AddColumn add column number to child nodes recursively

func (*DirectiveNode) GetToken

func (n *DirectiveNode) GetToken() *token.Token

GetToken returns token instance

func (*DirectiveNode) Read

func (n *DirectiveNode) Read(p []byte) (int, error)

Read implements (io.Reader).Read

func (*DirectiveNode) String

func (n *DirectiveNode) String() string

String directive to text

func (*DirectiveNode) Type

func (n *DirectiveNode) Type() NodeType

Type returns DirectiveType

type DocumentNode

type DocumentNode struct {
	*BaseNode
	Start *token.Token // position of DocumentHeader ( `---` )
	End   *token.Token // position of DocumentEnd ( `...` )
	Body  Node
}

DocumentNode type of Document

func Document

func Document(tk *token.Token, body Node) *DocumentNode

func (*DocumentNode) AddColumn

func (d *DocumentNode) AddColumn(col int)

AddColumn add column number to child nodes recursively

func (*DocumentNode) GetToken

func (d *DocumentNode) GetToken() *token.Token

GetToken returns token instance

func (*DocumentNode) Read

func (d *DocumentNode) Read(p []byte) (int, error)

Read implements (io.Reader).Read

func (*DocumentNode) String

func (d *DocumentNode) String() string

String document to text

func (*DocumentNode) Type

func (d *DocumentNode) Type() NodeType

Type returns DocumentNodeType

type DotNode

type DotNode struct {
}

DotNode holds the special identifier '.'.

func Dot

func Dot() *DotNode

func (*DotNode) String

func (d *DotNode) String() string

func (*DotNode) Type

func (d *DotNode) Type() TemplateNodeType

func (*DotNode) WriteTo

func (d *DotNode) WriteTo(sb *strings.Builder)

type ErrInvalidMergeType

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

func (*ErrInvalidMergeType) Error

func (e *ErrInvalidMergeType) Error() string

type FieldNode

type FieldNode struct {
	Ident []string // The identifiers in lexical order.
}

FieldNode holds a field (identifier starting with '.'). The names may be chained ('.x.y'). The period is dropped from each ident.

func Field

func Field(ident string) *FieldNode

func (*FieldNode) String

func (f *FieldNode) String() string

func (*FieldNode) Type

func (l *FieldNode) Type() TemplateNodeType

func (*FieldNode) WriteTo

func (f *FieldNode) WriteTo(sb *strings.Builder)

type File

type File struct {
	Name string
	Docs []*DocumentNode
}

File contains all documents in YAML file

func (*File) Read

func (f *File) Read(p []byte) (int, error)

Read implements (io.Reader).Read

func (*File) String

func (f *File) String() string

String all documents to text

type FloatNode

type FloatNode struct {
	*BaseNode
	Token     *token.Token
	Precision int
	Value     float64
}

FloatNode type of float node

func (*FloatNode) AddColumn

func (n *FloatNode) AddColumn(col int)

AddColumn add column number to child nodes recursively

func (*FloatNode) GetToken

func (n *FloatNode) GetToken() *token.Token

GetToken returns token instance

func (*FloatNode) GetValue

func (n *FloatNode) GetValue() interface{}

GetValue returns float64 value

func (*FloatNode) Read

func (n *FloatNode) Read(p []byte) (int, error)

Read implements (io.Reader).Read

func (*FloatNode) String

func (n *FloatNode) String() string

String float64 to text

func (*FloatNode) Type

func (n *FloatNode) Type() NodeType

Type returns FloatType

type IdentifierNode

type IdentifierNode struct {
	Ident string // The identifier's name.
}

IdentifierNode holds an identifier.

func Identifier

func Identifier(ident string) *IdentifierNode

func (*IdentifierNode) String

func (i *IdentifierNode) String() string

func (*IdentifierNode) Type

func (l *IdentifierNode) Type() TemplateNodeType

func (*IdentifierNode) WriteTo

func (i *IdentifierNode) WriteTo(sb *strings.Builder)

type IfNode

type IfNode struct {
	BranchNode
}

IfNode represents an {{if}} action and its commands.

func If

func If(tk *token.Token, pipe *PipeNode, list *NodeList, elseList *NodeList) *IfNode

type InfinityNode

type InfinityNode struct {
	*BaseNode
	Token *token.Token
	Value float64
}

InfinityNode type of infinity node

func Infinity

func Infinity(tk *token.Token) *InfinityNode

Infinity create node for .inf or -.inf value

func (*InfinityNode) AddColumn

func (n *InfinityNode) AddColumn(col int)

AddColumn add column number to child nodes recursively

func (*InfinityNode) GetToken

func (n *InfinityNode) GetToken() *token.Token

GetToken returns token instance

func (*InfinityNode) GetValue

func (n *InfinityNode) GetValue() interface{}

GetValue returns math.Inf(0) or math.Inf(-1)

func (*InfinityNode) Read

func (n *InfinityNode) Read(p []byte) (int, error)

Read implements (io.Reader).Read

func (*InfinityNode) String

func (n *InfinityNode) String() string

String infinity to text

func (*InfinityNode) Type

func (n *InfinityNode) Type() NodeType

Type returns InfinityType

type IntegerNode

type IntegerNode struct {
	*BaseNode
	Token *token.Token
	Value interface{} // int64 or uint64 value
}

IntegerNode type of integer node

func (*IntegerNode) AddColumn

func (n *IntegerNode) AddColumn(col int)

AddColumn add column number to child nodes recursively

func (*IntegerNode) GetToken

func (n *IntegerNode) GetToken() *token.Token

GetToken returns token instance

func (*IntegerNode) GetValue

func (n *IntegerNode) GetValue() interface{}

GetValue returns int64 value

func (*IntegerNode) Read

func (n *IntegerNode) Read(p []byte) (int, error)

Read implements (io.Reader).Read

func (*IntegerNode) String

func (n *IntegerNode) String() string

String int64 to text

func (*IntegerNode) Type

func (n *IntegerNode) Type() NodeType

Type returns IntegerType

type LiteralNode

type LiteralNode struct {
	*BaseNode
	Start *token.Token
	Value *StringNode
}

LiteralNode type of literal node

func Literal

func Literal(tk *token.Token) *LiteralNode

func (*LiteralNode) AddColumn

func (n *LiteralNode) AddColumn(col int)

AddColumn add column number to child nodes recursively

func (*LiteralNode) GetToken

func (n *LiteralNode) GetToken() *token.Token

GetToken returns token instance

func (*LiteralNode) GetValue

func (n *LiteralNode) GetValue() interface{}

GetValue returns string value

func (*LiteralNode) Read

func (n *LiteralNode) Read(p []byte) (int, error)

Read implements (io.Reader).Read

func (*LiteralNode) String

func (n *LiteralNode) String() string

String literal to text

func (*LiteralNode) Type

func (n *LiteralNode) Type() NodeType

Type returns LiteralType

type MapNode

type MapNode interface {
	MapRange() *MapNodeIter
}

MapNode interface of MappingValueNode / MappingNode

type MapNodeIter

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

MapNodeIter is an iterator for ranging over a MapNode

func (*MapNodeIter) Key

func (m *MapNodeIter) Key() Node

Key returns the key of the iterator's current map node entry.

func (*MapNodeIter) Next

func (m *MapNodeIter) Next() bool

Next advances the map iterator and reports whether there is another entry. It returns false when the iterator is exhausted.

func (*MapNodeIter) Value

func (m *MapNodeIter) Value() Node

Value returns the value of the iterator's current map node entry.

type MappingKeyNode

type MappingKeyNode struct {
	*BaseNode
	Start *token.Token
	Value Node
}

MappingKeyNode type of tag node

func MappingKey

func MappingKey(tk *token.Token) *MappingKeyNode

MappingKey create node for map key ( '?' ).

func (*MappingKeyNode) AddColumn

func (n *MappingKeyNode) AddColumn(col int)

AddColumn add column number to child nodes recursively

func (*MappingKeyNode) GetToken

func (n *MappingKeyNode) GetToken() *token.Token

GetToken returns token instance

func (*MappingKeyNode) Read

func (n *MappingKeyNode) Read(p []byte) (int, error)

Read implements (io.Reader).Read

func (*MappingKeyNode) String

func (n *MappingKeyNode) String() string

String tag to text

func (*MappingKeyNode) Type

func (n *MappingKeyNode) Type() NodeType

Type returns MappingKeyType

type MappingNode

type MappingNode struct {
	*BaseNode
	Start       *token.Token
	End         *token.Token
	IsFlowStyle bool
	Values      []*MappingValueNode
}

MappingNode type of mapping node

func Mapping

func Mapping(tk *token.Token, isFlowStyle bool, values ...*MappingValueNode) *MappingNode

Mapping create node for map

func (*MappingNode) AddColumn

func (n *MappingNode) AddColumn(col int)

AddColumn add column number to child nodes recursively

func (*MappingNode) GetToken

func (n *MappingNode) GetToken() *token.Token

GetToken returns token instance

func (*MappingNode) MapRange

func (n *MappingNode) MapRange() *MapNodeIter

MapRange implements MapNode protocol

func (*MappingNode) Merge

func (n *MappingNode) Merge(target *MappingNode)

Merge merge key/value of map.

func (*MappingNode) Read

func (n *MappingNode) Read(p []byte) (int, error)

Read implements (io.Reader).Read

func (*MappingNode) SetIsFlowStyle

func (n *MappingNode) SetIsFlowStyle(isFlow bool)

SetIsFlowStyle set value to IsFlowStyle field recursively.

func (*MappingNode) String

func (n *MappingNode) String() string

String mapping values to text

func (*MappingNode) Type

func (n *MappingNode) Type() NodeType

Type returns MappingType

type MappingValueNode

type MappingValueNode struct {
	*BaseNode
	Start    *token.Token
	Template Node
	Key      Node
	Value    Node
}

MappingValueNode type of mapping value

func MappingTemplate

func MappingTemplate(tk *token.Token, template Node) *MappingValueNode

MappingTemplate creates a node for a mapping value that is a template

func MappingValue

func MappingValue(tk *token.Token, key Node, value Node) *MappingValueNode

MappingValue create node for mapping value

func (*MappingValueNode) AddColumn

func (n *MappingValueNode) AddColumn(col int)

AddColumn add column number to child nodes recursively

func (*MappingValueNode) GetToken

func (n *MappingValueNode) GetToken() *token.Token

GetToken returns token instance

func (*MappingValueNode) MapRange

func (n *MappingValueNode) MapRange() *MapNodeIter

MapRange implements MapNode protocol

func (*MappingValueNode) Read

func (n *MappingValueNode) Read(p []byte) (int, error)

Read implements (io.Reader).Read

func (*MappingValueNode) Replace

func (n *MappingValueNode) Replace(value Node) error

Replace replace value node.

func (*MappingValueNode) SetIsFlowStyle

func (n *MappingValueNode) SetIsFlowStyle(isFlow bool)

SetIsFlowStyle set value to IsFlowStyle field recursively.

func (*MappingValueNode) String

func (n *MappingValueNode) String() string

String mapping value to text

func (*MappingValueNode) Type

func (n *MappingValueNode) Type() NodeType

Type returns MappingValueType

type MergeKeyNode

type MergeKeyNode struct {
	*BaseNode
	Token *token.Token
}

MergeKeyNode type of merge key node

func MergeKey

func MergeKey(tk *token.Token) *MergeKeyNode

MergeKey create node for merge key ( << )

func (*MergeKeyNode) AddColumn

func (n *MergeKeyNode) AddColumn(col int)

AddColumn add column number to child nodes recursively

func (*MergeKeyNode) GetToken

func (n *MergeKeyNode) GetToken() *token.Token

GetToken returns token instance

func (*MergeKeyNode) GetValue

func (n *MergeKeyNode) GetValue() interface{}

GetValue returns '<<' value

func (*MergeKeyNode) Read

func (n *MergeKeyNode) Read(p []byte) (int, error)

Read implements (io.Reader).Read

func (*MergeKeyNode) String

func (n *MergeKeyNode) String() string

String returns '<<' value

func (*MergeKeyNode) Type

func (n *MergeKeyNode) Type() NodeType

Type returns MergeKeyType

type NanNode

type NanNode struct {
	*BaseNode
	Token *token.Token
}

NanNode type of nan node

func Nan

func Nan(tk *token.Token) *NanNode

Nan create node for .nan value

func (*NanNode) AddColumn

func (n *NanNode) AddColumn(col int)

AddColumn add column number to child nodes recursively

func (*NanNode) GetToken

func (n *NanNode) GetToken() *token.Token

GetToken returns token instance

func (*NanNode) GetValue

func (n *NanNode) GetValue() interface{}

GetValue returns math.NaN()

func (*NanNode) Read

func (n *NanNode) Read(p []byte) (int, error)

Read implements (io.Reader).Read

func (*NanNode) String

func (n *NanNode) String() string

String returns .nan

func (*NanNode) Type

func (n *NanNode) Type() NodeType

Type returns NanType

type NilNode

type NilNode struct {
}

NilNode holds the special identifier 'nil' representing an untyped nil constant.

func Nil

func Nil() *NilNode

func (*NilNode) String

func (n *NilNode) String() string

func (*NilNode) Type

func (n *NilNode) Type() TemplateNodeType

func (*NilNode) WriteTo

func (n *NilNode) WriteTo(sb *strings.Builder)

type Node

type Node interface {
	io.Reader
	// String node to text
	String() string
	// GetToken returns token instance
	GetToken() *token.Token
	// Type returns type of node
	Type() NodeType
	// AddColumn add column number to child nodes recursively
	AddColumn(int)
	// SetComment set comment token to node
	SetComment(*token.Token) error
	// Comment returns comment token instance
	GetComment() *token.Token
	// contains filtered or unexported methods
}

Node type of node

func Bool

func Bool(tk *token.Token) Node

Bool create node for boolean value

func Filter

func Filter(typ NodeType, node Node) []Node

Filter returns a list of nodes that match the given type.

func FilterFile

func FilterFile(typ NodeType, file *File) []Node

FilterFile returns a list of nodes that match the given type.

func Float

func Float(tk *token.Token) Node

Float create node for float value

func Integer

func Integer(tk *token.Token) Node

Integer create node for integer value

func Null

func Null(tk *token.Token) Node

Null create node for null value

type NodeList

type NodeList struct {
	Nodes []Node // The element nodes in lexical order.
}

NodeList holds a sequence of nodes.

func List

func List(nodes ...Node) *NodeList

func (*NodeList) AddColumn

func (l *NodeList) AddColumn(col int)

AddColumn add column number to child nodes recursively

func (*NodeList) Append

func (l *NodeList) Append(n Node)

func (*NodeList) String

func (l *NodeList) String() string

func (*NodeList) WriteTo

func (l *NodeList) WriteTo(sb *strings.Builder)

type NodeType

type NodeType int

NodeType type identifier of node

const (
	// UnknownNodeType type identifier for default
	UnknownNodeType NodeType = iota
	// DocumentType type identifier for document node
	DocumentType
	// NullType type identifier for null node
	NullType
	// BoolType type identifier for boolean node
	BoolType
	// IntegerType type identifier for integer node
	IntegerType
	// FloatType type identifier for float node
	FloatType
	// InfinityType type identifier for infinity node
	InfinityType
	// NanType type identifier for nan node
	NanType
	// StringType type identifier for string node
	StringType
	// MergeKeyType type identifier for merge key node
	MergeKeyType
	// LiteralType type identifier for literal node
	LiteralType
	// MappingType type identifier for mapping node
	MappingType
	// MappingKeyType type identifier for mapping key node
	MappingKeyType
	// MappingValueType type identifier for mapping value node
	MappingValueType
	// SequenceType type identifier for sequence node
	SequenceType
	// AnchorType type identifier for anchor node
	AnchorType
	// AliasType type identifier for alias node
	AliasType
	// DirectiveType type identifier for directive node
	DirectiveType
	// TagType type identifier for tag node
	TagType
	// CommentType type identifier for comment node
	CommentType
	// ActionType type identifier for action node
	ActionType
	// IfType type identifier for if node
	IfType
	// RangeType type identifier for range node
	RangeType
	// WithType type identifier for with node
	WithType
	// TemplateInvokeType type identifier for template invoke node
	TemplateInvokeType
)

func (NodeType) String

func (t NodeType) String() string

String node type identifier to text

type NullNode

type NullNode struct {
	*BaseNode
	Comment *token.Token // position of Comment ( `#comment` )
	Token   *token.Token
}

NullNode type of null node

func (*NullNode) AddColumn

func (n *NullNode) AddColumn(col int)

AddColumn add column number to child nodes recursively

func (*NullNode) GetToken

func (n *NullNode) GetToken() *token.Token

GetToken returns token instance

func (*NullNode) GetValue

func (n *NullNode) GetValue() interface{}

GetValue returns nil value

func (*NullNode) Read

func (n *NullNode) Read(p []byte) (int, error)

Read implements (io.Reader).Read

func (*NullNode) SetComment

func (n *NullNode) SetComment(tk *token.Token) error

SetComment set comment token

func (*NullNode) String

func (n *NullNode) String() string

String returns `null` text

func (*NullNode) Type

func (n *NullNode) Type() NodeType

Type returns NullType

type PipeNode

type PipeNode struct {
	IsAssign bool            // The variables are being assigned, not declared.
	Decl     []*VariableNode // Variables in lexical order.
	Cmds     []*CommandNode  // The commands in lexical order.
}

PipeNode holds a pipeline with optional declaration

func (*PipeNode) Append

func (p *PipeNode) Append(command *CommandNode)

func (*PipeNode) String

func (p *PipeNode) String() string

func (*PipeNode) Type

func (l *PipeNode) Type() TemplateNodeType

func (*PipeNode) WriteTo

func (p *PipeNode) WriteTo(sb *strings.Builder)

type RangeNode

type RangeNode struct {
	BranchNode
}

RangeNode represents a {{range}} action and its commands.

func Range

func Range(tk *token.Token, pipe *PipeNode, list *NodeList, elseList *NodeList) *RangeNode

type ScalarNode

type ScalarNode interface {
	Node
	GetValue() interface{}
}

ScalarNode type for scalar node

type SequenceNode

type SequenceNode struct {
	*BaseNode
	Start       *token.Token
	End         *token.Token
	IsFlowStyle bool
	Values      []Node
}

SequenceNode type of sequence node

func Sequence

func Sequence(tk *token.Token, isFlowStyle bool) *SequenceNode

Sequence create node for sequence

func (*SequenceNode) AddColumn

func (n *SequenceNode) AddColumn(col int)

AddColumn add column number to child nodes recursively

func (*SequenceNode) ArrayRange

func (n *SequenceNode) ArrayRange() *ArrayNodeIter

ArrayRange implements ArrayNode protocol

func (*SequenceNode) GetToken

func (n *SequenceNode) GetToken() *token.Token

GetToken returns token instance

func (*SequenceNode) Merge

func (n *SequenceNode) Merge(target *SequenceNode)

Merge merge sequence value.

func (*SequenceNode) Read

func (n *SequenceNode) Read(p []byte) (int, error)

Read implements (io.Reader).Read

func (*SequenceNode) Replace

func (n *SequenceNode) Replace(idx int, value Node) error

Replace replace value node.

func (*SequenceNode) SetIsFlowStyle

func (n *SequenceNode) SetIsFlowStyle(isFlow bool)

SetIsFlowStyle set value to IsFlowStyle field recursively.

func (*SequenceNode) String

func (n *SequenceNode) String() string

String sequence to text

func (*SequenceNode) Type

func (n *SequenceNode) Type() NodeType

Type returns SequenceType

type StringNode

type StringNode struct {
	*BaseNode
	Token *token.Token
	Value string
}

StringNode type of string node

func String

func String(tk *token.Token) *StringNode

String create node for string value

func (*StringNode) AddColumn

func (n *StringNode) AddColumn(col int)

AddColumn add column number to child nodes recursively

func (*StringNode) GetToken

func (n *StringNode) GetToken() *token.Token

GetToken returns token instance

func (*StringNode) GetValue

func (n *StringNode) GetValue() interface{}

GetValue returns string value

func (*StringNode) Read

func (n *StringNode) Read(p []byte) (int, error)

Read implements (io.Reader).Read

func (*StringNode) String

func (n *StringNode) String() string

String string value to text with quote or literal header if required

func (*StringNode) Type

func (n *StringNode) Type() NodeType

Type returns StringType

type TagNode

type TagNode struct {
	*BaseNode
	Start *token.Token
	Value Node
}

TagNode type of tag node

func Tag

func Tag(tk *token.Token) *TagNode

func (*TagNode) AddColumn

func (n *TagNode) AddColumn(col int)

AddColumn add column number to child nodes recursively

func (*TagNode) GetToken

func (n *TagNode) GetToken() *token.Token

GetToken returns token instance

func (*TagNode) Read

func (n *TagNode) Read(p []byte) (int, error)

Read implements (io.Reader).Read

func (*TagNode) String

func (n *TagNode) String() string

String tag to text

func (*TagNode) Type

func (n *TagNode) Type() NodeType

Type returns TagType

type TemplateBoolNode

type TemplateBoolNode struct {
	True bool // The value of the boolean constant.
}

TemplateBoolNode holds a boolean constant.

func TemplateBool

func TemplateBool(true bool) *TemplateBoolNode

func (*TemplateBoolNode) String

func (b *TemplateBoolNode) String() string

func (*TemplateBoolNode) Type

func (*TemplateBoolNode) WriteTo

func (b *TemplateBoolNode) WriteTo(sb *strings.Builder)

type TemplateInvokeNode

type TemplateInvokeNode struct {
	*BaseNode
	Token *token.Token
	Name  string    // The name of the template (unquoted).
	Pipe  *PipeNode // The command to evaluate as dot for the template.
}

TemplateInvokeNode represents a {{template}} action.

func TemplateInvoke

func TemplateInvoke(tk *token.Token, name string, pipe *PipeNode) *TemplateInvokeNode

func (*TemplateInvokeNode) AddColumn

func (t *TemplateInvokeNode) AddColumn(col int)

AddColumn add column number to child nodes recursively

func (*TemplateInvokeNode) GetToken

func (t *TemplateInvokeNode) GetToken() *token.Token

GetToken returns token instance

func (*TemplateInvokeNode) Read

func (t *TemplateInvokeNode) Read(p []byte) (int, error)

func (*TemplateInvokeNode) String

func (t *TemplateInvokeNode) String() string

func (*TemplateInvokeNode) Type

func (t *TemplateInvokeNode) Type() NodeType

func (*TemplateInvokeNode) WriteTo

func (t *TemplateInvokeNode) WriteTo(sb *strings.Builder)

type TemplateNode

type TemplateNode interface {
	Type() TemplateNodeType
	String() string
	WriteTo(*strings.Builder)
}

type TemplateNodeType

type TemplateNodeType int

TemplateNodeType identifies the type of a template tree node.

const (
	TemplateNodeBool       TemplateNodeType = iota // A boolean constant.
	TemplateNodeChain                              // A sequence of field accesses.
	TemplateNodeCommand                            // An element of a pipeline.
	TemplateNodeDot                                // The cursor, dot.
	TemplateNodeField                              // A field or method name.
	TemplateNodeIdentifier                         // An identifier; always a function name.
	TemplateNodeNil                                // An untyped nil constant.
	TemplateNodeNumber                             // A numerical constant.
	TemplateNodePipe                               // A pipeline of commands.
	TemplateNodeString                             // A string constant.
	TemplateNodeVariable                           // A $ variable.
)

func (TemplateNodeType) String

func (t TemplateNodeType) String() string

String template node type identifier to text

type TemplateNumberNode

type TemplateNumberNode struct {
	IsInt      bool       // Number has an integral value.
	IsUint     bool       // Number has an unsigned integral value.
	IsFloat    bool       // Number has a floating-point value.
	IsComplex  bool       // Number is complex.
	Int64      int64      // The signed integer value.
	Uint64     uint64     // The unsigned integer value.
	Float64    float64    // The floating-point value.
	Complex128 complex128 // The complex value.
	Text       string     // The original textual representation from the input.
}

TemplateNumberNode holds a number: signed or unsigned integer, float, or complex. The value is parsed and stored under all the types that can represent the value. This simulates in a small amount of code the behavior of Go's ideal constants.

func TemplateNumber

func TemplateNumber(text string) (*TemplateNumberNode, error)

func (*TemplateNumberNode) String

func (n *TemplateNumberNode) String() string

func (*TemplateNumberNode) Type

func (*TemplateNumberNode) WriteTo

func (n *TemplateNumberNode) WriteTo(sb *strings.Builder)

type TemplateStringNode

type TemplateStringNode struct {
	Quoted string // The original text of the string, with quotes.
	Text   string // The string, after quote processing.
}

TemplateStringNode holds a string constant. The value has been "unquoted".

func TemplateString

func TemplateString(orig, text string) *TemplateStringNode

func (*TemplateStringNode) String

func (s *TemplateStringNode) String() string

func (*TemplateStringNode) Type

func (*TemplateStringNode) WriteTo

func (s *TemplateStringNode) WriteTo(sb *strings.Builder)

type TemplateVisitor

type TemplateVisitor interface {
	VisitTemplate(TemplateNode) TemplateVisitor
}

TemplateVisitor has Visit method that is invokded for each node encountered by WalkTemplate. If the result visitor w is not nil, Walk visits each of the children of node with the visitor w, followed by a call of w.Visit(nil).

type VariableNode

type VariableNode struct {
	Ident []string // Variable name and fields in lexical order.
}

VariableNode holds a list of variable names, possibly with chained field accesses. The dollar sign is part of the (first) name.

func Variable

func Variable(ident string) *VariableNode

func (*VariableNode) String

func (v *VariableNode) String() string

func (*VariableNode) Type

func (l *VariableNode) Type() TemplateNodeType

func (*VariableNode) WriteTo

func (v *VariableNode) WriteTo(sb *strings.Builder)

type Visitor

type Visitor interface {
	Visit(Node) Visitor
}

Visitor has Visit method that is invokded for each node encountered by Walk. If the result visitor w is not nil, Walk visits each of the children of node with the visitor w, followed by a call of w.Visit(nil).

type WithNode

type WithNode struct {
	BranchNode
}

WithNode represents a {{with}} action and its commands.

func With

func With(tk *token.Token, pipe *PipeNode, list *NodeList, elseList *NodeList) *WithNode

Jump to

Keyboard shortcuts

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