diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2020-07-04 11:12:55 +0200 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2020-07-04 15:05:30 +0200 |
| commit | c7d7f10bdff703e4a3c0414e8a33d4e45c91eb35 (patch) | |
| tree | 0dff0ee1f98dbfa3ad8776112053a450d176592b /vendor/github.com/go-toolsmith/astfmt | |
| parent | 9573094ce235bd9afe88f5da27a47dd6bcc1e13b (diff) | |
go.mod: vendor golangci-lint
Diffstat (limited to 'vendor/github.com/go-toolsmith/astfmt')
| -rw-r--r-- | vendor/github.com/go-toolsmith/astfmt/.travis.yml | 9 | ||||
| -rw-r--r-- | vendor/github.com/go-toolsmith/astfmt/LICENSE | 21 | ||||
| -rw-r--r-- | vendor/github.com/go-toolsmith/astfmt/README.md | 39 | ||||
| -rw-r--r-- | vendor/github.com/go-toolsmith/astfmt/astfmt.go | 111 | ||||
| -rw-r--r-- | vendor/github.com/go-toolsmith/astfmt/go.mod | 6 | ||||
| -rw-r--r-- | vendor/github.com/go-toolsmith/astfmt/go.sum | 4 |
6 files changed, 190 insertions, 0 deletions
diff --git a/vendor/github.com/go-toolsmith/astfmt/.travis.yml b/vendor/github.com/go-toolsmith/astfmt/.travis.yml new file mode 100644 index 000000000..c32ac0062 --- /dev/null +++ b/vendor/github.com/go-toolsmith/astfmt/.travis.yml @@ -0,0 +1,9 @@ +language: go +go: + - 1.x +install: + - # Prevent default install action "go get -t -v ./...". +script: + - go get -t -v ./... + - go tool vet . + - go test -v -race ./... diff --git a/vendor/github.com/go-toolsmith/astfmt/LICENSE b/vendor/github.com/go-toolsmith/astfmt/LICENSE new file mode 100644 index 000000000..eef17180f --- /dev/null +++ b/vendor/github.com/go-toolsmith/astfmt/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2018 go-toolsmith + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/vendor/github.com/go-toolsmith/astfmt/README.md b/vendor/github.com/go-toolsmith/astfmt/README.md new file mode 100644 index 000000000..954c92bf4 --- /dev/null +++ b/vendor/github.com/go-toolsmith/astfmt/README.md @@ -0,0 +1,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))) +} +``` diff --git a/vendor/github.com/go-toolsmith/astfmt/astfmt.go b/vendor/github.com/go-toolsmith/astfmt/astfmt.go new file mode 100644 index 000000000..ca993e033 --- /dev/null +++ b/vendor/github.com/go-toolsmith/astfmt/astfmt.go @@ -0,0 +1,111 @@ +// Package astfmt implements `ast.Node` formatting with fmt-like API. +package astfmt + +import ( + "bytes" + "fmt" + "go/ast" + "go/printer" + "go/token" + "io" +) + +// Println calls fmt.Println with additional support of %s format +// for ast.Node arguments. +// +// Uses empty file set for AST printing. +func Println(args ...interface{}) error { + return defaultPrinter.Println(args...) +} + +// Fprintf calls fmt.Fprintf with additional support of %s format +// for ast.Node arguments. +// +// Uses empty file set for AST printing. +func Fprintf(w io.Writer, format string, args ...interface{}) error { + return defaultPrinter.Fprintf(w, format, args...) +} + +// Sprintf calls fmt.Sprintf with additional support of %s format +// for ast.Node arguments. +// +// Uses empty file set for AST printing. +func Sprintf(format string, args ...interface{}) string { + return defaultPrinter.Sprintf(format, args...) +} + +// Sprint calls fmt.Sprint with additional support of %s format +// for ast.Node arguments. +// +// Uses empty file set for AST printing. +func Sprint(args ...interface{}) string { + return defaultPrinter.Sprint(args...) +} + +// NewPrinter returns printer that uses bound file set when printing AST nodes. +func NewPrinter(fset *token.FileSet) *Printer { + return &Printer{fset: fset} +} + +// Printer provides API close to fmt package for printing AST nodes. +// Unlike freestanding functions from this package, it makes it possible +// to associate appropriate file set for better output. +type Printer struct { + fset *token.FileSet +} + +// Println printer method is like Println function, but uses bound file set when printing. +func (p *Printer) Println(args ...interface{}) error { + _, err := fmt.Println(wrapArgs(p.fset, args)...) + return err +} + +// Fprintf printer method is like Fprintf function, but uses bound file set when printing. +func (p *Printer) Fprintf(w io.Writer, format string, args ...interface{}) error { + _, err := fmt.Fprintf(w, format, wrapArgs(p.fset, args)...) + return err +} + +// Sprintf printer method is like Sprintf function, but uses bound file set when printing. +func (p *Printer) Sprintf(format string, args ...interface{}) string { + return fmt.Sprintf(format, wrapArgs(p.fset, args)...) +} + +// Sprint printer method is like Sprint function, but uses bound file set when printing. +func (p *Printer) Sprint(args ...interface{}) string { + return fmt.Sprint(wrapArgs(p.fset, args)...) +} + +// defaultPrinter is used in printing functions like Println. +// Uses empty file set. +var defaultPrinter = NewPrinter(token.NewFileSet()) + +// wrapArgs returns arguments slice with every ast.Node element +// replaced with fmtNode wrapper that supports additional formatting. +func wrapArgs(fset *token.FileSet, args []interface{}) []interface{} { + for i := range args { + if x, ok := args[i].(ast.Node); ok { + args[i] = fmtNode{fset: fset, node: x} + } + } + return args +} + +type fmtNode struct { + fset *token.FileSet + node ast.Node +} + +func (n fmtNode) String() string { + var buf bytes.Buffer + if err := printer.Fprint(&buf, n.fset, n.node); err != nil { + return fmt.Sprintf("%%!s(ast.Node=%s)", err) + } + return buf.String() +} + +func (n fmtNode) GoString() string { + var buf bytes.Buffer + fmt.Fprintf(&buf, "%#v", n.node) + return buf.String() +} diff --git a/vendor/github.com/go-toolsmith/astfmt/go.mod b/vendor/github.com/go-toolsmith/astfmt/go.mod new file mode 100644 index 000000000..d23db1566 --- /dev/null +++ b/vendor/github.com/go-toolsmith/astfmt/go.mod @@ -0,0 +1,6 @@ +module github.com/go-toolsmith/astfmt + +require ( + github.com/go-toolsmith/astequal v1.0.0 // indirect + github.com/go-toolsmith/strparse v1.0.0 +) diff --git a/vendor/github.com/go-toolsmith/astfmt/go.sum b/vendor/github.com/go-toolsmith/astfmt/go.sum new file mode 100644 index 000000000..aa0857030 --- /dev/null +++ b/vendor/github.com/go-toolsmith/astfmt/go.sum @@ -0,0 +1,4 @@ +github.com/go-toolsmith/astequal v1.0.0 h1:4zxD8j3JRFNyLN46lodQuqz3xdKSrur7U/sr0SDS/gQ= +github.com/go-toolsmith/astequal v1.0.0/go.mod h1:H+xSiq0+LtiDC11+h1G32h7Of5O3CYFJ99GVbS5lDKY= +github.com/go-toolsmith/strparse v1.0.0 h1:Vcw78DnpCAKlM20kSbAyO4mPfJn/lyYA4BJUDxe2Jb4= +github.com/go-toolsmith/strparse v1.0.0/go.mod h1:YI2nUKP9YGZnL/L1/DLFBfixrcjslWct4wyljWhSRy8= |
