Pewarta Proxy

πŸ“‹ Server Request & Proxy Logs

Loading active proxy settings...
Developed by Khairul Adha (adhexa.id)
Mengambil log server...

βš™οΈ Pengaturan Proxy Target

Help us shape the future of Go! Take the 2026 Go Developer Survey

parse

package standard library
go1.27.3 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2026 License: BSD-3-Clause Imports: 7 Imported by: 1,425

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 ΒΆ

This section is empty.

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 or comments.

func Parse ΒΆ

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

Parse returns a map from template name to 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 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
}

ActionNode holds an action (something bounded by delimiters). Control actions have their own nodes; ActionNode represents simple ones such as field evaluations and parenthesized pipelines.

func (*ActionNode) Copy ΒΆ

func (a *ActionNode) Copy() Node

func (*ActionNode) String ΒΆ

func (a *ActionNode) String() string

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 BranchNode ΒΆ

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
}

BranchNode is the common representation of if, range, and with.

func (*BranchNode) Copy ΒΆ added in go1.4

func (b *BranchNode) Copy() Node

func (*BranchNode) String ΒΆ

func (b *BranchNode) String() string

type BreakNode ΒΆ added in go1.18

type BreakNode struct {
	NodeType
	Pos
	Line int
	// contains filtered or unexported fields
}

BreakNode represents a {{break}} action.

func (*BreakNode) Copy ΒΆ added in go1.18

func (b *BreakNode) Copy() Node

func (*BreakNode) String ΒΆ added in go1.18

func (b *BreakNode) String() string

type ChainNode ΒΆ added in go1.1

