parse

package
v0.0.0-...-c66b129 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2014 License: BSD-3-Clause Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Special items
	ERROR itemType = iota
	EOF
)

The list of items.

View Source
const (
	OTag  = "{{"
	OLen  = 2
	ORune = '{'
	CTag  = "}}"
	CLen  = 2
	CRune = '}'
)

Variables

View Source
var ItemStrings = [...]string{
	ERROR: "ERROR",
	EOF:   "EOF",
	// contains filtered or unexported fields
}

itemStrings provides string descriptions to the item.

View Source
var ItemToNode map[itemType]NodeType // itemTypes to NodeTypes (for ident declarations)
View Source
var NodeStrings map[NodeType]string

NodeStrings gives a string description for the NodeType

Functions

func Collect

func Collect(name, src, left, right string) (items []item)

collect gathers the emitted items into a slice.-- for development

func NewLexerFromString

func NewLexerFromString(name, data string, initState stateFn) *lexer

Returns a new, initialized lexer with the tag defaults set to {{}}.

func PrintCollection

func PrintCollection(items []item)

exposed for dev

Types

type ActionNode

type ActionNode struct {
	NodeType
	Typ itemType
	Pos
	Line int
	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 (*ActionNode) Copy

func (a *ActionNode) Copy() Node

func (*ActionNode) String

func (a *ActionNode) String() string

type BranchNode

type BranchNode struct {
	NodeType
	Pos
	Line     int       // The line number in the input (deprecated; kept for compatibility)
	Pipe     *PipeNode // The pipeline to be evaluated.
	List     *ListNode // What to execute if the value is non-empty.
	ElseList *ListNode // What to execute if the value is empty (nil if absent).
}

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

func (*BranchNode) String

func (b *BranchNode) String() string

type CRNode

type CRNode struct {
	NodeType
	Pos
	Text []byte
}

CRNode holds newline char

func (*CRNode) Copy

func (cr *CRNode) Copy() Node

func (*CRNode) String

func (cr *CRNode) String() string

type CTagNode

type CTagNode struct {
	NodeType
	Pos
	Text []byte
}

CTagNode holds a closing tag

func (*CTagNode) Copy

func (t *CTagNode) Copy() Node

func (*CTagNode) String

func (t *CTagNode) String() string

type ChainNode

type ChainNode struct {
	NodeType
	Pos
	Node  Node
	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 (*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) Copy

func (c *ChainNode) Copy() Node

func (*ChainNode) String

func (c *ChainNode) String() string

type CommandNode

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

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

func (*CommandNode) Copy

func (c *CommandNode) Copy() Node

func (*CommandNode) String

func (c *CommandNode) String() string

type CommentNode

type CommentNode struct {
	NodeType
	TagType itemType
	Pos
	//	Width int
	Line int
	Pipe *PipeNode
}

CommentNode holds a tag

func (*CommentNode) Copy

func (t *CommentNode) Copy() Node

func (*CommentNode) String

func (t *CommentNode) String() string

type DotNode

type DotNode struct {
	Pos
}

DotNode holds the special identifier '.'.

func (*DotNode) Copy

func (d *DotNode) Copy() Node

func (*DotNode) String

func (d *DotNode) String() string

func (*DotNode) Type

func (d *DotNode) Type() NodeType

type FieldNode

type FieldNode struct {
	NodeType
	Pos
	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 (*FieldNode) Copy

func (f *FieldNode) Copy() Node

func (*FieldNode) String

func (f *FieldNode) String() string

type IdentifierNode

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

IdentifierNode holds an identifier.

func NewIdentifier

func NewIdentifier(typ NodeType, ident string) *IdentifierNode

NewIdentifier returns a new IdentifierNode with the given identifier name.

func (*IdentifierNode) Copy

func (i *IdentifierNode) Copy() Node

func (*IdentifierNode) SetPos

func (i *IdentifierNode) SetPos(pos Pos) *IdentifierNode

SetPos sets the position. NewIdentifier is a public method so we can't modify its signature. Chained for convenience. TODO: fix one day?

func (*IdentifierNode) String

func (i *IdentifierNode) String() string

type IfNode

type IfNode struct {
	BranchNode
}

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

func (*IfNode) Copy

func (i *IfNode) Copy() Node

type InvertedNode

type InvertedNode struct {
	NodeType
	Pos
	Ident string // The identifier's name.
}

InvertedNode holds an identifier.

func (*InvertedNode) Copy

func (i *InvertedNode) Copy() Node

func (*InvertedNode) SetPos

func (i *InvertedNode) SetPos(pos Pos) *InvertedNode

SetPos sets the position. ParentNode is a public method so we can't modify its signature. Chained for convenience. TODO: fix one day?

func (*InvertedNode) String

func (i *InvertedNode) String() string

type ListNode

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

ListNode holds a sequence of nodes.

func (*ListNode) Copy

func (l *ListNode) Copy() Node

func (*ListNode) CopyList

func (l *ListNode) CopyList() *ListNode

func (*ListNode) String

func (l *ListNode) String() string

type NLNode

type NLNode struct {
	NodeType
	Pos
	Text []byte
}

NLNode holds newline char

func (*NLNode) Copy

func (nl *NLNode) Copy() Node

func (*NLNode) String

func (nl *NLNode) String() string

type Node

type Node interface {
	Type() NodeType
	String() string
	// Copy does a deep copy of the Node and all its components.
	// To avoid type assertions, some XxxNodes also have specialized
	// CopyXxx methods that return *XxxNode.
	Copy() Node
	Position() Pos // byte position of start of node in full original input string
	// contains filtered or unexported methods
}

A Node is an element in the parse tree. The interface is trivial. The interface contains an unexported method so that only types local to this package can satisfy it.

type NodeType

type NodeType int

NodeType identifies the type of a parse tree node.

const (
	NodeText  NodeType = iota // Plain text.
	NodeNL                    // NL are evaluated separately
	NodeCR                    // CRs need to be handled too
	NodeSpace                 // Space..we classify that differently
	NodeComment
	NodeEscaped
	NodeUnescaped
	NodeSection
	NodeInverted
	NodePartial
	NodeParent
	NodeList     // A list of nodes
	NodePipe     // A pipeline of commands.
	NodeTemplate // A template invocation action.
	NodeIdentifier
	NodeCommand
	NodeVariable
	NodeCTag
	NodeBranch
	NodeIf
	NodeElse
	NodeRange
	NodeWith
	NodeAction // A non-control action such as a field evaluation.
	NodeChain
	NodeField
	NodeDot
	NodeEnd
)

func (NodeType) String

func (n NodeType) String() string

func (NodeType) Type

func (t NodeType) Type() NodeType

Type returns itself and provides an easy default implementation for embedding in a Node. Embedded in all non-trivial Nodes.

type ParentNode

type ParentNode struct {
	NodeType
	Pos
	Ident string // The identifier's name.
}

ParentNode holds an identifier.

func (*ParentNode) Copy

func (i *ParentNode) Copy() Node

func (*ParentNode) SetPos

func (i *ParentNode) SetPos(pos Pos) *ParentNode

SetPos sets the position. ParentNode is a public method so we can't modify its signature. Chained for convenience. TODO: fix one day?

func (*ParentNode) String

func (i *ParentNode) String() string

type PartialNode

type PartialNode struct {
	NodeType
	Pos
	Ident string // The identifier's name.
}

PartialNode holds an identifier.

func (*PartialNode) Copy

func (i *PartialNode) Copy() Node

func (*PartialNode) SetPos

func (i *PartialNode) SetPos(pos Pos) *PartialNode

SetPos sets the position. NewIdentifier is a public method so we can't modify its signature. Chained for convenience. TODO: fix one day?

func (*PartialNode) String

func (i *PartialNode) String() string

type PipeNode

type PipeNode struct {
	NodeType
	Pos
	Line int // The line number in the input (deprecated; kept for compatibility)
	Decl []*VariableNode
	Cmds []*CommandNode // The commands in lexical order.
}

PipeNode holds a pipeline with optional declaration

func (*PipeNode) Copy

func (p *PipeNode) Copy() Node

func (*PipeNode) CopyPipe

func (p *PipeNode) CopyPipe() *PipeNode

func (*PipeNode) String

func (p *PipeNode) String() string

type Pos

type Pos int

Pos represents a byte position in the original input text from which this template was parsed.

func (Pos) Position

func (p Pos) Position() Pos

type RangeNode

type RangeNode struct {
	BranchNode
}

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

func (*RangeNode) Copy

func (r *RangeNode) Copy() Node

type SpaceNode

type SpaceNode struct {
	NodeType
	Pos
	Text []byte
}

SpaceNode holds a series of spaces, this sometimes matter

func (*SpaceNode) Copy

func (t *SpaceNode) Copy() Node

func (*SpaceNode) String

func (t *SpaceNode) String() string

type TemplateNode

type TemplateNode struct {
	NodeType
	Pos
	Line int       // The line number in the input (deprecated; kept for compatibility)
	Name string    // The name of the template (unquoted).
	Pipe *PipeNode // The command to evaluate as dot for the template.
}

TemplateNode represents a {{template}} action.

func (*TemplateNode) Copy

func (t *TemplateNode) Copy() Node

func (*TemplateNode) String

func (t *TemplateNode) String() string

type TextNode

type TextNode struct {
	NodeType
	Pos
	Text []byte // The text; may span newlines.
}

TextNode holds plain text.

func (*TextNode) Copy

func (t *TextNode) Copy() Node

func (*TextNode) String

func (t *TextNode) String() string

type VariableNode

type VariableNode struct {
	NodeType
	Typ itemType // Variables can be escaped or unescaped; this is for that.
	Pos
	Ident []string // Variable name and fields in lexical order
}

VariableNode holds an escaped variable

func (*VariableNode) Copy

func (v *VariableNode) Copy() Node

func (*VariableNode) String

func (v *VariableNode) String() string

type WithNode

type WithNode struct {
	BranchNode
}

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

func (*WithNode) Copy

func (w *WithNode) Copy() Node

Jump to

Keyboard shortcuts

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