TODO: 解析的正则
This commit is contained in:
parent
a0677f2451
commit
28fce16157
10
rocksdb.go
10
rocksdb.go
|
@ -4,6 +4,8 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
"regexp"
|
||||||
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
@ -55,6 +57,10 @@ type Metadata struct {
|
||||||
|
|
||||||
type ValueType int
|
type ValueType int
|
||||||
|
|
||||||
|
const (
|
||||||
|
VT_BOOL ValueType = 00000 + iota
|
||||||
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
VT_INT ValueType = 10000 + iota
|
VT_INT ValueType = 10000 + iota
|
||||||
VT_INT8
|
VT_INT8
|
||||||
|
@ -94,7 +100,9 @@ type Field struct {
|
||||||
|
|
||||||
// Parse 从字符串中解析 var a int; a = 0; a < 0 && a > 5 ;
|
// Parse 从字符串中解析 var a int; a = 0; a < 0 && a > 5 ;
|
||||||
func (field *Field) Parse(code string) {
|
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 表结构
|
// Table 表结构
|
||||||
|
|
47
table_test.go
Normal file
47
table_test.go
Normal file
|
@ -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)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user