save
This commit is contained in:
parent
5d7d9fc547
commit
cc9071bc70
|
@ -1,17 +1,52 @@
|
||||||
package crontab
|
package crontab
|
||||||
|
|
||||||
func Add(v1, v2 interface{}) interface{} {
|
func Add(v ...interface{}) interface{} {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func Sub(v1, v2 interface{}) interface{} {
|
func Sub(v ...interface{}) interface{} {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func Div(v1, v2 interface{}) interface{} {
|
func Div(v ...interface{}) interface{} {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func Mul(v1, v2 interface{}) interface{} {
|
func Mul(v ...interface{}) interface{} {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Or(v ...interface{}) interface{} {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func And(v ...interface{}) interface{} {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func parseConditionExpr(condExpr string) []string {
|
||||||
|
|
||||||
|
var conds []string
|
||||||
|
OpenClose := 0
|
||||||
|
cur := 0
|
||||||
|
i := 0
|
||||||
|
for ; i < len(condExpr); i++ {
|
||||||
|
switch condExpr[i] {
|
||||||
|
case ',':
|
||||||
|
if OpenClose == 0 {
|
||||||
|
conds = append(conds, condExpr[cur:i])
|
||||||
|
cur = i + 1
|
||||||
|
}
|
||||||
|
case '(':
|
||||||
|
OpenClose++
|
||||||
|
case ')':
|
||||||
|
OpenClose--
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if cur < i {
|
||||||
|
conds = append(conds, condExpr[cur:i])
|
||||||
|
}
|
||||||
|
|
||||||
|
return conds
|
||||||
|
}
|
||||||
|
|
|
@ -1,306 +1,299 @@
|
||||||
package crontab
|
package crontab
|
||||||
|
|
||||||
import (
|
// import (
|
||||||
"log"
|
// "strconv"
|
||||||
"strconv"
|
// "testing"
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/davecgh/go-spew/spew"
|
// "github.com/davecgh/go-spew/spew"
|
||||||
)
|
// )
|
||||||
|
|
||||||
//xx={xx()},n>f|n > x |{w=5},5<f<8{w=5s;},
|
// //xx={xx()},n>f|n > x |{w=5},5<f<8{w=5s;},
|
||||||
|
|
||||||
// Condition 条件表达式的结构实例
|
// // Condition 条件表达式的结构实例
|
||||||
type Condition struct {
|
// type Condition struct {
|
||||||
execList []Execute
|
// execList []Execute
|
||||||
}
|
|
||||||
|
|
||||||
type Cond struct {
|
|
||||||
expr string
|
|
||||||
op string
|
|
||||||
}
|
|
||||||
|
|
||||||
type Execute struct {
|
|
||||||
conds []Cond
|
|
||||||
calls []*Call
|
|
||||||
}
|
|
||||||
|
|
||||||
type CondExec struct {
|
|
||||||
params []interface{}
|
|
||||||
execType int
|
|
||||||
}
|
|
||||||
|
|
||||||
func (cond *Cond) Execute() bool {
|
|
||||||
i := 0
|
|
||||||
|
|
||||||
var ce []CondExec
|
|
||||||
for ; i < len(cond.expr); i++ {
|
|
||||||
|
|
||||||
switch cond.expr[i] {
|
|
||||||
case '(': // 函数方法
|
|
||||||
ce = append(ce)
|
|
||||||
case '<':
|
|
||||||
|
|
||||||
case '>':
|
|
||||||
|
|
||||||
case '=':
|
|
||||||
|
|
||||||
case ' ':
|
|
||||||
i++
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
// func indexOperator(s string, start int) (start int, end int) {
|
|
||||||
// return 0, 1
|
|
||||||
// }
|
// }
|
||||||
|
|
||||||
func parseCond(cond string) []Cond {
|
// type Cond struct {
|
||||||
var CondList []Cond
|
// expr string
|
||||||
|
// op string
|
||||||
|
// }
|
||||||
|
|
||||||
s := 0
|
// type Execute struct {
|
||||||
i := 0
|
// conds []*Call
|
||||||
for ; i < len(cond); i++ {
|
// calls []*Call
|
||||||
|
// }
|
||||||
|
|
||||||
switch cond[i] {
|
// // func indexOperator(s string, start int) (start int, end int) {
|
||||||
// case '{':
|
// // return 0, 1
|
||||||
// // 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++
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
// var VarDict = make(map[string]interface{})
|
||||||
|
// var FuncDict = make(map[string]func(vars ...interface{}) interface{})
|
||||||
|
|
||||||
if s < i {
|
// func init() {
|
||||||
CondList = append(CondList, Cond{expr: cond[s:i], op: ""})
|
// VarDict["w"] = float64(2.0)
|
||||||
}
|
// VarDict["f"] = float64(0.0)
|
||||||
|
// VarDict["s"] = float64(0.0)
|
||||||
|
// }
|
||||||
|
|
||||||
return CondList
|
// func parseFunc(fname string) func(...interface{}) interface{} {
|
||||||
}
|
// return FuncDict[fname]
|
||||||
|
// }
|
||||||
|
|
||||||
type Method struct {
|
// func parseVar(v string) float64 {
|
||||||
expr string
|
// fvar, err := strconv.ParseFloat(v, 64)
|
||||||
exec []string
|
// if err != nil {
|
||||||
}
|
// return VarDict[v].(float64)
|
||||||
|
// }
|
||||||
|
// return fvar
|
||||||
|
// }
|
||||||
|
|
||||||
var VarDict = make(map[string]interface{})
|
// type Operator struct {
|
||||||
var FuncDict = make(map[string]func(vars ...interface{}) interface{})
|
// Value interface{}
|
||||||
|
// Operate func(v1, v2 interface{}) interface{}
|
||||||
|
// }
|
||||||
|
|
||||||
func parseFunc(fname string) func(...interface{}) interface{} {
|
// func parseExpr(e string) []Operator {
|
||||||
return FuncDict[fname]
|
// i := 1
|
||||||
}
|
// s := 1
|
||||||
|
|
||||||
func parseVar(v string) float64 {
|
// isCall := false
|
||||||
fvar, err := strconv.ParseFloat(v, 64)
|
// // isVar := false
|
||||||
if err != nil {
|
|
||||||
return *VarDict[v].(*float64)
|
|
||||||
}
|
|
||||||
return fvar
|
|
||||||
}
|
|
||||||
|
|
||||||
func parseExpr(e string) []interface{} {
|
// var ops []Operator
|
||||||
i := 1
|
|
||||||
s := 1
|
|
||||||
|
|
||||||
isCall := false
|
// for ; i < len(e); i++ {
|
||||||
// isVar := false
|
// switch e[i] {
|
||||||
|
// case '(':
|
||||||
|
// isCall = true
|
||||||
|
// case '+':
|
||||||
|
// if isCall {
|
||||||
|
// ops = append(ops, Operator{Value: parseCall(e[s:i]), Operate: Add})
|
||||||
|
// } else {
|
||||||
|
// ops = append(ops, Operator{Value: parseVar(e[s:i]), Operate: Add})
|
||||||
|
// }
|
||||||
|
|
||||||
for ; i < len(e); i++ {
|
// s = i + 1
|
||||||
switch e[i] {
|
// isCall = false
|
||||||
case '(':
|
|
||||||
isCall = true
|
|
||||||
case '+':
|
|
||||||
if isCall {
|
|
||||||
parseCall(e[s:i])
|
|
||||||
} else {
|
|
||||||
parseVar(e[s:i])
|
|
||||||
}
|
|
||||||
|
|
||||||
s = i + 1
|
// case '-':
|
||||||
isCall = false
|
// if isCall {
|
||||||
case '-':
|
// ops = append(ops, Operator{Value: parseCall(e[s:i]), Operate: Sub})
|
||||||
if isCall {
|
// } else {
|
||||||
parseCall(e[s:i])
|
// ops = append(ops, Operator{Value: parseVar(e[s:i]), Operate: Sub})
|
||||||
} else {
|
// }
|
||||||
parseVar(e[s:i])
|
|
||||||
}
|
|
||||||
|
|
||||||
s = i + 1
|
// s = i + 1
|
||||||
isCall = false
|
// isCall = false
|
||||||
case '*':
|
// case '*':
|
||||||
if isCall {
|
// if isCall {
|
||||||
parseCall(e[s:i])
|
// ops = append(ops, Operator{Value: parseCall(e[s:i]), Operate: Mul})
|
||||||
} else {
|
// } else {
|
||||||
parseVar(e[s:i])
|
// ops = append(ops, Operator{Value: parseVar(e[s:i]), Operate: Mul})
|
||||||
}
|
// }
|
||||||
|
|
||||||
s = i + 1
|
// s = i + 1
|
||||||
isCall = false
|
// isCall = false
|
||||||
case '/':
|
// case '/':
|
||||||
if isCall {
|
// if isCall {
|
||||||
parseCall(e[s:i])
|
// ops = append(ops, Operator{Value: parseCall(e[s:i]), Operate: Div})
|
||||||
} else {
|
// } else {
|
||||||
parseVar(e[s:i])
|
// ops = append(ops, Operator{Value: parseVar(e[s:i]), Operate: Div})
|
||||||
}
|
// }
|
||||||
|
|
||||||
s = i + 1
|
// s = i + 1
|
||||||
isCall = false
|
// isCall = false
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
// case '>':
|
||||||
}
|
|
||||||
|
|
||||||
func parseCallParams(value string) []interface{} {
|
// case '<':
|
||||||
|
|
||||||
i := 1
|
// case '=':
|
||||||
s := 1
|
|
||||||
|
|
||||||
var params []interface{}
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
for ; i < len(value); i++ {
|
// return ops
|
||||||
switch value[i] {
|
// }
|
||||||
case ',':
|
|
||||||
params = append(params, parseExpr(value[s:i]))
|
|
||||||
s = i + 1
|
|
||||||
case '=':
|
|
||||||
params = append(params, parseExpr(value[s:i]))
|
|
||||||
s = i + 1
|
|
||||||
case ')':
|
|
||||||
params = append(params, parseExpr(value[s:i]))
|
|
||||||
return params
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
panic("can't find )")
|
// func parseCallParams(value string) []interface{} {
|
||||||
}
|
|
||||||
|
|
||||||
type Call struct {
|
// i := 0
|
||||||
fname string
|
// s := 0
|
||||||
params string
|
|
||||||
}
|
|
||||||
|
|
||||||
func (call *Call) Execute() {
|
// var params []interface{}
|
||||||
parseFunc(call.fname)(parseCallParams(call.params)...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func parseCall(value string) *Call {
|
// for ; i < len(value); i++ {
|
||||||
|
// switch value[i] {
|
||||||
|
// case '{':
|
||||||
|
// s++
|
||||||
|
// continue
|
||||||
|
// case ',', '=', ')':
|
||||||
|
// params = append(params, parseExpr(value[s:i]))
|
||||||
|
// s = i + 1
|
||||||
|
// case '|':
|
||||||
|
// params = append(params, parseExpr(value[s:i]))
|
||||||
|
// s = i + 1
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
for i := 0; i < len(value); i++ {
|
// return params
|
||||||
switch value[i] {
|
// // panic("can't find )")
|
||||||
case '(':
|
// }
|
||||||
return &Call{fname: value[0:i], params: value[i:]}
|
|
||||||
// parseFunc(value[0:i])
|
|
||||||
// parseCallParams(value[i:])
|
|
||||||
case '=': // assignment
|
|
||||||
return &Call{fname: "1", params: value}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
// type Call struct {
|
||||||
}
|
// fname string
|
||||||
|
// params string
|
||||||
|
// }
|
||||||
|
|
||||||
func parseCalls(expr string) []*Call {
|
// func (call *Call) Execute() {
|
||||||
|
// parseFunc(call.fname)(parseCallParams(call.params)...)
|
||||||
|
// }
|
||||||
|
|
||||||
// var execList []string
|
// func parseCall(value string) *Call {
|
||||||
i := 0
|
|
||||||
s := i
|
|
||||||
|
|
||||||
var calls []*Call
|
// for i := 0; i < len(value); i++ {
|
||||||
FOR:
|
// switch value[i] {
|
||||||
for ; i < len(expr); i++ {
|
// case '(':
|
||||||
switch expr[i] {
|
// return &Call{fname: value[0:i], params: value[i:]}
|
||||||
case '}':
|
// // parseFunc(value[0:i])
|
||||||
break FOR
|
// // parseCallParams(value[i:])
|
||||||
case ';':
|
// case '=': // assignment
|
||||||
calls = append(calls, parseCall(expr[s:i]))
|
// return &Call{fname: "=", params: value}
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
return calls
|
// return nil
|
||||||
}
|
// }
|
||||||
|
|
||||||
func parseDefine(v, method string) {
|
// func parseCondCalls(expr string) []*Call {
|
||||||
|
// // var execList []string
|
||||||
|
// i := 0
|
||||||
|
// s := 0
|
||||||
|
|
||||||
}
|
// var calls []*Call
|
||||||
|
|
||||||
func parseConditionList(condExpr string) []string {
|
// for ; i < len(expr); i++ {
|
||||||
|
// switch expr[i] {
|
||||||
|
// case '|':
|
||||||
|
// calls = append(calls, &Call{fname: "|", params: expr[s:i]})
|
||||||
|
// s = i + 1
|
||||||
|
// case '&':
|
||||||
|
// calls = append(calls, &Call{fname: "&", params: expr[s:i]})
|
||||||
|
// s = i + 1
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
var conds []string
|
// if s < i {
|
||||||
OpenClose := 0
|
// calls = append(calls, &Call{fname: "", params: expr[s:i]}) //可能存在问题
|
||||||
cur := 0
|
// }
|
||||||
i := 0
|
// return calls
|
||||||
for ; i < len(condExpr); i++ {
|
|
||||||
switch condExpr[i] {
|
|
||||||
case ',':
|
|
||||||
if OpenClose == 0 {
|
|
||||||
conds = append(conds, condExpr[cur:i])
|
|
||||||
cur = i + 1
|
|
||||||
}
|
|
||||||
case '(':
|
|
||||||
OpenClose++
|
|
||||||
case ')':
|
|
||||||
OpenClose--
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if cur < i {
|
// }
|
||||||
conds = append(conds, condExpr[cur:i])
|
|
||||||
}
|
|
||||||
|
|
||||||
return conds
|
// func parseCalls(expr string) []*Call {
|
||||||
}
|
|
||||||
|
|
||||||
func TestBaseCond(t *testing.T) {
|
// // var execList []string
|
||||||
t.Error()
|
// i := 0
|
||||||
condition := Condition{}
|
// s := 0
|
||||||
condExpr := "5>n>12|n<15|add(1,5){w=5},f>5{w=5s;add(1,2)}"
|
|
||||||
|
|
||||||
for _, expr := range parseConditionList(condExpr) {
|
// var calls []*Call
|
||||||
// condexpr
|
// FOR:
|
||||||
log.Println(expr)
|
// for ; i < len(expr); i++ {
|
||||||
ParseExpr:
|
// switch expr[i] {
|
||||||
for i := 0; i < len(expr); i++ {
|
// case '}':
|
||||||
|
// break FOR
|
||||||
|
// case ';':
|
||||||
|
// calls = append(calls, parseCall(expr[s:i]))
|
||||||
|
// s = i + 1
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
if expr[i] == '{' {
|
// if s < i {
|
||||||
s := i
|
// calls = append(calls, parseCall(expr[s:i]))
|
||||||
|
// }
|
||||||
|
// return calls
|
||||||
|
// }
|
||||||
|
|
||||||
for s > 0 {
|
// func parseDefine(v, method string) {
|
||||||
switch expr[s] {
|
|
||||||
case ' ':
|
|
||||||
s--
|
|
||||||
case '=':
|
|
||||||
// 判断 = 定义表达
|
|
||||||
parseDefine(expr[0:s], expr[i+1:])
|
|
||||||
break ParseExpr
|
|
||||||
default:
|
|
||||||
// 判断 = 条件表达
|
|
||||||
exec := Execute{conds: parseCond(expr[0:s]), calls: parseCalls(expr[i+1:])}
|
|
||||||
condition.execList = append(condition.execList, exec)
|
|
||||||
|
|
||||||
break ParseExpr
|
// }
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 判断 = 执行表达
|
// func parseConditionList(condExpr string) []string {
|
||||||
exec := Execute{calls: parseCalls(expr)}
|
|
||||||
condition.execList = append(condition.execList, exec)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
// var conds []string
|
||||||
|
// OpenClose := 0
|
||||||
|
// cur := 0
|
||||||
|
// i := 0
|
||||||
|
// for ; i < len(condExpr); i++ {
|
||||||
|
// switch condExpr[i] {
|
||||||
|
// case ',':
|
||||||
|
// if OpenClose == 0 {
|
||||||
|
// conds = append(conds, condExpr[cur:i])
|
||||||
|
// cur = i + 1
|
||||||
|
// }
|
||||||
|
// case '(':
|
||||||
|
// OpenClose++
|
||||||
|
// case ')':
|
||||||
|
// OpenClose--
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
// 找不到{ 判断 = 执行表达
|
// if cur < i {
|
||||||
exec := Execute{calls: parseCalls(expr)}
|
// conds = append(conds, condExpr[cur:i])
|
||||||
condition.execList = append(condition.execList, exec)
|
// }
|
||||||
}
|
|
||||||
|
|
||||||
spew.Dump(condition)
|
// return conds
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
// func TestBaseCond(t *testing.T) {
|
||||||
|
// t.Error()
|
||||||
|
// condition := Condition{}
|
||||||
|
// condExpr := "5>n>12|n<15|add(1,5){w=5},f>5{w=5s;add(1,2)}"
|
||||||
|
|
||||||
|
// ParseExpr:
|
||||||
|
// for _, expr := range parseConditionList(condExpr) {
|
||||||
|
// // condexpr
|
||||||
|
|
||||||
|
// for i := 0; i < len(expr); i++ {
|
||||||
|
|
||||||
|
// if expr[i] == '{' {
|
||||||
|
// s := i
|
||||||
|
|
||||||
|
// for s > 0 {
|
||||||
|
// switch expr[s] {
|
||||||
|
// case ' ':
|
||||||
|
// s--
|
||||||
|
// case '=':
|
||||||
|
// // 判断 = 定义表达
|
||||||
|
// parseDefine(expr[0:s], expr[i+1:])
|
||||||
|
// continue ParseExpr
|
||||||
|
|
||||||
|
// default:
|
||||||
|
// // 判断 = 条件表达
|
||||||
|
|
||||||
|
// exec := Execute{conds: parseCondCalls(expr[0:s]), calls: parseCalls(expr[i+1:])}
|
||||||
|
// condition.execList = append(condition.execList, exec)
|
||||||
|
|
||||||
|
// continue ParseExpr
|
||||||
|
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// // 判断 = 执行表达
|
||||||
|
// exec := Execute{calls: parseCalls(expr)}
|
||||||
|
// condition.execList = append(condition.execList, exec)
|
||||||
|
|
||||||
|
// continue ParseExpr
|
||||||
|
// }
|
||||||
|
|
||||||
|
// }
|
||||||
|
|
||||||
|
// // 找不到{ 判断 = 执行表达
|
||||||
|
// exec := Execute{calls: parseCalls(expr)}
|
||||||
|
// condition.execList = append(condition.execList, exec)
|
||||||
|
// }
|
||||||
|
|
||||||
|
// spew.Dump(condition)
|
||||||
|
// }
|
||||||
|
|
108
new_test.go
Normal file
108
new_test.go
Normal file
|
@ -0,0 +1,108 @@
|
||||||
|
package crontab
|
||||||
|
|
||||||
|
import (
|
||||||
|
"strconv"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/davecgh/go-spew/spew"
|
||||||
|
)
|
||||||
|
|
||||||
|
var VarDict = make(map[string]interface{})
|
||||||
|
var FuncDict = make(map[string]func(vars ...interface{}) interface{})
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
VarDict["w"] = float64(2.0)
|
||||||
|
VarDict["f"] = float64(0.0)
|
||||||
|
VarDict["s"] = float64(0.0)
|
||||||
|
|
||||||
|
FuncDict["add"] = Add
|
||||||
|
FuncDict["sub"] = Sub
|
||||||
|
FuncDict["mul"] = Mul
|
||||||
|
FuncDict["div"] = Div
|
||||||
|
}
|
||||||
|
|
||||||
|
type Object struct {
|
||||||
|
value string
|
||||||
|
ctype string
|
||||||
|
param *Object
|
||||||
|
}
|
||||||
|
|
||||||
|
func (obj *Object) Value() interface{} {
|
||||||
|
switch obj.ctype {
|
||||||
|
case "const":
|
||||||
|
fvar, err := strconv.ParseFloat(obj.value, 64)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return fvar
|
||||||
|
case "var":
|
||||||
|
return VarDict[obj.value]
|
||||||
|
case "call":
|
||||||
|
|
||||||
|
var params []interface{}
|
||||||
|
cur := obj.param
|
||||||
|
for cur != nil {
|
||||||
|
params = append(params, cur.Value())
|
||||||
|
}
|
||||||
|
return FuncDict[obj.value](params...)
|
||||||
|
}
|
||||||
|
|
||||||
|
panic("err type")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (obj *Object) SetValue(v *Object) {
|
||||||
|
VarDict[obj.value] = v.Value()
|
||||||
|
}
|
||||||
|
|
||||||
|
parse
|
||||||
|
|
||||||
|
func TestParse(t *testing.T) {
|
||||||
|
t.Error()
|
||||||
|
condition := &Object{}
|
||||||
|
condExpr := "5>n>12|n<15|add(1,5){w=5},f>5{w=5s;add(1,2)}"
|
||||||
|
|
||||||
|
ParseExpr:
|
||||||
|
for _, expr := range parseConditionExpr(condExpr) {
|
||||||
|
// condexpr
|
||||||
|
|
||||||
|
for i := 0; i < len(expr); i++ {
|
||||||
|
|
||||||
|
if expr[i] == '{' {
|
||||||
|
s := i
|
||||||
|
|
||||||
|
for s > 0 {
|
||||||
|
switch expr[s] {
|
||||||
|
case ' ':
|
||||||
|
s--
|
||||||
|
case '=':
|
||||||
|
// 判断 = 定义表达
|
||||||
|
// parseDefine(expr[0:s], expr[i+1:])
|
||||||
|
continue ParseExpr
|
||||||
|
|
||||||
|
default:
|
||||||
|
// 判断 = 条件表达
|
||||||
|
|
||||||
|
exec := Execute{conds: parseCondCalls(expr[0:s]), calls: parseCalls(expr[i+1:])}
|
||||||
|
condition.execList = append(condition.execList, exec)
|
||||||
|
|
||||||
|
continue ParseExpr
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 判断 = 执行表达
|
||||||
|
exec := Execute{calls: parseCalls(expr)}
|
||||||
|
condition.execList = append(condition.execList, exec)
|
||||||
|
|
||||||
|
continue ParseExpr
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// 找不到{ 判断 = 执行表达
|
||||||
|
exec := Execute{calls: parseCalls(expr)}
|
||||||
|
condition.execList = append(condition.execList, exec)
|
||||||
|
}
|
||||||
|
|
||||||
|
spew.Dump(condition)
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user