importer

package
v0.0.0-...-6c909a5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 24, 2018 License: MIT Imports: 16 Imported by: 0

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

func Default(files []*ast.File) types.Importer

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.

func DefaultFrom

func DefaultFrom(files []*ast.File, whence string) (types.Importer, error)

DefaultFrom is like Default, with an optional whence argument for the path to the directory from which the importing is done.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL