build

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2016 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// positions
	FileHead       = "file_head"
	BeforeImport   = "before_import"
	InImport       = "in_import"
	AfterImport    = "after_import"
	BeforeConst    = "before_const"
	AfterConst     = "after_const"
	BeforeEnum     = "before_enum"
	AfterEnum      = "after_enum"
	BeforeStruct   = "before_struct"
	AfterStruct    = "after_struct"
	BeforeProtocol = "before_protocol"
	AfterProtocol  = "after_protocol"
	BeforeService  = "before_service"
	AfterService   = "after_service"

	// Extention config filename
	ExtConfigFilename = "ext.json"
)

Variables

View Source
var (
	ErrAmbiguousNames = errors.New("ambiguous names")
)
View Source
var (
	ErrExtensionName = errors.New("invalid extension name")
)

Functions

func BuildComment

func BuildComment(comment *ast.CommentGroup) string

func BuildDoc

func BuildDoc(doc *ast.CommentGroup) string

helper functions

func BuildIdent

func BuildIdent(ident *ast.Ident) string

func BuildIdentList

func BuildIdentList(idents []*ast.Ident) []string

func ParseFlags

func ParseFlags() (plugin Plugin, config PluginRuntimeConfig, builder *Builder, err error)

Types

type ArrayType

type ArrayType struct {
	TypeBase
	T    Type
	Size Expr
}

func BuildArray

func BuildArray(t *ast.ArrayType) *ArrayType

type BasicLit

type BasicLit struct {
	Kind  lexer.Token
	Value string
}

func BuildBasicLit

func BuildBasicLit(lit *ast.BasicLit) *BasicLit

func (BasicLit) ExprNode

func (BasicLit) ExprNode()

type BasicType

type BasicType struct {
	TypeBase
	Name string
}

type Bean

type Bean struct {
	Kind    string
	Doc     string
	Name    string
	Fields  []*Field
	Comment string
}

func BuildBean

func BuildBean(bean *ast.BeanDecl) *Bean

func (Bean) Extends

func (bean Bean) Extends() []Type

func (Bean) Field

func (bean Bean) Field(i int) *Field

func (Bean) NumField

func (bean Bean) NumField() int

type Builder

type Builder struct {
	Packages map[string]*Package
	// contains filtered or unexported fields
}

Builder

func Build

func Build(pkgs map[string]*ast.Package, importPaths []string) (*Builder, error)

func NewBuilder

func NewBuilder() *Builder

func (*Builder) Decode

func (builder *Builder) Decode(s string) error

func (*Builder) Encode

func (builder *Builder) Encode() string

type ConstSpec

type ConstSpec struct {
	Doc     string
	Name    string
	Value   Expr
	Comment string
}

func BuildConstSpec

func BuildConstSpec(spec *ast.ConstSpec) *ConstSpec

func (ConstSpec) ValueString

func (c ConstSpec) ValueString() string

type EmbeddedPosition

type EmbeddedPosition string

func (EmbeddedPosition) IsValid

func (pos EmbeddedPosition) IsValid() bool

func (EmbeddedPosition) Match

func (pos EmbeddedPosition) Match(kind, at string) bool

type EmbeddedValue

type EmbeddedValue struct {
	Text     string `join:"text"`
	Template string `json:"template"`
}

func (EmbeddedValue) IsValid

func (v EmbeddedValue) IsValid() bool

type Expr

type Expr interface {
	ExprNode()
}

func BuildExpr

func BuildExpr(expr ast.Expr) Expr

type ExprBase

type ExprBase struct{}

func (ExprBase) ExprNode

func (ExprBase) ExprNode()

type Extention

type Extention struct {
	Name    string `json:"name"`
	Author  string `json:"author"`
	URL     string `json:"url"`
	Version string `json:"version"`
	// language -> position -> embedded_values
	EmbeddedAt map[string]map[EmbeddedPosition][]EmbeddedValue `json:"at"`

	Path string `json:"path"`
}

func LoadExtensions

func LoadExtensions(rootdir string, names []string) ([]Extention, error)

func (Extention) Find

func (e Extention) Find(lang, kind, at string) []EmbeddedValue

type ExtentionKey

type ExtentionKey struct {
	Author string
	Name   string
}

func GetExtentionKey

func GetExtentionKey(name string) (ExtentionKey, error)

func (ExtentionKey) Path

func (key ExtentionKey) Path(rootdir string) string

func (ExtentionKey) Subdir

func (key ExtentionKey) Subdir() string

type Field

type Field struct {
	Doc     string
	Options []string
	Type    Type
	Names   []string
	Default Expr
	Tag     Tag
	Comment string
}

func BuildField

func BuildField(field *ast.Field) *Field

func BuildFieldList

func BuildFieldList(fields *ast.FieldList) []*Field

