Open hhstore opened 5 years ago
傻瓜式
生产代码. https://github.com/cweill/gotests
https://github.com/yakumioto/mgen
https://github.com/dave/jennifer
ParseFile()
: 该方法很强大, mode 支持多个解析模式. 支持解析注释使用示例:
package gen
import (
"go/ast"
"go/parser"
"go/token"
)
// This example shows what an AST looks like when printed for debugging.
func ExamplePrint() {
// src is the input for which we want to print the AST.
src := `
package main
// main: this is main func
func main() {
// call println -key1=value1 -key2=value2
println("Hello, World!")
}
`
// Create the AST by parsing src.
fset := token.NewFileSet() // positions are relative to fset
f, err := parser.ParseFile(fset, "", src, parser.ParseComments) // [mode=0]
if err != nil {
panic(err)
}
// Print the AST.
ast.Print(fset, f)
}
package gen
import (
"testing"
)
func TestExamplePrint(t *testing.T) {
ExamplePrint()
}
related:
167