definition

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2024 License: MulanPSL-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var GlobalConfig = &Config{
	Verbose: false,
}
View Source
var PredefineTemplateFunc = template.FuncMap{
	"BytesToString": func(bs []byte) string { return string(bs) },

	"StringsToLower":      strings.ToLower,
	"StringsToUpper":      strings.ToUpper,
	"StringsCompare":      strings.Compare,
	"StringsContains":     strings.Contains,
	"StringsContainsAny":  strings.ContainsAny,
	"StringsCount":        strings.Count,
	"StringsFields":       strings.Fields,
	"StringsHasPrefix":    strings.HasPrefix,
	"StringsHasSuffix":    strings.HasSuffix,
	"StringsIndex":        strings.Index,
	"StringsIndexAny":     strings.IndexAny,
	"StringsJoin":         strings.Join,
	"StringsLastIndex":    strings.LastIndex,
	"StringsLastIndexAny": strings.LastIndexAny,
	"StringsRepeat":       strings.Repeat,
	"StringsReplace":      strings.Replace,
	"StringsReplaceAll":   strings.ReplaceAll,
	"StringsSplit":        strings.Split,
	"StringsSplitN":       strings.SplitN,
	"StringsSplitAfter":   strings.SplitAfter,
	"StringsSplitAfterN":  strings.SplitAfterN,
	"StringsToTitle":      strings.ToTitle,
	"StringsTrim":         strings.Trim,
	"StringsTrimLeft":     strings.TrimLeft,
	"StringsTrimPrefix":   strings.TrimPrefix,
	"StringsTrimRight":    strings.TrimRight,
	"StringsTrimSpace":    strings.TrimSpace,
	"StringsTrimSuffix":   strings.TrimSuffix,

	"StrconvFormatInt":   strconv.FormatInt,
	"StrconvFormatUint":  strconv.FormatUint,
	"StrconvFormatFloat": strconv.FormatFloat,
	"StrconvFormatBool":  strconv.FormatBool,
	"StrconvItoa":        strconv.Itoa,

	"StringsToFirstUpper": func(str string) string {
		if len(str) == 0 {
			return str
		}
		return strings.ToUpper(str[0:1]) + str[1:]
	},
}
View Source
var Symbols = map[string]map[string]reflect.Value{}

self package symbols

Functions

func DoGenerate

func DoGenerate(ctx *Context) error

执行生成

func DoParse

func DoParse(ctx *Context) error

执行解析

func ForeachFileRecursively

func ForeachFileRecursively(dir string, check func(string) bool, fn func(dir, filename string) error) error

func LoadScript

func LoadScript(ctx *Context) error

func LoadTemplate

func LoadTemplate(ctx *Context) error

func RegGenerator

func RegGenerator(generator Generator)

func RegParser

func RegParser(parser Parser)

Types

type Config

type Config struct {
	Verbose bool        `yaml:"verbose,omitempty"`
	Cmd     interface{} `yaml:"cmd,omitempty"`

	Parser    *ParserConfig    `yaml:"parser,omitempty"`
	Generator *GeneratorConfig `yaml:"generator,omitempty"`
	Template  *TemplateConfig  `yaml:"template,omitempty"`
	Script    *ScriptConfig    `yaml:"script,omitempty"`
}

func (*Config) Name

func (*Config) Name() string

func (*Config) ToDefault

func (*Config) ToDefault(cfg config.IConfigDefault)

type Context

type Context struct {
	DFSet *DFSet

	Template *TemplateManager

	FuncConfigModify []FConfigModify
	FuncParsePre     []FParsePre
	FuncParsePost    []FParsePost
	FuncGeneratePre  []FGeneratePre
	FuncGeneratePost []FGeneratePost
	FuncTemplateFunc []FTemplateFunc
}

func NewContext

func NewContext() *Context

func (*Context) AddDefinedFile

func (ctx *Context) AddDefinedFile(df *DFFile)

type DFEnum

type DFEnum struct {
	Name       string
	SourceFile string
	Options    map[string]string
	Values     []*DFEnumValue

	Comment string
}

type DFEnumValue

type DFEnumValue struct {
	Name    string
	Options map[string]string
	Value   string

	Comment string
}

