Standard library / text/template/parse

text/template/parse.NumberNode

Numeric literal with representability flags and original spelling. Inspect the exported fields of a parsed node. This low-level package is intended for tooling, not ordinary rendering. Expected stdout: 'true\n'.

Formal Syntax & Structure

go syntaxgo
type NumberNode struct {  NodeType  Pos
  IsInt      bool  IsUint     bool  IsFloat    bool  IsComplex  bool  Int64      int64  Uint64     uint64  Float64    float64  Complex128 complex128  Text       string}

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("{{42}}")  n := t.Root.Nodes[0].(*parse.ActionNode).Pipe.Cmds[0].Args[0].(*parse.NumberNode)  fmt.Println(n.IsInt && n.Int64 == 42)}
Go Reference