File tree 1 file changed +27
-0
lines changed
1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -6,9 +6,11 @@ package format
6
6
7
7
import (
8
8
"bytes"
9
+ "fmt"
9
10
"go/parser"
10
11
"go/token"
11
12
"io/ioutil"
13
+ "log"
12
14
"strings"
13
15
"testing"
14
16
)
@@ -143,3 +145,28 @@ func TestPartial(t *testing.T) {
143
145
}
144
146
}
145
147
}
148
+
149
+ func ExampleNode () {
150
+ const expr = "(6+2*3)/4"
151
+
152
+ // parser.ParseExpr parses the argument and returns the
153
+ // corresponding ast.Node.
154
+ node , err := parser .ParseExpr (expr )
155
+ if err != nil {
156
+ log .Fatal (err )
157
+ }
158
+
159
+ // Create a FileSet for node. Since the node does not come
160
+ // from a real source file, fset will be empty.
161
+ fset := token .NewFileSet ()
162
+
163
+ var buf bytes.Buffer
164
+ err = Node (& buf , fset , node )
165
+ if err != nil {
166
+ log .Fatal (err )
167
+ }
168
+
169
+ fmt .Println (buf .String ())
170
+
171
+ // Output: (6 + 2*3) / 4
172
+ }
You can’t perform that action at this time.
0 commit comments