generator

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2022 License: MulanPSL-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ArrGenerator = []*Generator{}
View Source
var ArrParser = []*Parser{}
View Source
var GlobalTemplateConfig = &TemplateConfig{
	OverrideMap: make(map[string]string, 16),
	Import:      make(map[string]string, 16),
}
View Source
var RootTemplate *template.Template

Functions

func ForeachPluginGenerators added in v0.2.0

func ForeachPluginGenerators(list []string, f func(p *PluginGenerator)) error

func LoadAllTemplate added in v0.3.0

func LoadAllTemplate() error

func RegPluginGenerator added in v0.2.0

func RegPluginGenerator(pg *PluginGenerator)

func RegTemplateFunc added in v0.3.0

func RegTemplateFunc(name string, fm template.FuncMap)

func RegTemplateHeader added in v0.3.0

func RegTemplateHeader(h *TemplateDefine)

func UtilJoinDocCommentIndent added in v0.3.0

func UtilJoinDocCommentIndent(ss []string, commentTag string, indent string) string

Types

type ConstValue

type ConstValue struct {
	Name    string `json:"name,omitempty"`
	Value   uint32 `json:"value"`
	Comment string `json:"comment,omitempty"`
}

type DefineST

type DefineST struct {
	Name   string                    `json:"name,omitempty"`
	Fields map[string]*DefineSTField `json:"fields,omitempty"`

	IsMessage bool `json:"isMessage,omitempty"`

	Doc    []string               `json:"doc,omitempty"`
	Option map[string]interface{} `json:"option,omitempty"`
}

type DefineSTField added in v0.3.0

type DefineSTField struct {
	BuiltinType reflect.Kind `json:"builtinType,omitempty"`
	CustomType  string       `json:"customType,omitempty"` //DefineST.Name

	IsArray bool `json:"isArray,omitempty"`

	IsMap  bool         `json:"isMap,omitempty"`
	MapKey reflect.Kind `json:"mapKey,omitempty"`

	FromPackage string `json:"fromPackage,omitempty"`

	OriginalTypeStr string `json:"originalTypeStr,omitempty"`

	Doc     []string               `json:"doc,omitempty"`
	Comment string                 `json:"comment,omitempty"`
	Option  map[string]interface{} `json:"option,omitempty"`
}

type File

type File struct {
	Name string `json:"name,omitempty"`

	//结构定义
	DefineST []*DefineST `json:"defineST,omitempty"`
	//协议号定义
	ProtoID map[uint32]*ConstValue `json:"protoID,omitempty"`
	//错误码定义
	ErrCode map[uint32]*ConstValue `json:"errCode,omitempty"`
	//其他常量定义
	Const map[uint32]*ConstValue `json:"const,omitempty"`

	//原型包名
	PackageName string `json:"packageName,omitempty"`
	//原型包引用关系: 包名=>包路径 (含义由解析器确保)
	PackageImport map[string]string `json:"packageImport,omitempty"`

	Doc    []string               `json:"doc,omitempty"`
	Option map[string]interface{} `json:"option,omitempty"`
}

type Generator

type Generator struct {
	Lang  string
	Proto string

	NewConfig func() GeneratorConfig
	Generate  func(oc GeneratorConfig, pSet *PrototypeSet) error

	ArrTemplateDataDefine []*TemplateDataDefine
}

func GetGenerator added in v0.3.0

func GetGenerator(lang, proto string) *Generator

type GeneratorConfig

type GeneratorConfig interface{}

type Message

type Message struct {
	//必须有一个相同名称的DefineST
	Name        string `json:"name,omitempty"`
	ProtoIDName string `json:"protoIDName,omitempty"`

	Option map[string]interface{} `json:"option,omitempty"`
}

type Parser

type Parser struct {
	Name      string
	NewConfig func() ParserConfig
	Parse     func(oc ParserConfig) (*PrototypeSet, error)
}

func GetParser added in v0.3.0

func GetParser(name string) *Parser

