Created
July 13, 2015 21:46
-
-
Save hoffoo/5283774e409ba7e8b003 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"go/ast" | |
"go/parser" | |
"go/token" | |
) | |
func main() { | |
file := "fail.go" | |
//path := "github.com/hoffoo/ffffar" | |
// Create the AST by parsing src. | |
fset := token.NewFileSet() // positions are relative to fset | |
f, err := parser.ParseFile(fset, file, nil, parser.ParseComments|parser.AllErrors) | |
if err != nil { | |
panic(err) | |
} | |
for path, obj := range f.Scope.Objects { | |
fmt.Println(path) | |
switch d := obj.Decl.(type) { | |
case *ast.FuncType: | |
// XXX implement getting comments from these types | |
case *ast.StructType: | |
// XXX implement getting comments from these types | |
case *ast.FuncDecl: | |
if d.Doc == nil { | |
continue | |
} | |
if d.Doc.List != nil { | |
for _, comment := range d.Doc.List { | |
if comment != nil { | |
fmt.Printf("%s - %s\n", d.Name, comment.Text) | |
} | |
} | |
} else { | |
fmt.Printf("%s - %v", d.Doc.Text) | |
} | |
} | |
} | |
} | |
// This is a type | |
type T struct { | |
// this is a Member | |
Member int | |
} | |
// this is an instance fn | |
func (*T) instancemem() { | |
} | |
// this is a public fn | |
func pubmem() { | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment