Standard library / text/template/parse

text/template/parse.Node

Closed interface for a template syntax node. Type identifies its category, String displays syntax, Copy copies nodes (see BranchNode caveat), and Position reports byte offsets. External types cannot implement its private method. Expected stdout: 'true\n'.

Formal Syntax & Structure

go syntaxgo
type Node interface {  Type() NodeType  String() string  Copy() Node  Position() Pos
}

Working Example

Example Snippetgo
package main
import (  "fmt"  "text/template/parse")
func tree(s string) *parse.Tree {  t := parse.New("demo")  t.Mode = parse.ParseComments | parse.SkipFuncCheck  _, e := t.Parse(s, "", "", map[string]*parse.Tree{})  if e != nil {    panic(e)  }  return t}func action(s string) *parse.ActionNode { return tree(s).Root.Nodes[0].(*parse.ActionNode) }
func main() {  var n parse.Node = tree("Hi").Root.Nodes[0]  fmt.Println(n.Type() == parse.NodeText && n.String() == "Hi")}
Go Reference