type DFFieldType

type DFFieldType struct {
	ValueType DFType
	KeyType   *DFType

	IsArray bool
	IsMap   bool
}

type DFFile

type DFFile struct {
	Name    string
	Path    string
	Options map[string]string

	Enums   []*DFEnum
	Structs []*DFStruct

	Comment string
}

type DFSet

type DFSet struct {
	Files []*DFFile
	// contains filtered or unexported fields
}

func NewDFSet

func NewDFSet() *DFSet

func (*DFSet) GetFileByPath

func (set *DFSet) GetFileByPath(path string) *DFFile

type DFStruct

type DFStruct struct {
	Name       string
	SourceFile string
	Options    map[string]string

	Fields []*DFStructField
	OneOfs []*DFStructOneOf

	Comment string
}

func (*DFStruct) GetField

func (ds *DFStruct) GetField(name string) *DFStructField

func (*DFStruct) GetOneOf

func (ds *DFStruct) GetOneOf(name string) *DFStructOneOf

type DFStructField

type DFStructField struct {
	Name    string
	Options map[string]string

	FieldType DFFieldType

	Comment string
}

type DFStructOneOf

type DFStructOneOf struct {
	Name    string
	Options map[string]string
	Fields  []*DFStructField

	Comment string
}

type DFType

type DFType struct {
	Source string

	IsEnum   bool
	IsStruct bool
}

type FConfigModify

type FConfigModify func(cfg *Config) error

type FGeneratePost

type FGeneratePost func(ctx *Context) error

type FGeneratePre

type FGeneratePre func(ctx *Context) error

type FParsePost

type FParsePost func(ctx *Context) error

type FParsePre

type FParsePre func(ctx *Context) error

type FTemplateFunc

type FTemplateFunc func() template.FuncMap

type Generator

type Generator interface {
	Name() string
	Make() (Generator, error)
	Generate(*Context) error
}

type GeneratorConfig

type GeneratorConfig struct {
	GenRoot string `yaml:"genRoot,omitempty"`

	Plugins map[string]interface{} `yaml:"plugins,omitempty"`
}

func (*GeneratorConfig) Name

func (*GeneratorConfig) Name() string

func (*GeneratorConfig) ToDefault

func (*GeneratorConfig) ToDefault(cfg config.IConfigDefault)

type Parser

type Parser interface {
	Name() string
	Make() (Parser, error)
	Parse(*Context) error
}

type ParserConfig

type ParserConfig struct {
	Dir           []string `yaml:"dir,omitempty"`
	DefineSetFile string   `yaml:"defineSetFile,omitempty"`

	Plugins map[string]interface{} `yaml:"plugins,omitempty"`
}

func (*ParserConfig) Name

func (*ParserConfig) Name() string

func (*ParserConfig) ToDefault

func (*ParserConfig) ToDefault(cfg config.IConfigDefault)

type ScriptConfig

type ScriptConfig struct {
	GoPath    string
	ImportPkg []string

	PrepareExec string
	PrepareArgs []string
}

func (*ScriptConfig) Name

func (*ScriptConfig) Name() string

func (*ScriptConfig) ToDefault

func (*ScriptConfig) ToDefault(cfg config.IConfigDefault)

type ScriptPackage

type ScriptPackage struct {
	ConfigModifyFunc []FConfigModify

	ParsePreFunc  []FParsePre
	ParsePostFunc []FParsePost

	GeneratePreFunc  []FGeneratePre
	GeneratePostFunc []FGeneratePost

	TemplateFunc []FTemplateFunc
}

type TemplateConfig

type TemplateConfig struct {
	Dir []string `yaml:"dir,omitempty"`

	Ext []string `yaml:"ext,omitempty"`
}

func (*TemplateConfig) Name

func (*TemplateConfig) Name() string

func (*TemplateConfig) ToDefault

func (*TemplateConfig) ToDefault(cfg config.IConfigDefault)

type TemplateManager

type TemplateManager struct {
	Config *TemplateConfig

	RootTemplate *template.Template
}

func NewTemplateManager

func NewTemplateManager() *TemplateManager

Jump to

Keyboard shortcuts

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