Standard library / text/template/parse

text/template/parse.Tree.Parse()

Populates a tree and the supplied tree set. Empty delimiters choose defaults; custom delimiters can be supplied. Expected stdout: 'true\n'.

Formal Syntax & Structure

go syntaxgo
func (t *Tree) Parse(text, leftDelim, rightDelim string, treeSet map[string]*Tree, funcs ...map[string]any) (tree *Tree, err error)

Parameters & Attributes

NameTypeDescription
textstringTemplate source text, authored by a trusted developer.
leftDelimstringInput to the operation as described above.
rightDelimstringInput to the operation as described above.
treeSetmap[string]*TreeInput to the operation as described above.
funcs...map[string]anyInput to the operation as described above.

Return Value

(tree *Tree, err error)

Populates a tree and the supplied tree set.

Working Example

Example Snippetgo
package main
import (  "fmt"  "text/template/parse")
func check(e error) {  if e != nil {    panic(e)  }}
func main() {  t := parse.New("demo")  s := map[string]*parse.Tree{}  _, e := t.Parse("[[.]]", "[[", "]]", s)  check(e)  fmt.Println(s["demo"] == t && t.Root.Nodes[0].Type() == parse.NodeAction)}
Go Reference