dnscrypt-proxy/vendor/github.com/go-toolsmith/astfmt
Frank Denis 8e913d8bf9 Udate deps 2021-09-24 09:30:49 +02:00
..
.travis.yml Update deps 2021-07-03 10:56:53 +02:00
LICENSE Update deps 2021-07-03 10:56:53 +02:00
README.md Update deps 2021-07-03 10:56:53 +02:00
astfmt.go Update deps 2021-07-03 10:56:53 +02:00

README.md

Go Report Card GoDoc

astfmt

Package astfmt implements ast.Node formatting with fmt-like API.

Installation

go get github.com/go-toolsmith/astfmt

Example

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)))
}