https://github.com/go-toolsmith/astfmt
Package astfmt implements ast.Node formatting with fmt-like API.
https://github.com/go-toolsmith/astfmt
ast fmt go golang printer stringify
Last synced: 12 days ago
JSON representation
Package astfmt implements ast.Node formatting with fmt-like API.
- Host: GitHub
- URL: https://github.com/go-toolsmith/astfmt
- Owner: go-toolsmith
- License: mit
- Created: 2018-06-15T06:17:19.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2025-09-07T16:53:31.000Z (5 months ago)
- Last Synced: 2025-09-07T18:41:13.700Z (5 months ago)
- Topics: ast, fmt, go, golang, printer, stringify
- Language: Go
- Size: 19.5 KB
- Stars: 5
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# astfmt
[![build-img]][build-url]
[![pkg-img]][pkg-url]
[![reportcard-img]][reportcard-url]
[![version-img]][version-url]
Package `astfmt` implements ast.Node formatting with fmt-like API.
## Installation
Go version 1.16+
```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)))
}
```
## License
[MIT License](LICENSE).
[build-img]: https://github.com/go-toolsmith/astfmt/workflows/build/badge.svg
[build-url]: https://github.com/go-toolsmith/astfmt/actions
[pkg-img]: https://pkg.go.dev/badge/go-toolsmith/astfmt
[pkg-url]: https://pkg.go.dev/github.com/go-toolsmith/astfmt
[reportcard-img]: https://goreportcard.com/badge/go-toolsmith/astfmt
[reportcard-url]: https://goreportcard.com/report/go-toolsmith/astfmt
[version-img]: https://img.shields.io/github/v/release/go-toolsmith/astfmt
[version-url]: https://github.com/go-toolsmith/astfmt/releases