parse

package
v0.6.31 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2021 License: BSD-3-Clause Imports: 5 Imported by: 0

Documentation

Overview

Package parse builds parse trees for templates as defined by text/template and html/template. Clients should use those packages to construct templates rather than this one, which provides shared internal data structures not intended for general use.

Index

Constants

View Source
const (
	ERROR token = iota
	EOF         // End of File
	SPACE       // White Space

	TEXT
	IDENT // names, variables

	AT_SIGN // @
	COMMA   // ,
	L_PAREN // (
	R_PAREN // )
	L_DELIM // {{
	R_DELIM // }}

	MODEL
	TABLE
	VIEW
	COUNTER
)

Variables

This section is empty.

Functions

This section is empty.

Types

type CounterNode

type CounterNode struct {
	NodeType
	Pos

	Text string // The text; may span newlines.
	// contains filtered or unexported fields
}

CounterNode holds counter

func (*CounterNode) Copy

func (t *CounterNode) Copy() Node

func (*CounterNode) String

func (t *CounterNode) String() string

type ListNode

type ListNode struct {
	NodeType
	Pos

	Nodes []Node // The element nodes in lexical order.
	// contains filtered or unexported fields
}

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 ModelNode

type ModelNode struct {
	NodeType
	Pos

	Text string // The text; may span newlines.
	// contains filtered or unexported fields
}

ModelNode holds model

func (*ModelNode) Copy

func (t *ModelNode) Copy() Node

func (*ModelNode) String

func (t *ModelNode) 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 (
	NodeList NodeType = iota // a list of Nodes
	NodeText
	NodeModel
	NodeTable
	NodeView
	NodeCounter
)

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 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 TableNode

type TableNode struct {
	NodeType
	Pos

	PartitionKeys  []string
	ClusteringKeys []string
	// contains filtered or unexported fields
}

TableNode holds table

func (*TableNode) Copy

func (t *TableNode) Copy() Node

func (*TableNode) String

func (t *TableNode) String() string

type TextNode

type TextNode struct {
	NodeType
	Pos

	Text string // The text; may span newlines.
	// contains filtered or unexported fields
}

TextNode holds plain text.

func (*TextNode) Copy

func (t *TextNode) Copy() Node

func (*TextNode) String

func (t *TextNode) String() string

type Tree

type Tree struct {
	Name      string    // name of the template represented by the tree.
	ParseName string    // name of the top-level template during parsing, for error messages.
	Root      *ListNode // top-level root of the tree.
	// contains filtered or unexported fields
}

Tree is the representation of a single parsed template.

func New

func New(name string) *Tree

New allocates a new parse tree with the given name.

func Parse

func Parse(name, text string) (*Tree, error)

Parse returns a map from template name to parse.Tree, created by parsing the templates described in the argument string. The top-level template will be given the specified name. If an error is encountered, parsing stops and an empty map is returned with the error.

func (*Tree) Copy

func (t *Tree) Copy() *Tree

Copy returns a copy of the Tree. Any parsing state is discarded.

func (*Tree) Parse

func (t *Tree) Parse(text string) (tree *Tree, err error)

Parse parses the template definition string to construct a representation of the template for execution. If either action delimiter string is empty, the default ("{{" or "}}") is used. Embedded template definitions are added to the treeSet map.

type ViewNode

type ViewNode struct {
	NodeType
	Pos

	PartitionKeys  []string
	ClusteringKeys []string
	// contains filtered or unexported fields
}

ViewNode holds view

func (*ViewNode) Copy

func (t *ViewNode) Copy() Node

func (*ViewNode) String

func (t *ViewNode) String() string

Jump to

Keyboard shortcuts

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