https://github.com/src-d/go-parse-utils
https://github.com/src-d/go-parse-utils
Last synced: 6 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/src-d/go-parse-utils
- Owner: src-d
- License: mit
- Created: 2017-01-24T12:04:33.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2018-11-28T02:48:57.000Z (almost 7 years ago)
- Last Synced: 2025-05-05T05:05:33.589Z (6 months ago)
- Language: Go
- Size: 17.6 KB
- Stars: 15
- Watchers: 4
- Forks: 14
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# go-parse-utils
`go-parse-utils` is a collection of utilities for parsing code easily.
[](https://godoc.org/gopkg.in/src-d/go-parse-utils.v1) [](https://travis-ci.org/src-d/go-parse-utils) [](https://codecov.io/gh/src-d/go-parse-utils) [](http://doge.mit-license.org) [](https://goreportcard.com/report/gopkg.in/src-d/go-parse-utils.v1)
### Install
```
go get gopkg.in/src-d/go-parse-utils.v1
```
### Package AST
`PackageAST` retrieves the `*ast.Package` of a package in the given path.
```go
pkg, err := parseutil.PackageAST("github.com/my/project")
```
### Source code importer
The default `importer.Importer` of the Go standard library scans compiled objects, which can be painful to deal with in code generation, as it requires to `go build` before running `go generate`.
This packages provides an implementation of `importer.Importer` and `importer.ImporterFrom` that reads directly from source code if the package is in the GOPATH, otherwise (the stdlib, for example) falls back to the default importer in the standard library.
Features:
* It is safe for concurrent use.
* Caches packages after they are first imported.
```go
importer := parseutil.NewImporter()
pkg, err := importer.Import("github.com/my/project")
```
### License
MIT, see [LICENSE](/LICENSE)