parse

package
v0.0.0-...-526ed0b Latest Latest
Warning

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

Go to latest
Published: May 31, 2017 License: GPL-3.0 Imports: 7 Imported by: 0

Documentation

Overview

Package parse builds parse trees for FreeMarker templates. Clients should use github.com/b3log/freemarker.go package to construct templates rather than this one, which provides shared internal data structures not intended for general use.

Index

Constants

View Source
const (
	LowestPrec  = 0 // non-operators
	UnaryPrec   = 6
	HighestPrec = 7
)

Variables

This section is empty.

Functions

func IsEmptyTree

func IsEmptyTree(n Node) bool

IsEmptyTree reports whether this tree (node) is empty of everything but space.

func Parse

func Parse(name, text string) (map[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.

Types

type BoolNode

type BoolNode struct {
	NodeType
	Pos

	True bool // The value of the boolean constant.
	// contains filtered or unexported fields
}

BoolNode holds a boolean constant.

func (*BoolNode) Copy

func (b *BoolNode) Copy() Node

func (*BoolNode) String

func (b *BoolNode) String() string

type ContentNode

type ContentNode struct {
	NodeType
	Pos

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

ContentNode holds a sequence of nodes.

func (*ContentNode) Copy

func (c *ContentNode) Copy() Node

func (*ContentNode) CopyContent

func (c *ContentNode) CopyContent() *ContentNode

func (*ContentNode) String

func (c *ContentNode) String() string

type ExpressionNode

type ExpressionNode struct {
	NodeType
	Pos

	Nodes []Node // two nodes at most, binary expression, such as "a+b"
	// contains filtered or unexported fields
}

func (*ExpressionNode) Copy

func (c *ExpressionNode) Copy() Node

func (*ExpressionNode) CopyExpr

func (c *ExpressionNode) CopyExpr() *ExpressionNode

func (*ExpressionNode) String

func (c *ExpressionNode) String() string

type IdentifierNode

type IdentifierNode struct {
	NodeType
	Pos

	Ident string // The identifier's name.
	// contains filtered or unexported fields
}

IdentifierNode holds an identifier.

func (*IdentifierNode) Copy

func (i *IdentifierNode) Copy() Node

func (*IdentifierNode) String

func (i *IdentifierNode) String() string

type IfNode

type IfNode struct {
	NodeType
	Pos

	Expr        *ExpressionNode
	Content     *ContentNode
	ElseContent *ContentNode
	// contains filtered or unexported fields
}

IfNode represents a <#if> directive.

func (*IfNode) Copy

func (i *IfNode) Copy() Node

func (*IfNode) String

func (ifNode *IfNode) String() string

type InterpolationNode

type InterpolationNode struct {
	NodeType
	Pos

	Expr *ExpressionNode
	// contains filtered or unexported fields
}

InterpolationNode represents a ${expr}.

func (*InterpolationNode) Copy

func (i *InterpolationNode) Copy() Node

func (*InterpolationNode) String

func (interpolationNode *InterpolationNode) String() string

type ListNode

type ListNode struct {
	NodeType
	Pos

	Expr        *ExpressionNode
	Content     *ContentNode
	ElseContent *ContentNode
	// contains filtered or unexported fields
}

ListNode represents a <#list> directive.

func (*ListNode) Copy

func (l *ListNode) Copy() Node

func (*ListNode) String

func (t *ListNode) String() string

type NilNode

type NilNode struct {
	NodeType
	Pos
	// contains filtered or unexported fields
}

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

func (*NilNode) Copy

func (n *NilNode) Copy() Node

func (*NilNode) String

func (n *NilNode) String() string

func (*NilNode) Type

func (n *NilNode) Type() NodeType

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 (
	NodeContent       NodeType = iota // list of Nodes
	NodeText                          // plain text
	NodeIdentifier                    // identifier
	NodeInterpolation                 // interpolation
	NodeExpression                    // expression
	NodeBool                          // boolean constant
	NodeNumber                        // numerical constant
	NodeString                        // string constant
	NodeNil                           // untyped nil constant
	NodeIf                            // if directive
	NodeList                          // list directive

	NodeTemplate // template invocation action
)

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 NumberNode

type NumberNode struct {
	NodeType
	Pos

	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.
	// contains filtered or unexported fields
}

NumberNode 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 (*NumberNode) Copy

func (n *NumberNode) Copy() Node

func (*NumberNode) String

func (n *NumberNode) 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 StringNode

type StringNode struct {
	NodeType
	Pos

	Text string // The string, after quote processing.
	// contains filtered or unexported fields
}

StringNode holds a string constant.

func (*StringNode) Copy

func (s *StringNode) Copy() Node

func (*StringNode) String

func (s *StringNode) String() string

type TextNode

type TextNode struct {
	NodeType
	Pos

	Text []byte // 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      *ContentNode // 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 (*Tree) Copy

func (t *Tree) Copy() *Tree

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

func (*Tree) ErrorContext

func (t *Tree) ErrorContext(n Node) (location, context string)

ErrorContext returns a textual representation of the location of the node in the input text. The receiver is only used when the node does not have a pointer to the tree inside, which can occur in old code.

func (*Tree) Parse

func (t *Tree) Parse(text string, treeSet map[string]*Tree) (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.

Jump to

Keyboard shortcuts

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