目录 搜索
archive archive/tar archive/zip bufio bufio(缓存) builtin builtin(内置包) bytes bytes(包字节) compress compress/bzip2(压缩/bzip2) compress/flate(压缩/flate) compress/gzip(压缩/gzip) compress/lzw(压缩/lzw) compress/zlib(压缩/zlib) container container/heap(容器数据结构heap) container/list(容器数据结构list) container/ring(容器数据结构ring) context context(上下文) crypto crypto(加密) crypto/aes(加密/aes) crypto/cipher(加密/cipher) crypto/des(加密/des) crypto/dsa(加密/dsa) crypto/ecdsa(加密/ecdsa) crypto/elliptic(加密/elliptic) crypto/hmac(加密/hmac) crypto/md5(加密/md5) crypto/rand(加密/rand) crypto/rc4(加密/rc4) crypto/rsa(加密/rsa) crypto/sha1(加密/sha1) crypto/sha256(加密/sha256) crypto/sha512(加密/sha512) crypto/subtle(加密/subtle) crypto/tls(加密/tls) crypto/x509(加密/x509) crypto/x509/pkix(加密/x509/pkix) database database/sql(数据库/sql) database/sql/driver(数据库/sql/driver) debug debug/dwarf(调试/dwarf) debug/elf(调试/elf) debug/gosym(调试/gosym) debug/macho(调试/macho) debug/pe(调试/pe) debug/plan9obj(调试/plan9obj) encoding encoding(编码) encoding/ascii85(编码/ascii85) encoding/asn1(编码/asn1) encoding/base32(编码/base32) encoding/base64(编码/base64) encoding/binary(编码/binary) encoding/csv(编码/csv) encoding/gob(编码/gob) encoding/hex(编码/hex) encoding/json(编码/json) encoding/pem(编码/pem) encoding/xml(编码/xml) errors errors(错误) expvar expvar flag flag(命令行参数解析flag包) fmt fmt go go/ast(抽象语法树) go/build go/constant(常量) go/doc(文档) go/format(格式) go/importer go/parser go/printer go/scanner(扫描仪) go/token(令牌) go/types(类型) hash hash(散列) hash/adler32 hash/crc32 hash/crc64 hash/fnv html html html/template(模板) image image(图像) image/color(颜色) image/color/palette(调色板) image/draw(绘图) image/gif image/jpeg image/png index index/suffixarray io io io/ioutil log log log/syslog(日志系统) math math math/big math/big math/bits math/bits math/cmplx math/cmplx math/rand math/rand mime mime mime/multipart(多部分) mime/quotedprintable net net net/http net/http net/http/cgi net/http/cookiejar net/http/fcgi net/http/httptest net/http/httptrace net/http/httputil net/http/internal net/http/pprof net/mail net/mail net/rpc net/rpc net/rpc/jsonrpc net/smtp net/smtp net/textproto net/textproto net/url net/url os os os/exec os/signal os/user path path path/filepath(文件路径) plugin plugin(插件) reflect reflect(反射) regexp regexp(正则表达式) regexp/syntax runtime runtime(运行时) runtime/debug(调试) runtime/internal/sys runtime/pprof runtime/race(竞争) runtime/trace(执行追踪器) sort sort(排序算法) strconv strconv(转换) strings strings(字符串) sync sync(同步) sync/atomic(原子操作) syscall syscall(系统调用) testing testing(测试) testing/iotest testing/quick text text/scanner(扫描文本) text/tabwriter text/template(定义模板) text/template/parse time time(时间戳) unicode unicode unicode/utf16 unicode/utf8 unsafe unsafe
文字

  • import "text/template/parse"

  • 概观

  • 索引

概观

解析构包建为 text / template和html / template 定义的模板分析树。客户应该使用这些软件包来构建模板,而不是这个软件包,它提供了不用于一般用途的共享内部数据结构。

索引

  • 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

func IsEmptyTree(n Node) bool

IsEmptyTree 报告此树(节点)是否为空而不是空间。

func Parse

func Parse(name, text, leftDelim, rightDelim string, funcs ...map[string]interface{}) (map[string]*Tree, error)

Parse 从模板名称返回映射到 parse.Tree,通过解析参数字符串中描述的模板创建。顶层模板将被赋予指定的名称。如果遇到错误,解析将停止并返回一个空映射并显示错误。

键入ActionNode

ActionNode 包含一个动作(由分隔符限定)。控制动作有自己的节点;ActionNode 表示简单的例如字段评估和圆括号的管道。

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

func (a *ActionNode) Copy() Node

func (*ActionNode) String

func (a *ActionNode) String() string

键入BoolNode

BoolNode 保存一个布尔常量。