type ParserConfig

type ParserConfig interface{}

type PluginFuncAppendConstFile added in v0.3.0

type PluginFuncAppendConstFile func(tmplData *TmplDataConstFile, pSet *PrototypeSet)

type PluginFuncAppendDefineField added in v0.2.0

type PluginFuncAppendDefineField func(tmplData *TmplDataDefineSTField, pSet *PrototypeSet, cursor *DefineSTField)

type PluginFuncAppendDefineST added in v0.2.0

type PluginFuncAppendDefineST func(tmplData *TmplDataDefineST, pSet *PrototypeSet, cursor *DefineST)

type PluginFuncAppendFile added in v0.2.0

type PluginFuncAppendFile func(tmplData *TmplDataProtoFile, pSet *PrototypeSet, cursor *File)

type PluginFuncAppendMessage added in v0.2.0

type PluginFuncAppendMessage func(tmplData *TmplDataMessage, pSet *PrototypeSet, cursor *Message)

type PluginGenerator added in v0.2.0

type PluginGenerator struct {
	Name string

	AppendFile        PluginFuncAppendFile
	AppendMessage     PluginFuncAppendMessage
	AppendDefineST    PluginFuncAppendDefineST
	AppendDefineField PluginFuncAppendDefineField
	AppendConstFile   PluginFuncAppendConstFile
}

func GetPluginGenerator added in v0.2.0

func GetPluginGenerator(name string) *PluginGenerator

type PrototypeSet

type PrototypeSet struct {
	RootDir  string                 `json:"rootDir,omitempty"`
	File     map[string]*File       `json:"file,omitempty"`
	Message  map[string]*Message    `json:"message,omitempty"`
	DefineST map[string]*DefineST   `json:"defineST,omitempty"`
	ProtoID  map[uint32]*ConstValue `json:"protoID,omitempty"`
	ErrCode  map[uint32]*ConstValue `json:"errCode,omitempty"`
}

type TemplateConfig added in v0.3.0

type TemplateConfig struct {
	OverrideMap map[string]string `json:"overrideMap,omitempty"`
	Import      map[string]string `json:"import,omitempty"`
}

type TemplateDataDefine added in v0.3.0

type TemplateDataDefine struct {
	Name   string
	Sample interface{}
}

func ArrTemplateDataDefine added in v0.3.0

func ArrTemplateDataDefine() []*TemplateDataDefine

type TemplateDefine added in v0.3.0

type TemplateDefine struct {
	Name             string `json:"name,omitempty"`
	Filepath         string `json:"filepath,omitempty"`
	WantTemplateData string `json:"wantTemplateData,omitempty"`

	BuiltinTemplateText string `json:"builtinTemplateText,omitempty"`

	Template *template.Template `json:"template,omitempty"`

	ActualFilepath     string `json:"actualFilepath,omitempty"`
	ActualTemplateText string `json:"actualTemplateText,omitempty"`
}

func ArrTemplateHeader added in v0.3.0

func ArrTemplateHeader() []*TemplateDefine

func GetTemplateHeader added in v0.3.0

func GetTemplateHeader(name string) *TemplateDefine

func (*TemplateDefine) PrepareActual added in v0.3.0

func (h *TemplateDefine) PrepareActual() error

type TmplDataConstFile added in v0.3.0

type TmplDataConstFile struct {
	CFListProtoID   []*TmplDataConstValue
	CFListErrorCode []*TmplDataConstValue
	CFListConst     []*TmplDataConstValue

	CFOption  map[string]interface{}
	CFPlugins map[string]interface{} //插件参数
}

内置模板参数: 常量文件

func PrepareTmplDataConstFile added in v0.3.0

func PrepareTmplDataConstFile(p *PrototypeSet) *TmplDataConstFile

原型转化模板参数基本型: 常量文件

type TmplDataConstValue added in v0.3.0

