?
This document uses PHP Chinese website manual Release
import "text/template/parse"
概觀
索引
解析構(gòu)包建為 text / template和html / template 定義的模板分析樹??蛻魬?yīng)該使用這些軟件包來構(gòu)建模板,而不是這個(gè)軟件包,它提供了不用于一般用途的共享內(nèi)部數(shù)據(jù)結(jié)構(gòu)。
func IsEmptyTree(n Node) bool
func Parse(name, text, leftDelim, rightDelim string, funcs ...map[string]interface{}) (map[string]*Tree, error)
type ActionNode
func (a *ActionNode) Copy() Node
func (a *ActionNode) String() string
type BoolNode
func (b *BoolNode) Copy() Node
func (b *BoolNode) String() string
type BranchNode
func (b *BranchNode) Copy() Node
func (b *BranchNode) String() string
type ChainNode
func (c *ChainNode) Add(field string)
func (c *ChainNode) Copy() Node
func (c *ChainNode) String() string
type CommandNode
func (c *CommandNode) Copy() Node
func (c *CommandNode) String() string
type DotNode
func (d *DotNode) Copy() Node
func (d *DotNode) String() string
func (d *DotNode) Type() NodeType
type FieldNode
func (f *FieldNode) Copy() Node
func (f *FieldNode) String() string
type IdentifierNode
func NewIdentifier(ident string) *IdentifierNode
func (i *IdentifierNode) Copy() Node
func (i *IdentifierNode) SetPos(pos Pos) *IdentifierNode
func (i *IdentifierNode) SetTree(t *Tree) *IdentifierNode
func (i *IdentifierNode) String() string
type IfNode
func (i *IfNode) Copy() Node
type ListNode
func (l *ListNode) Copy() Node
func (l *ListNode) CopyList() *ListNode
func (l *ListNode) String() string
type NilNode
func (n *NilNode) Copy() Node
func (n *NilNode) String() string
func (n *NilNode) Type() NodeType
type Node
type NodeType
func (t NodeType) Type() NodeType
type NumberNode
func (n *NumberNode) Copy() Node
func (n *NumberNode) String() string
type PipeNode
func (p *PipeNode) Copy() Node
func (p *PipeNode) CopyPipe() *PipeNode
func (p *PipeNode) String() string
type Pos
func (p Pos) Position() Pos
type RangeNode
func (r *RangeNode) Copy() Node
type StringNode
func (s *StringNode) Copy() Node
func (s *StringNode) String() string
type TemplateNode
func (t *TemplateNode) Copy() Node
func (t *TemplateNode) String() string
type TextNode
func (t *TextNode) Copy() Node
func (t *TextNode) String() string
type Tree
func New(name string, funcs ...map[string]interface{}) *Tree
func (t *Tree) Copy() *Tree
func (t *Tree) ErrorContext(n Node) (location, context string)
func (t *Tree) Parse(text, leftDelim, rightDelim string, treeSet map[string]*Tree, funcs ...map[string]interface{}) (tree *Tree, err error)
type VariableNode
func (v *VariableNode) Copy() Node
func (v *VariableNode) String() string
type WithNode
func (w *WithNode) Copy() Node
lex.go node.go parse.go
func IsEmptyTree(n Node) bool
IsEmptyTree 報(bào)告此樹(節(jié)點(diǎn))是否為空而不是空間。
func Parse(name, text, leftDelim, rightDelim string, funcs ...map[string]interface{}) (map[string]*Tree, error)
Parse 從模板名稱返回映射到 parse.Tree,通過解析參數(shù)字符串中描述的模板創(chuàng)建。頂層模板將被賦予指定的名稱。如果遇到錯(cuò)誤,解析將停止并返回一個(gè)空映射并顯示錯(cuò)誤。
ActionNode 包含一個(gè)動(dòng)作(由分隔符限定)。控制動(dòng)作有自己的節(jié)點(diǎn);ActionNode 表示簡(jiǎn)單的例如字段評(píng)估和圓括號(hào)的管道。
type ActionNode struct { NodeType Pos Line int // The line number in the input. Deprecated: Kept for compatibility. Pipe *PipeNode // The pipeline in the action. // contains filtered or unexported fields}
func (a *ActionNode) Copy() Node
func (a *ActionNode) String() string
BoolNode 保存一個(gè)布爾常量。
type BoolNode struct { NodeType Pos True bool // The value of the boolean constant. // contains filtered or unexported fields}
func (b *BoolNode) Copy() Node
func (b *BoolNode) String() string
BranchNode 是 if,range 和 with 的常見表示。
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). // contains filtered or unexported fields}
func (b *BranchNode) Copy() Node
func (b *BranchNode) String() string
ChainNode 包含一個(gè)術(shù)語,后跟一串字段訪問(標(biāo)識(shí)符以'。'開頭)。這些名字可能被鏈接('.x.y')。期間從每個(gè)身份證中刪除。
type ChainNode struct { NodeType Pos Node Node Field []string // The identifiers in lexical order. // contains filtered or unexported fields}
func (c *ChainNode) Add(field string)
添加將指定的字段(應(yīng)以句點(diǎn)開頭)添加到鏈的末尾。
func (c *ChainNode) Copy() Node
func (c *ChainNode) String() string
CommandNode 包含一個(gè)命令(一個(gè)評(píng)估操作中的管道)。
type CommandNode struct { NodeType Pos Args []Node // Arguments in lexical order: Identifier, field, or constant. // contains filtered or unexported fields}
func (c *CommandNode) Copy() Node
func (c *CommandNode) String() string
DotNode 包含特殊標(biāo)識(shí)符'。'。
type DotNode struct { NodeType Pos // contains filtered or unexported fields}
func (d *DotNode) Copy() Node
func (d *DotNode) String() string
func (d *DotNode) Type() NodeType
FieldNode 包含一個(gè)字段(標(biāo)識(shí)符以'。'開始)。這些名字可能被鏈接('.x.y')。該期限從每個(gè)身份證件中刪除。
type FieldNode struct { NodeType Pos Ident []string // The identifiers in lexical order. // contains filtered or unexported fields}
func (f *FieldNode) Copy() Node
func (f *FieldNode) String() string
IdentifierNode 包含一個(gè)標(biāo)識(shí)符。
type IdentifierNode struct { NodeType Pos Ident string // The identifier's name. // contains filtered or unexported fields}
func NewIdentifier(ident string) *IdentifierNode
NewIdentifier 用給定的標(biāo)識(shí)符名稱返回一個(gè)新的 IdentifierNode。
func (i *IdentifierNode) Copy() Node
func (i *IdentifierNode) SetPos(pos Pos) *IdentifierNode
SetPos 設(shè)置位置。NewIdentifier 是一種公共方法,所以我們不能修改它的簽名。為了方便鏈接。TODO:修好一天?
func (i *IdentifierNode) SetTree(t *Tree) *IdentifierNode
SetTree 設(shè)置節(jié)點(diǎn)的父樹。NewIdentifier 是一種公共方法,所以我們不能修改它的簽名。為了方便鏈接。TODO:修好一天?
func (i *IdentifierNode) String() string
IfNode 表示一個(gè) {{if}} 動(dòng)作及其命令。
type IfNode struct { BranchNode}
func (i *IfNode) Copy() Node
ListNode 包含一系列節(jié)點(diǎn)。
type ListNode struct { NodeType Pos Nodes []Node // The element nodes in lexical order. // contains filtered or unexported fields}
func (l *ListNode) Copy() Node
func (l *ListNode) CopyList() *ListNode
func (l *ListNode) String() string
NilNode 保存表示無類型 nil 常量的特殊標(biāo)識(shí)符'nil'。
type NilNode struct { NodeType Pos // contains filtered or unexported fields}
func (n *NilNode) Copy() Node
func (n *NilNode) String() string
func (n *NilNode) Type() NodeType
節(jié)點(diǎn)是分析樹中的一個(gè)元素。界面很簡(jiǎn)單。該接口包含一個(gè)未導(dǎo)出的方法,因此只有該包的本地類型才能滿足它。
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}
NodeType 標(biāo)識(shí)分析樹節(jié)點(diǎn)的類型。
type NodeType int
const ( NodeText NodeType = iota // Plain text. NodeAction // A non-control action such as a field evaluation. NodeBool // A boolean constant. NodeChain // A sequence of field accesses. NodeCommand // An element of a pipeline. NodeDot // The cursor, dot. NodeField // A field or method name. NodeIdentifier // An identifier; always a function name. NodeIf // An if action. NodeList // A list of Nodes. NodeNil // An untyped nil constant. NodeNumber // A numerical constant. NodePipe // A pipeline of commands. NodeRange // A range action. NodeString // A string constant. NodeTemplate // A template invocation action. NodeVariable // A $ variable. NodeWith // A with action.)
func (t NodeType) Type() NodeType
Type 返回自身并提供一個(gè)簡(jiǎn)單的默認(rèn)實(shí)現(xiàn)來嵌入節(jié)點(diǎn)。嵌入在所有非平凡的節(jié)點(diǎn)中。
NumberNode 包含一個(gè)數(shù)字:有符號(hào)或無符號(hào)整數(shù),浮點(diǎn)數(shù)或復(fù)數(shù)。該值被解析并存儲(chǔ)在所有可以表示該值的類型下。這在少量代碼中模擬 Go 的理想常量的行為。
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}
func (n *NumberNode) Copy() Node
func (n *NumberNode) String() string
PipeNode 擁有一個(gè)可選聲明的管道
type PipeNode struct { NodeType Pos Line int // The line number in the input. Deprecated: Kept for compatibility. Decl []*VariableNode // Variable declarations in lexical order. Cmds []*CommandNode // The commands in lexical order. // contains filtered or unexported fields}
func (p *PipeNode) Copy() Node
func (p *PipeNode) CopyPipe() *PipeNode
func (p *PipeNode) String() string
Pos 表示從中解析模板的原始輸入文本中的字節(jié)位置。
type Pos int
func (p Pos) Position() Pos
RangeNode表示一個(gè) {{range}} 動(dòng)作及其命令。
type RangeNode struct { BranchNode}
func (r *RangeNode) Copy() Node
StringNode 包含一個(gè)字符串常量。該值已被“未引用”。
type StringNode struct { NodeType Pos Quoted string // The original text of the string, with quotes. Text string // The string, after quote processing. // contains filtered or unexported fields}
func (s *StringNode) Copy() Node
func (s *StringNode) String() string
TemplateNode 表示一個(gè) {{template}} 動(dòng)作。
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. // contains filtered or unexported fields}
func (t *TemplateNode) Copy() Node
func (t *TemplateNode) String() string
TextNode 保存純文本。
type TextNode struct { NodeType Pos Text []byte // The text; may span newlines. // contains filtered or unexported fields}
func (t *TextNode) Copy() Node
func (t *TextNode) String() string
樹是單個(gè)解析模板的表示。
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}
func New(name string, funcs ...map[string]interface{}) *Tree
New 分配給定名稱的新分析樹。
func (t *Tree) Copy() *Tree
Copy 返回樹的副本。任何解析狀態(tài)都會(huì)被丟棄。
func (t *Tree) ErrorContext(n Node) (location, context string)
ErrorContext 返回輸入文本中節(jié)點(diǎn)位置的文本表示。只有當(dāng)節(jié)點(diǎn)沒有指向內(nèi)部樹的指針時(shí)才會(huì)使用接收器,這可能會(huì)發(fā)生在舊代碼中。
func (t *Tree) Parse(text, leftDelim, rightDelim string, treeSet map[string]*Tree, funcs ...map[string]interface{}) (tree *Tree, err error)
Parse 解析模板定義字符串以構(gòu)建用于執(zhí)行的模板表示。如果任何動(dòng)作分隔符字符串為空,則使用默認(rèn)值(“{{”或“}}”)。嵌入式模板定義被添加到樹形圖。
VariableNode 包含變量名稱列表,可能帶有鏈接字段訪問。美元符號(hào)是(第一)名稱的一部分。
type VariableNode struct { NodeType Pos Ident []string // Variable name and fields in lexical order. // contains filtered or unexported fields}
func (v *VariableNode) Copy() Node
func (v *VariableNode) String() string
WithNode 表示一個(gè) {{with}} 動(dòng)作及其命令。
type WithNode struct { BranchNode}
func (w *WithNode) Copy() Node