diff --git a/condition.go b/condition.go new file mode 100644 index 0000000..c8cc5d3 --- /dev/null +++ b/condition.go @@ -0,0 +1 @@ +package crontab diff --git a/condition_test.go b/condition_test.go new file mode 100644 index 0000000..3054afa --- /dev/null +++ b/condition_test.go @@ -0,0 +1,107 @@ +package crontab + +import ( + "strings" + "testing" +) + +//xx={xx()},n>f|n > x |{w=5},5': + + case '=': + + case ' ': + i++ + } + } + + return false +} + +// func indexOperator(s string, start int) (start int, end int) { +// return 0, 1 +// } + +func parseCond(cond string) { + var CondList []Cond + + s := 0 + i := 0 + for ; i < len(cond); i++ { + + switch cond[i] { + // case '{': + // // take execute proccess + case '|': + CondList = append(CondList, Cond{expr: cond[s:i], op: "|"}) + s = i + 1 + case '&': + CondList = append(CondList, Cond{expr: cond[s:i], op: "&"}) + s = i + 1 + case ' ': + i++ + } + + } + +} + +func parseMethod(expr string) { + +} + +func parseDefine(v, method string) { + +} + +func TestBaseCond(t *testing.T) { + condExpr := "n>f|n > x |{w=5},{w=5s;}" + for _, expr := range strings.Split(condExpr, ",") { + // condexpr + for i := 0; i <= len(expr); i++ { + + if expr[i] == '{' { + s := i - 1 + for s > 0 { + switch expr[s] { + case ' ': + s-- + case '=': + // 判断 = 定义表达 + parseDefine(expr[0:s], expr[s+1:]) + default: + // 判断 = 条件表达 + parseCond(expr[0:i]) + parseMethod(expr[i:]) + } + } + // 判断 = 执行表达 + parseMethod(expr) + } + + } + + // 找不到{ 判断 = 执行表达 + parseMethod(expr) + } +}