示例#1
0
文件: main.go 项目: katydid/v0.1
func main() {
	gen := gen.NewFunc("serialize")
	gen(valueStr, "value.gen.go", []interface{}{
		&valuer{"Float64", "float64", "0"},
		&valuer{"Float32", "float32", "0"},
		&valuer{"Int64", "int64", "0"},
		&valuer{"Uint64", "uint64", "0"},
		&valuer{"Int32", "int32", "0"},
		&valuer{"Uint32", "uint32", "0"},
		&valuer{"Bool", "bool", "false"},
		&valuer{"String", "string", `""`},
		&valuer{"Bytes", "[]byte", "nil"},
	}, `"fmt"`)
}
示例#2
0
文件: main.go 项目: katydid/v0.1
func main() {
	gen := gen.NewFunc("compose")
	gen(composeStr, "compose.gen.go", []interface{}{
		&composer{"Float64", "SINGLE_DOUBLE", "Double", "Float64s", "LIST_DOUBLE"},
		&composer{"Float32", "SINGLE_FLOAT", "Float", "Float32s", "LIST_FLOAT"},
		&composer{"Int64", "SINGLE_INT64", "Int64", "Int64s", "LIST_INT64"},
		&composer{"Uint64", "SINGLE_UINT64", "Uint64", "Uint64s", "LIST_UINT64"},
		&composer{"Int32", "SINGLE_INT32", "Int32", "Int32s", "LIST_INT32"},
		&composer{"Uint32", "SINGLE_UINT32", "Uint32", "Uint32s", "LIST_UINT32"},
		&composer{"Bool", "SINGLE_BOOL", "Bool", "Bools", "LIST_BOOL"},
		&composer{"String", "SINGLE_STRING", "String", "Strings", "LIST_STRING"},
		&composer{"Bytes", "SINGLE_BYTES", "Bytes", "ListOfBytes", "LIST_BYTES"},
	},
		`"github.com/katydid/katydid/asm/ast"`,
		`"github.com/katydid/katydid/funcs"`,
		`"github.com/katydid/katydid/types"`)
}
示例#3
0
文件: conv-gen.go 项目: katydid/v0.1
func main() {
	gen := gen.NewFunc("conv")
	gen(convStr, "conv.gen.go", []interface{}{
		&conver{"float64", "double", "DOUBLE", "double(%f)", "0"},
		&conver{"float32", "float", "FLOAT", "float(%f)", "0"},
		&conver{"int64", "int64", "INT64", "int64(%d)", "0"},
		&conver{"uint64", "uint64", "UINT64", "uint64(%d)", "0"},
		&conver{"int32", "int32", "INT32", "int32(%d)", "0"},
		&conver{"bool", "bool", "BOOL", "%v", "false"},
		&conver{"string", "string", "STRING", "`%s`", `""`},
		&conver{"[]byte", "[]byte", "BYTES", "%#v", "nil"},
		&conver{"uint32", "uint32", "UINT32", "uint32(%d)", "0"},
	},
		`"fmt"`,
		`"github.com/katydid/katydid/asm/lexer"`,
		`"github.com/katydid/katydid/asm/parser"`,
		`"github.com/katydid/katydid/asm/ast"`,
		`"github.com/katydid/katydid/types"`,
		`"strings"`)
}
示例#4
0
文件: main.go 项目: katydid/v0.1
func main() {
	gen := gen.NewFunc("funcs")
	gen(compareStr, "compare.gen.go", []interface{}{
		&compare{"ge", ">=", "float64", ""},
		&compare{"ge", ">=", "float32", ""},
		&compare{"ge", ">=", "int64", ""},
		&compare{"ge", ">=", "uint64", ""},
		&compare{"ge", ">=", "int32", ""},
		&compare{"ge", ">=", "uint32", ""},
		&compare{"ge", "", "bytes", "return bytes.Compare(this.V1.Eval(), this.V2.Eval()) >= 0"},
		&compare{"gt", ">", "float64", ""},
		&compare{"gt", ">", "float32", ""},
		&compare{"gt", ">", "int64", ""},
		&compare{"gt", ">", "uint64", ""},
		&compare{"gt", ">", "int32", ""},
		&compare{"gt", ">", "uint32", ""},
		&compare{"gt", "", "bytes", "return bytes.Compare(this.V1.Eval(), this.V2.Eval()) > 0"},
		&compare{"le", "<=", "float64", ""},
		&compare{"le", "<=", "float32", ""},
		&compare{"le", "<=", "int64", ""},
		&compare{"le", "<=", "uint64", ""},
		&compare{"le", "<=", "int32", ""},
		&compare{"le", "<=", "uint32", ""},
		&compare{"le", "", "bytes", "return bytes.Compare(this.V1.Eval(), this.V2.Eval()) <= 0"},
		&compare{"lt", "<", "float64", ""},
		&compare{"lt", "<", "float32", ""},
		&compare{"lt", "<", "int64", ""},
		&compare{"lt", "<", "uint64", ""},
		&compare{"lt", "<", "int32", ""},
		&compare{"lt", "<", "uint32", ""},
		&compare{"lt", "", "bytes", "return bytes.Compare(this.V1.Eval(), this.V2.Eval()) < 0"},
		&compare{"eq", "==", "float64", ""},
		&compare{"eq", "==", "float32", ""},
		&compare{"eq", "==", "int64", ""},
		&compare{"eq", "==", "uint64", ""},
		&compare{"eq", "==", "int32", ""},
		&compare{"eq", "==", "uint32", ""},
		&compare{"eq", "==", "bool", ""},
		&compare{"eq", "==", "string", ""},
		&compare{"eq", "", "bytes", "return bytes.Equal(this.V1.Eval(), this.V2.Eval())"},
	}, `"bytes"`)
	gen(newFuncStr, "newfunc.gen.go", []interface{}{
		"Float64",
		"Float32",
		"Int64",
		"Uint64",
		"Int32",
		"Uint32",
		"Bool",
		"String",
		"Bytes",
		"Float64s",
		"Float32s",
		"Int64s",
		"Uint64s",
		"Int32s",
		"Uint32s",
		"Bools",
		"Strings",
		"ListOfBytes",
	})
	gen(constStr, "const.gen.go", []interface{}{
		&conster{"Float64", "float64", "double(%f)", ""},
		&conster{"Float32", "float32", "float(%f)", ""},
		&conster{"Int64", "int64", "int64(%d)", ""},
		&conster{"Uint64", "uint64", "uint64(%d)", ""},
		&conster{"Int32", "int32", "int32(%d)", ""},
		&conster{"Uint32", "uint32", "uint32(%d)", ""},
		&conster{"Bool", "bool", "%v", ""},
		&conster{"String", "string", "`%s`", ""},
		&conster{"Bytes", "[]byte", "%#v", ""},
		&conster{"Float64s", "[]float64", "double(%f)", "double"},
		&conster{"Float32s", "[]float32", "float(%f)", "float"},
		&conster{"Int64s", "[]int64", "int64(%d)", "int64"},
		&conster{"Uint64s", "[]uint64", "uint64(%d)", "uint64"},
		&conster{"Int32s", "[]int32", "int32(%d)", "int32"},
		&conster{"Uint32s", "[]uint32", "uint32(%d)", "uint32"},
		&conster{"Bools", "[]bool", "%v", "bool"},
		&conster{"Strings", "[]string", "`%s`", "string"},
		&conster{"ListOfBytes", "[][]byte", "%#v", "[]byte"},
	}, `"fmt"`, `"strings"`, `"reflect"`)
	gen(listStr, "list.gen.go", []interface{}{
		&list{"Float64s", "Float64", "float64"},
		&list{"Float32s", "Float32", "float32"},
		&list{"Int64s", "Int64", "int64"},
		&list{"Uint64s", "Uint64", "uint64"},
		&list{"Int32s", "Int32", "int32"},
		&list{"Bools", "Bool", "bool"},
		&list{"Strings", "String", "string"},
		&list{"ListOfBytes", "Bytes", "[]byte"},
		&list{"Uint32s", "Uint32", "uint32"},
	}, `"strings"`)
	gen(printStr, "print.gen.go", []interface{}{
		&printer{"Float64", "float64"},
		&printer{"Float32", "float32"},
		&printer{"Int64", "int64"},
		&printer{"Uint64", "uint64"},
		&printer{"Int32", "int32"},
		&printer{"Uint32", "uint32"},
		&printer{"Bool", "bool"},
		&printer{"String", "string"},
		&printer{"Bytes", "[]byte"},
		&printer{"Float64s", "[]float64"},
		&printer{"Float32s", "[]float32"},
		&printer{"Int64s", "[]int64"},
		&printer{"Uint64s", "[]uint64"},
		&printer{"Int32s", "[]int32"},
		&printer{"Uint32s", "[]uint32"},
		&printer{"Bools", "[]bool"},
		&printer{"Strings", "[]string"},
		&printer{"ListOfBytes", "[][]byte"},
	}, `"fmt"`)
	gen(lengthStr, "length.gen.go", []interface{}{
		"Float64s",
		"Float32s",
		"Int64s",
		"Uint64s",
		"Int32s",
		"Uint32s",
		"Bools",
		"Strings",
		"ListOfBytes",
		"String",
		"Bytes",
	})
	gen(elemStr, "elem.gen.go", []interface{}{
		&elemer{"Float64s", "float64", "Float64"},
		&elemer{"Float32s", "float32", "Float32"},
		&elemer{"Int64s", "int64", "Int64"},
		&elemer{"Uint64s", "uint64", "Uint64"},
		&elemer{"Int32s", "int32", "Int32"},
		&elemer{"Uint32s", "uint32", "Uint32"},
		&elemer{"Bools", "bool", "Bool"},
		&elemer{"Strings", "string", "String"},
		&elemer{"ListOfBytes", "[]byte", "Bytes"},
	})
	gen(rangeStr, "range.gen.go", []interface{}{
		&ranger{"Float64s", "[]float64"},
		&ranger{"Float32s", "[]float32"},
		&ranger{"Int64s", "[]int64"},
		&ranger{"Uint64s", "[]uint64"},
		&ranger{"Int32s", "[]int32"},
		&ranger{"Uint32s", "[]uint32"},
		&ranger{"Bools", "[]bool"},
		&ranger{"Strings", "[]string"},
		&ranger{"ListOfBytes", "[][]byte"},
	})
	gen(variableStr, "variable.gen.go", []interface{}{
		&printer{"Float64", "float64"},
		&printer{"Float32", "float32"},
		&printer{"Int64", "int64"},
		&printer{"Uint64", "uint64"},
		&printer{"Int32", "int32"},
		&printer{"Uint32", "uint32"},
		&printer{"Bool", "bool"},
		&printer{"String", "string"},
		&printer{"Bytes", "[]byte"},
	}, `"github.com/katydid/katydid/serialize"`)
	gen(existsStr, "exists.gen.go", []interface{}{
		&printer{"Float64", "float64"},
		&printer{"Float32", "float32"},
		&printer{"Int64", "int64"},
		&printer{"Uint64", "uint64"},
		&printer{"Int32", "int32"},
		&printer{"Uint32", "uint32"},
		&printer{"Bool", "bool"},
		&printer{"String", "string"},
		&printer{"Bytes", "[]byte"},
	})
}