blob: 954c92bf4699aec66e1fa9fdb678fc4042ac80b4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
[](https://goreportcard.com/report/github.com/go-toolsmith/strparse)
[](https://godoc.org/github.com/go-toolsmith/strparse)
# astfmt
Package astfmt implements ast.Node formatting with fmt-like API.
## Installation
```bash
go get github.com/go-toolsmith/astfmt
```
## Example
```go
package main
import (
"go/token"
"os"
"github.com/go-toolsmith/astfmt"
"github.com/go-toolsmith/strparse"
)
func Example() {
x := strparse.Expr(`foo(bar(baz(1+2)))`)
// astfmt functions add %s support for ast.Node arguments.
astfmt.Println(x) // => foo(bar(baz(1 + 2)))
astfmt.Fprintf(os.Stdout, "node=%s\n", x) // => node=foo(bar(baz(1 + 2)))
// Can use specific file set with printer.
fset := token.NewFileSet() // Suppose this fset is used when parsing
pp := astfmt.NewPrinter(fset)
pp.Println(x) // => foo(bar(baz(1 + 2)))
}
```
|