Source file
src/go/format/example_test.go
1
2
3
4
5 package format_test
6
7 import (
8 "bytes"
9 "fmt"
10 "go/format"
11 "go/parser"
12 "go/token"
13 "log"
14 )
15
16 func ExampleNode() {
17 const expr = "(6+2*3)/4"
18
19
20
21 node, err := parser.ParseExpr(expr)
22 if err != nil {
23 log.Fatal(err)
24 }
25
26
27
28 fset := token.NewFileSet()
29
30 var buf bytes.Buffer
31 err = format.Node(&buf, fset, node)
32 if err != nil {
33 log.Fatal(err)
34 }
35
36 fmt.Println(buf.String())
37
38
39 }
40
View as plain text