type ChainNode struct {
	NodeType
	Pos

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

ChainNode holds a term followed by a chain of field accesses (identifier starting with '.'). The names may be chained ('.x.y'). The periods are dropped from each ident.

func (*ChainNode) Add ΒΆ added in go1.1

func (c *ChainNode) Add(field string)

Add adds the named field (which should start with a period) to the end of the chain.

func (*ChainNode) Copy ΒΆ added in go1.1

func (c *ChainNode) Copy() Node

func (*ChainNode) String ΒΆ added in go1.1

func (c *ChainNode) String() string

type CommandNode ΒΆ

type CommandNode struct {
	NodeType
	Pos

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

CommandNode holds a command (a pipeline inside an evaluating action).

func (*CommandNode) Copy ΒΆ

func (c *CommandNode) Copy() Node

func (*CommandNode) String ΒΆ

func (c *CommandNode) String() string

type CommentNode ΒΆ added in go1.16

type CommentNode struct {
	NodeType
	Pos

	Text string // Comment text.
	// contains filtered or unexported fields
}

CommentNode holds a comment.

func (*CommentNode) Copy ΒΆ added in go1.16

func (c *CommentNode) Copy() Node

func (*CommentNode) String ΒΆ added in go1.16

func (c *CommentNode) String() string

type ContinueNode ΒΆ added in go1.18

type ContinueNode struct {
	NodeType
	Pos
	Line int
	// contains filtered or unexported fields
}

ContinueNode represents a {{continue}} action.

func (*ContinueNode) Copy ΒΆ added in go1.18

func (c *ContinueNode) Copy() Node

func (*ContinueNode) String ΒΆ added in go1.18

func (c *ContinueNode) String() string

type DotNode ΒΆ

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

DotNode holds the special identifier '.'.

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 ΒΆ

type FieldNode struct {
	NodeType
	Pos

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

FieldNode holds a field (identifier starting with '.'). The names may be chained ('.x.y'). The period is dropped from each ident.

func (*FieldNode) Copy ΒΆ

func (f *FieldNode) Copy() Node

func (*FieldNode) String ΒΆ

func (f *FieldNode) 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 NewIdentifier ΒΆ

func NewIdentifier(ident string) *IdentifierNode

NewIdentifier returns a new IdentifierNode with the given identifier name.

func (*IdentifierNode) Copy ΒΆ

func (i *IdentifierNode) Copy() Node

func (*IdentifierNode) SetPos ΒΆ added in go1.1

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

SetPos sets the position. NewIdentifier is a public method so we can't modify its signature. Chained for convenience. TODO: fix one day?

func (*IdentifierNode) SetTree ΒΆ added in go1.4

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

SetTree sets the parent tree for the node. NewIdentifier is a public method so we can't modify its signature. Chained for convenience. TODO: fix one day?

func (*IdentifierNode) String ΒΆ

func (i *IdentifierNode) String() string

type IfNode ΒΆ

type IfNode struct {
	BranchNode
}

IfNode represents an {{if}} action and its commands.

func (*IfNode) Copy ΒΆ

func (i *IfNode) Copy() Node

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 Mode ΒΆ added in go1.16

type Mode uint

A Mode value is a set of flags (or 0). Modes control parser behavior.

const (
	ParseComments Mode = 1 << iota // parse comments and add them to AST
	SkipFuncCheck                  // do not check that functions are defined
)

type NilNode ΒΆ added in go1.1

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

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

func (*NilNode) Copy ΒΆ added in go1.1

func (n *NilNode) Copy() Node

func (*NilNode) String ΒΆ added in go1.1

func (n *NilNode) String() string

func (*NilNode) Type ΒΆ added in go1.1

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 (
	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.
	NodeComment    // A comment.
	NodeBreak      // A break action.
	NodeContinue   // A continue 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 PipeNode ΒΆ

type PipeNode struct {
	NodeType
	Pos

	Line     int             // The line number in the input. Deprecated: Kept for compatibility.
	IsAssign bool            // The variables are being assigned, not declared.
	Decl     []*VariableNode // Variables in lexical order.
	Cmds     []*CommandNode  // The commands in lexical order.
	// contains filtered or unexported fields
}

PipeNode holds a pipeline with optional declaration

func (*PipeNode) Copy ΒΆ

func (p *PipeNode) Copy() Node

func (*PipeNode) CopyPipe ΒΆ

func (p *PipeNode) CopyPipe() *PipeNode

func (*PipeNode) String ΒΆ

func (p *PipeNode) String() string

type Pos ΒΆ added in go1.1

type Pos int

Pos represents a byte position in the original input text from which this template was parsed.

func (Pos) Position ΒΆ added in go1.1

func (p Pos) Position() Pos

type RangeNode ΒΆ

type RangeNode struct {
	BranchNode
}

RangeNode represents a {{range}} action and its commands.

func (*RangeNode) Copy ΒΆ

func (r *RangeNode) Copy() Node

type 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
}

StringNode holds a string constant. The value has been "unquoted".

func (*StringNode) Copy ΒΆ

func (s *StringNode) Copy() Node

func (*StringNode) String ΒΆ

func (s *StringNode) String() string

type TemplateNode ΒΆ

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
}

TemplateNode represents a {{template}} action.

func (*TemplateNode) Copy ΒΆ

func (t *TemplateNode) Copy() Node

func (*TemplateNode) String ΒΆ

func (t *TemplateNode) 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      *ListNode // top-level root of the tree.
	Mode      Mode      // parsing mode.
	// contains filtered or unexported fields
}

Tree is the representation of a single parsed template.

func New ΒΆ

func New(name string, funcs ...map[string]any) *Tree

New allocates a new parse tree with the given name.

func (*Tree) Copy ΒΆ added in go1.2

func (t *Tree) Copy() *Tree

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

func (*Tree) ErrorContext ΒΆ added in go1.1

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, leftDelim, rightDelim string, treeSet map[string]*Tree, funcs ...map[string]any) (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 VariableNode ΒΆ

type VariableNode struct {
	NodeType
	Pos

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

VariableNode holds a list of variable names, possibly with chained field accesses. The dollar sign is part of the (first) name.

func (*VariableNode) Copy ΒΆ

func (v *VariableNode) Copy() Node

func (*VariableNode) String ΒΆ

func (v *VariableNode) String() string

type WithNode ΒΆ

type WithNode struct {
	BranchNode
}

WithNode represents a {{with}} action and its commands.

func (*WithNode) Copy ΒΆ

func (w *WithNode) Copy() Node

Jump to

Keyboard shortcuts

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