type TmplDataConstValue struct {
	//应该只有其中一个上游
	SuperConstFile *TmplDataConstFile
	SuperProtoFile *TmplDataProtoFile

	ConstName        string
	ConstValue       uint32
	ConstLineComment string

	ConstOption  map[string]interface{}
	ConstPlugins map[string]interface{} //插件参数

	ConstLineCommentIndent string
}

内置模板参数: 常量定义

func PrepareTmplDataConstValue added in v0.3.0

func PrepareTmplDataConstValue(p *ConstValue) *TmplDataConstValue

原型转化模板参数基本型: 常量值

type TmplDataDefineST added in v0.3.0

type TmplDataDefineST struct {
	SuperProtoFile *TmplDataProtoFile

	STName       string   //结构名称
	STDocComment []string //结构注释

	STMessage *TmplDataMessage //若结构为消息时有值

	STFields []*TmplDataDefineSTField

	STOption  map[string]interface{}
	STPlugins map[string]interface{} //插件参数

	STDocCommentIndent string //经过预处理的结构注释
}

内置模板参数: 结构定义

func PrepareTmplDataDefineST added in v0.3.0

func PrepareTmplDataDefineST(p *DefineST) *TmplDataDefineST

原型转化模板参数基本型: 结构定义

type TmplDataDefineSTField added in v0.3.0

type TmplDataDefineSTField struct {
	SuperDefineST *TmplDataDefineST

	FieldName        string   //字段名称
	FieldDocComment  []string //字段注释
	FieldLineComment string   //字段行尾注释

	FieldTypeStr      string //类型字符串, 应为输出语言整理过的类型字符串, 不应包含各类限定词或辅助描述符
	FieldIsArray      bool
	FieldIsMap        bool
	FieldIsCustomType bool
	FieldValueType    string //类型字符串, 同时也是Array的元素类型, 和Map的值类型, 用于生成器装填转化过的类型字符串
	FieldKeyType      string //Map类型的key类型字符串, 用于生成器装填转化过的类型字符串

	FieldFromPackage       string
	FieldFromPackagePrefix string

	FieldOriginalTypeStr string //类型的原始字符串, 应等于解析源文件的类型描述符

	FieldNullable bool //可以为空, 表示可以不初始化

	FieldOption  map[string]interface{}
	FieldPlugins map[string]interface{} //插件参数

	FieldDocCommentIndent  string //经过预处理的字段注释
	FieldLineCommentIndent string //经过预处理的行尾注释
}

内置模板参数: 字段定义

func PrepareTmplDataDefineSTField added in v0.3.0

func PrepareTmplDataDefineSTField(p *DefineSTField, name string) *TmplDataDefineSTField

原型转化模板参数基本型: 字段定义

type TmplDataMessage added in v0.3.0

type TmplDataMessage struct {
	//消息的结构定义
	MessageDefineST *TmplDataDefineST

	//消息的协议号名称
	MessageProtoIDName string

	MessageOption  map[string]interface{}
	MessagePlugins map[string]interface{} //插件参数
}

内置模板参数: 消息定义

func PrepareTmplDataMessage added in v0.3.0

func PrepareTmplDataMessage(p *Message, df *TmplDataDefineST) *TmplDataMessage

原型转化模板参数基本型: 消息定义

type TmplDataProtoFile added in v0.3.0

type TmplDataProtoFile struct {
	PFName string

	PFDocComment []string

	PFListDefineST []*TmplDataDefineST
	PFListProtoID  []*TmplDataConstValue
	PFListConst    []*TmplDataConstValue

	PFOption  map[string]interface{}
	PFPlugins map[string]interface{} //插件参数

	PFPackageName   string
	PFPackageImport map[string]string

	PFCodeTextDefineST []string
	PFDocCommentIndent string //经过预处理的文件注释
}

内置模板参数: 协议文件

func PrepareTmplDataProtoFile added in v0.3.0

func PrepareTmplDataProtoFile(f *File, pSet *PrototypeSet) *TmplDataProtoFile

原型转化模板参数基本型: 协议文件

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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