type BoolNode struct {
        NodeType
        Pos

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

func (*BoolNode) Copy

func (b *BoolNode) Copy() Node

func (*BoolNode) String

func (b *BoolNode) String() string

键入BranchNode

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

func (b *BranchNode) Copy() Node

func (*BranchNode) String

func (b *BranchNode) String() string

type ChainNode

ChainNode 包含一个术语,后跟一串字段访问(标识符以'。'开头)。这些名字可能被链接('.x.y')。期间从每个身份证中删除。

type ChainNode struct {
        NodeType
        Pos

        Node  Node
        Field []string // The identifiers in lexical order.        // contains filtered or unexported fields}

func (*ChainNode) Add

func (c *ChainNode) Add(field string)

添加将指定的字段(应以句点开头)添加到链的末尾。

func (*ChainNode) Copy

func (c *ChainNode) Copy() Node

func (*ChainNode) String

func (c *ChainNode) String() string

键入CommandNode

CommandNode 包含一个命令(一个评估操作中的管道)。

type CommandNode struct {
        NodeType
        Pos

        Args []Node // Arguments in lexical order: Identifier, field, or constant.        // contains filtered or unexported fields}

func (*CommandNode) Copy

func (c *CommandNode) Copy() Node

func (*CommandNode) String

func (c *CommandNode) String() string

type DotNode

DotNode 包含特殊标识符'。'。

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

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

FieldNode 包含一个字段(标识符以'。'开始)。这些名字可能被链接('.x.y')。该期限从每个身份证件中删除。

type FieldNode struct {
        NodeType
        Pos

        Ident []string // The identifiers in lexical order.        // contains filtered or unexported fields}

func (*FieldNode) Copy

func (f *FieldNode) Copy() Node

func (*FieldNode) String

func (f *FieldNode) String() string

键入IdentifierNode

IdentifierNode 包含一个标识符。

type IdentifierNode struct {
        NodeType
        Pos

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

func NewIdentifier

func NewIdentifier(ident string) *IdentifierNode

NewIdentifier 用给定的标识符名称返回一个新的 IdentifierNode。

func (*IdentifierNode) Copy

func (i *IdentifierNode) Copy() Node

func (*IdentifierNode) SetPos

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

SetPos 设置位置。NewIdentifier 是一种公共方法,所以我们不能修改它的签名。为了方便链接。TODO:修好一天?

func (*IdentifierNode) SetTree

func (i *IdentifierNode) SetTree(t *Tree) *IdentifierNode

SetTree 设置节点的父树。NewIdentifier 是一种公共方法,所以我们不能修改它的签名。为了方便链接。TODO:修好一天?

func (*IdentifierNode) String

func (i *IdentifierNode) String() string

type IfNode

IfNode 表示一个 {{if}} 动作及其命令。

type IfNode struct {
        BranchNode}

func (*IfNode) Copy

func (i *IfNode) Copy() Node

type ListNode

ListNode 包含一系列节点。

type ListNode struct {
        NodeType
        Pos

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

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 NilNode

NilNode 保存表示无类型 nil 常量的特殊标识符'nil'。

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

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}

键入NodeType

NodeType 标识分析树节点的类型。

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 (NodeType) Type

func (t NodeType) Type() NodeType

Type 返回自身并提供一个简单的默认实现来嵌入节点。嵌入在所有非平凡的节点中。

键入NumberNode

NumberNode 包含一个数字:有符号或无符号整数,浮点数或复数。该值被解析并存储在所有可以表示该值的类型下。这在少量代码中模拟 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 (*NumberNode) Copy

func (n *NumberNode) Copy() Node

func (*NumberNode) String

func (n *NumberNode) String() string

键入PipeNode

PipeNode 拥有一个可选声明的管道

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

func (p *PipeNode) Copy() Node

func (*PipeNode) CopyPipe

func (p *PipeNode) CopyPipe() *PipeNode

func (*PipeNode) String

func (p *PipeNode) String() string

键入Pos

Pos 表示从中解析模板的原始输入文本中的字节位置。

type Pos int

func (Pos) Position

func (p Pos) Position() Pos

键入RangeNode

RangeNode表示一个 {{range}} 动作及其命令。

type RangeNode struct {
        BranchNode}

func (*RangeNode) Copy

func (r *RangeNode) Copy() Node

键入StringNode

StringNode 包含一个字符串常量。该值已被“未引用”。

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

func (s *StringNode) Copy() Node

func (*StringNode) String

func (s *StringNode) String() string

键入TemplateNode

TemplateNode 表示一个 {{template}} 动作。

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

func (t *TemplateNode) Copy() Node

func (*TemplateNode) String

func (t *TemplateNode) String() string

键入TextNode

TextNode 保存纯文本。

type TextNode struct {
        NodeType
        Pos

        Text []byte // The text; may span newlines.        // contains filtered or unexported fields}

func (*TextNode) Copy

func (t *TextNode) Copy() Node

func (*TextNode) String

func (t *TextNode) String() string

键入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}

func New

func New(name string, funcs ...map[string]interface{}) *Tree

New 分配给定名称的新分析树。

func (*Tree) Copy

func (t *Tree) Copy() *Tree

Copy 返回树的副本。任何解析状态都会被丢弃。

func (*Tree) ErrorContext

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

ErrorContext 返回输入文本中节点位置的文本表示。只有当节点没有指向内部树的指针时才会使用接收器,这可能会发生在旧代码中。

func (*Tree) Parse

func (t *Tree) Parse(text, leftDelim, rightDelim string, treeSet map[string]*Tree, funcs ...map[string]interface{}) (tree *Tree, err error)

Parse 解析模板定义字符串以构建用于执行的模板表示。如果任何动作分隔符字符串为空,则使用默认值(“{{”或“}}”)。嵌入式模板定义被添加到树形图。

键入VariableNode

VariableNode 包含变量名称列表,可能带有链接字段访问。美元符号是(第一)名称的一部分。

type VariableNode struct {
        NodeType
        Pos

        Ident []string // Variable name and fields in lexical order.        // contains filtered or unexported fields}

func (*VariableNode) Copy

func (v *VariableNode) Copy() Node

func (*VariableNode) String

func (v *VariableNode) String() string

键入WithNode

WithNode 表示一个 {{with}} 动作及其命令。

type WithNode struct {
        BranchNode}

func (*WithNode) Copy

func (w *WithNode) Copy() Node
上一篇: 下一篇: