aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/go-toolsmith/strparse
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2020-07-04 11:12:55 +0200
committerDmitry Vyukov <dvyukov@google.com>2020-07-04 15:05:30 +0200
commitc7d7f10bdff703e4a3c0414e8a33d4e45c91eb35 (patch)
tree0dff0ee1f98dbfa3ad8776112053a450d176592b /vendor/github.com/go-toolsmith/strparse
parent9573094ce235bd9afe88f5da27a47dd6bcc1e13b (diff)
go.mod: vendor golangci-lint
Diffstat (limited to 'vendor/github.com/go-toolsmith/strparse')
-rw-r--r--vendor/github.com/go-toolsmith/strparse/.travis.yml9
-rw-r--r--vendor/github.com/go-toolsmith/strparse/LICENSE21
-rw-r--r--vendor/github.com/go-toolsmith/strparse/README.md34
-rw-r--r--vendor/github.com/go-toolsmith/strparse/go.mod1
-rw-r--r--vendor/github.com/go-toolsmith/strparse/strparse.go59
5 files changed, 124 insertions, 0 deletions
diff --git a/vendor/github.com/go-toolsmith/strparse/.travis.yml b/vendor/github.com/go-toolsmith/strparse/.travis.yml
new file mode 100644
index 000000000..8994d395c
--- /dev/null
+++ b/vendor/github.com/go-toolsmith/strparse/.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 ./... \ No newline at end of file
diff --git a/vendor/github.com/go-toolsmith/strparse/LICENSE b/vendor/github.com/go-toolsmith/strparse/LICENSE
new file mode 100644
index 000000000..eef17180f
--- /dev/null
+++ b/vendor/github.com/go-toolsmith/strparse/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/strparse/README.md b/vendor/github.com/go-toolsmith/strparse/README.md
new file mode 100644
index 000000000..ae80a5398
--- /dev/null
+++ b/vendor/github.com/go-toolsmith/strparse/README.md
@@ -0,0 +1,34 @@
+[![Go Report Card](https://goreportcard.com/badge/github.com/go-toolsmith/strparse)](https://goreportcard.com/report/github.com/go-toolsmith/strparse)
+[![GoDoc](https://godoc.org/github.com/go-toolsmith/strparse?status.svg)](https://godoc.org/github.com/go-toolsmith/strparse)
+[![Build Status](https://travis-ci.org/go-toolsmith/strparse.svg?branch=master)](https://travis-ci.org/go-toolsmith/strparse)
+
+
+# strparse
+
+Package strparse provides convenience wrappers around `go/parser` for simple
+expression, statement and declaretion parsing from string.
+
+## Installation
+
+```bash
+go get github.com/go-toolsmith/strparse
+```
+
+## Example
+
+```go
+package main
+
+import (
+ "go-toolsmith/astequal"
+ "go-toolsmith/strparse"
+)
+
+func main() {
+ // Comparing AST strings for equallity (note different spacing):
+ x := strparse.Expr(`1 + f(v[0].X)`)
+ y := strparse.Expr(` 1+f( v[0].X ) `)
+ fmt.Println(astequal.Expr(x, y)) // => true
+}
+
+```
diff --git a/vendor/github.com/go-toolsmith/strparse/go.mod b/vendor/github.com/go-toolsmith/strparse/go.mod
new file mode 100644
index 000000000..ed9d88136
--- /dev/null
+++ b/vendor/github.com/go-toolsmith/strparse/go.mod
@@ -0,0 +1 @@
+module github.com/go-toolsmith/strparse
diff --git a/vendor/github.com/go-toolsmith/strparse/strparse.go b/vendor/github.com/go-toolsmith/strparse/strparse.go
new file mode 100644
index 000000000..894c7ebac
--- /dev/null
+++ b/vendor/github.com/go-toolsmith/strparse/strparse.go
@@ -0,0 +1,59 @@
+// Package strparse provides convenience wrappers around `go/parser` for simple
+// expression, statement and declaration parsing from string.
+//
+// Can be used to construct AST nodes using source syntax.
+package strparse
+
+import (
+ "go/ast"
+ "go/parser"
+ "go/token"
+)
+
+var (
+ // BadExpr is returned as a parse result for malformed expressions.
+ // Should be treated as constant or readonly variable.
+ BadExpr = &ast.BadExpr{}
+
+ // BadStmt is returned as a parse result for malformed statmenents.
+ // Should be treated as constant or readonly variable.
+ BadStmt = &ast.BadStmt{}
+
+ // BadDecl is returned as a parse result for malformed declarations.
+ // Should be treated as constant or readonly variable.
+ BadDecl = &ast.BadDecl{}
+)
+
+// Expr parses single expression node from s.
+// In case of parse error, BadExpr is returned.
+func Expr(s string) ast.Expr {
+ node, err := parser.ParseExpr(s)
+ if err != nil {
+ return BadExpr
+ }
+ return node
+}
+
+// Stmt parses single statement node from s.
+// In case of parse error, BadStmt is returned.
+func Stmt(s string) ast.Stmt {
+ node, err := parser.ParseFile(token.NewFileSet(), "", "package main;func main() {"+s+"}", 0)
+ if err != nil {
+ return BadStmt
+ }
+ fn := node.Decls[0].(*ast.FuncDecl)
+ if len(fn.Body.List) != 1 {
+ return BadStmt
+ }
+ return fn.Body.List[0]
+}
+
+// Decl parses single declaration node from s.
+// In case of parse error, BadDecl is returned.
+func Decl(s string) ast.Decl {
+ node, err := parser.ParseFile(token.NewFileSet(), "", "package main;"+s, 0)
+ if err != nil || len(node.Decls) != 1 {
+ return BadDecl
+ }
+ return node.Decls[0]
+}