Standard library / text/template/parse

text/template/parse.IdentifierNode.SetPos()

SetPos sets the source byte position and returns the same identifier for chaining. Expected stdout: 'true\n'.

Formal Syntax & Structure

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

Parameters & Attributes

NameTypeDescription
posPosInput to the operation as described above.

Return Value

*IdentifierNode

SetPos sets the source byte position and returns the same identifier for chaining.

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() {  t := tree("{{printf \"x\"}}")  n := t.Root.Nodes[0].(*parse.ActionNode).Pipe.Cmds[0].Args[0].(*parse.IdentifierNode)  fmt.Println(n.SetPos(12) == n && n.Position() == 12)}
Go Reference