Documentation ¶
Overview ¶
Package importer provides access to export data importers.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConvertAST ¶
func ConvertAST(a *ast.File, info *types.Info, ann *annotations.Annotation)
ConvertAST transforms an imported Go AST applying type annotations found in doc comments.
It looks up doc comment lines of the form 'For SGO: <annotation>', where <annotation> is a type expression. If found, the annotation replaces the type of the documented declaration or field.
Example ¶
package main import ( "os" "github.com/tcard/sgo/sgo/ast" "github.com/tcard/sgo/sgo/types" "github.com/tcard/sgo/sgo/importer" "github.com/tcard/sgo/sgo/parser" "github.com/tcard/sgo/sgo/printer" "github.com/tcard/sgo/sgo/token" ) func main() { fset := token.NewFileSet() a, _ := parser.ParseFile(fset, "example.sgo", ` package example type LinkedList struct { Head int // For SGo: ?*LinkedList Tail *LinkedList } `, parser.ParseComments) info := &types.Info{ Defs: map[*ast.Ident]types.Object{}, Uses: map[*ast.Ident]types.Object{}, } cfg := &types.Config{} cfg.Check("", fset, []*ast.File{a}, info) importer.ConvertAST(a, info, nil) printer.Fprint(os.Stdout, fset, a) }
Output: package example type LinkedList struct { Head int // For SGo: ?*LinkedList Tail ?*LinkedList }
func Default ¶
Default returns a types.Importer that imports from Go source code and transforms to SGo.
For packages imported from any of the passed files, conversion is performed by passing the AST through ConvertAST. The packages that imported packages import themselves are imported by the default go/importer, without transformation to SGo at all, unless they're also imported by those files.
Types ¶
This section is empty.