https://github.com/goiste/goparser
Parse Go files by annotation in doc comment
https://github.com/goiste/goparser
ast ast-tree go go-parser golang parser
Last synced: 12 months ago
JSON representation
Parse Go files by annotation in doc comment
- Host: GitHub
- URL: https://github.com/goiste/goparser
- Owner: goiste
- Created: 2022-08-16T15:15:02.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2022-08-16T15:32:13.000Z (almost 4 years ago)
- Last Synced: 2025-06-25T09:06:31.227Z (about 1 year ago)
- Topics: ast, ast-tree, go, go-parser, golang, parser
- Language: Go
- Homepage:
- Size: 3.91 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Go Parser
A small package that helps you parse Go files by annotation in doc comment, e.g. get var values or list of struct
methods.
Features:
- get values of variables:
- literal types
- slices of literal types
- maps with literal types as keys and values
- get list of function names:
- by method receiver type
- by parameters types
Literal types:
- bool
- string
- int8-int64
- uint8-uint64
- float32/64
— set directly, w/o type castings or pointers
Usage:
parsed code:
```go
var (
// parser
boolValue = true
// parser:str
stringValue = "3"
```
[full example_code.go](example/example_code.go)
main code:
```go
import (
gp "github.com/goiste/goparser"
)
...
p, err := gp.New("example_code.go")
if err != nil {
panic(err)
}
boolValues := gp.GetBasicValues[bool](p, "parser")
for _, v := range boolValues {
fmt.Printf("name: %s; value: %t\n", v.Name, v.Value) // name: boolValue; value: true
}
stringValues := gp.GetBasicValues[string](p, "parser", "parser:str")
for _, v := range stringValues {
fmt.Printf("name: %s; value: %q\n", v.Name, v.Value) // name: stringValue; value: "3"
}
```
[full example.go](example/example.go)