diff --git a/rocksdb.go b/rocksdb.go index 62a3f73..d323064 100644 --- a/rocksdb.go +++ b/rocksdb.go @@ -4,6 +4,8 @@ import ( "fmt" "log" "os" + "regexp" + "strings" "sync" "sync/atomic" "time" @@ -55,6 +57,10 @@ type Metadata struct { type ValueType int +const ( + VT_BOOL ValueType = 00000 + iota +) + const ( VT_INT ValueType = 10000 + iota VT_INT8 @@ -94,7 +100,9 @@ type Field struct { // Parse 从字符串中解析 var a int; a = 0; a < 0 && a > 5 ; func (field *Field) Parse(code string) { - + codes := strings.Split(code, ";") + re := regexp.MustCompile("var +([a-zA-Z_]+) +[a-zA-Z]+[8|16|32|64]{0,1}") + re.FindStringSubmatch(codes[0]) } // Table 表结构 diff --git a/table_test.go b/table_test.go new file mode 100644 index 0000000..4618d3c --- /dev/null +++ b/table_test.go @@ -0,0 +1,47 @@ +package main + +import ( + "regexp" + "strings" + "testing" +) + +var ReKeyDefined = regexp.MustCompile("var +([a-zA-Z_]+) +([a-zA-Z0-9]+) *(\\([0-9]+\\))") + +type parseTest struct { + PS string + Result []string +} + +func TestParseRe(t *testing.T) { + + var parseCollection []parseTest + parseCollection = append(parseCollection, + parseTest{ + PS: "var a int; a = 0 ; a >= 1 && a <= 4", + Result: []string{"a", "int"}, + }, + parseTest{ + PS: "var das_das int64; das_das = 0 ; das_das >= 1 && das_das <= 4", + Result: []string{"das_das", "int64"}, + }, + parseTest{ + PS: "var BitTkoen text; BitTkoen = 0 ; BitTkoen >= 1 && BitTkoen <= 4", + Result: []string{"BitTkoen", "text"}, + }, + parseTest{ + PS: "var BitTkoen char(24); BitTkoen = 0 ; BitTkoen >= 1 && BitTkoen <= 4", + Result: []string{"BitTkoen", "text"}, + }, + ) + + for _, parse := range parseCollection { + codes := strings.Split(parse.PS, ";") + result := ReKeyDefined.FindStringSubmatch(codes[0]) + if len(result) >= 3 && !(result[1] == parse.Result[0] && result[2] == parse.Result[1]) { + t.Error(result) + } + t.Error(result) + } + +}