Documentation
¶
Overview ¶
Package astfrom provides a more forgiving interface for ad-hoc creation of objects in the go/ast package. It's intended for quick debugging and inspection of Go ASTs. See the parent package for a higher level interface for generating complete ASTs at runtime.
Example ¶
package main
import (
"bytes"
"fmt"
"go/format"
"go/token"
"github.com/cstockton/astgen/astfrom"
)
func main() {
run := func(src string) {
node := astfrom.Source(src)
fset := token.NewFileSet()
var buf bytes.Buffer
if err := format.Node(&buf, fset, node); err != nil {
fmt.Println(`Error:`, err)
}
fmt.Printf("`%v` ->\n%s\n\n", src, buf.String())
}
run(`myIdent`)
run(`1 + 2`)
run(`func() {}`)
run(`var foo = "str"`)
run(`var foo = "str"; i := 0`)
}
Output: `myIdent` -> myIdent `1 + 2` -> 1 + 2 `func() {}` -> func() { } `var foo = "str"` -> var foo = "str" `var foo = "str"; i := 0` -> { var foo = "str" i := 0 }
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.