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
- func IsEmptyTree(n Node) bool
- func Parse(name, text string) (map[string]*Tree, error)
- type BoolNode
- type ContentNode
- type ExpressionNode
- type IdentifierNode
- type IfNode
- type InterpolationNode
- type ListNode
- type NilNode
- type Node
- type NodeType
- type NumberNode
- type Pos
- type StringNode
- type TextNode
- type Tree
Constants ¶
const ( LowestPrec = 0 // non-operators UnaryPrec = 6 HighestPrec = 7 )
Variables ¶
This section is empty.
Functions ¶
func IsEmptyTree ¶
IsEmptyTree reports whether this tree (node) is empty of everything but space.
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.
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.
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.
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 )
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.
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.
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 (*Tree) ErrorContext ¶
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.