func (*Field) AddTag

func (field *Field) AddTag(key, value string)

func (Field) GetTag

func (field Field) GetTag(key string) string

func (Field) HasTag

func (field Field) HasTag(key string) bool

func (Field) IsExtended

func (field Field) IsExtended() bool

func (Field) Name

func (field Field) Name() (string, error)

func (Field) Value

func (field Field) Value() string

type File

type File struct {
	Filename   string
	Doc        string
	Package    string
	Beans      []*Bean
	Decls      []*GenDecl
	Unresolved []string
}

func BuildFile

func BuildFile(file *ast.File) *File

type FuncType

type FuncType struct {
	TypeBase
	Params []*Field
	Result Type
}

func BuildFunc

func BuildFunc(t *ast.FuncType) *FuncType

type GenDecl

type GenDecl struct {
	Doc     string
	Imports []*ImportSpec
	Consts  []*ConstSpec
}

func BuildGenDecl

func BuildGenDecl(decl *ast.GenDecl) *GenDecl

type Ident

type Ident string

func (Ident) ExprNode

func (Ident) ExprNode()

type ImportSpec

type ImportSpec struct {
	Doc     string
	Name    string
	Package string
	Comment string
}

func BuildImportSpec

func BuildImportSpec(spec *ast.ImportSpec) *ImportSpec

type MapType

type MapType struct {
	TypeBase
	K Type
	V Type
}

func BuildMap

func BuildMap(t *ast.MapType) *MapType

type ObjectId

type ObjectId string

func (ObjectId) IsValid

func (id ObjectId) IsValid() bool

func (ObjectId) Name

func (id ObjectId) Name() string

func (ObjectId) Package

func (id ObjectId) Package() string

func (ObjectId) String

func (id ObjectId) String() string

type Package

type Package struct {
	Name    string
	Imports map[string]string
	Files   map[string]*File
}

func BuildPackage

func BuildPackage(pkg *ast.Package) *Package

type Plugin

type Plugin struct {
	Lang         string `json:"lang"`
	Name         string `json:"name"`
	Bin          string `json:"bin"`
	TemplatesDir string `json:"templates,omitempty"`

	RuntimeConfig PluginRuntimeConfig `json:"-"`
}

func (Plugin) Generate

func (plugin Plugin) Generate(builder *Builder, stdout, stderr io.Writer) error

func (*Plugin) Init

func (plugin *Plugin) Init() error

type PluginRuntimeConfig

type PluginRuntimeConfig struct {
	Verbose       string
	Outdir        string
	ExtentionsDir string
	Extentions    []Extention
	Envvars       map[string]string
}

func (*PluginRuntimeConfig) BoolEnv

func (config *PluginRuntimeConfig) BoolEnv(name string) bool

func (*PluginRuntimeConfig) Decode

func (config *PluginRuntimeConfig) Decode(s string) error

func (PluginRuntimeConfig) Encode

func (config PluginRuntimeConfig) Encode() string

func (*PluginRuntimeConfig) FloatEnv

func (config *PluginRuntimeConfig) FloatEnv(name string) float64

func (*PluginRuntimeConfig) Getenv

func (config *PluginRuntimeConfig) Getenv(name string) string

func (*PluginRuntimeConfig) IntEnv

func (config *PluginRuntimeConfig) IntEnv(name string) int64

func (*PluginRuntimeConfig) UintEnv

func (config *PluginRuntimeConfig) UintEnv(name string) uint64

type PluginSet

type PluginSet struct {
	// contains filtered or unexported fields
}

func NewPluginSet

func NewPluginSet() *PluginSet

func (*PluginSet) Len

func (pset *PluginSet) Len() int

func (*PluginSet) Lookup

func (pset *PluginSet) Lookup(lang string) (*Plugin, bool)

func (*PluginSet) Register

func (pset *PluginSet) Register(plugin Plugin) error

type StructType

type StructType struct {
	TypeBase
	Package string
	Name    string
}

func BuildStruct

func BuildStruct(t *ast.StructType) *StructType

type Tag

type Tag string

func BuildTag

func BuildTag(tag *ast.BasicLit) Tag

func (Tag) Get

func (tag Tag) Get(key string) string

func (Tag) Lookup

func (tag Tag) Lookup(key string) (value string, ok bool)

func (*Tag) Set

func (tag *Tag) Set(key, value string)

type Type

type Type interface {
	Expr
	TypeNode()
}

func BuildType

func BuildType(typ ast.Type) Type

type TypeBase

type TypeBase struct {
	ExprBase
}

func (TypeBase) TypeNode

func (TypeBase) TypeNode()

type VectorType

type VectorType struct {
	TypeBase
	T Type
}

func BuildVector

func BuildVector(t *ast.VectorType) *VectorType

Jump to

Keyboard shortcuts

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