diff --git a/internal/cmd/platypus/run/run.go b/internal/cmd/platypus/run/run.go index 3d4f3d6..6ed4531 100644 --- a/internal/cmd/platypus/run/run.go +++ b/internal/cmd/platypus/run/run.go @@ -123,7 +123,7 @@ func runScript(ctx context.Context, options *Options, script *plruntime.Script) tn = pt.Time measurement = pt.Measurement - errR := engine.RunScriptWithRMapIn(script, pt, nil) + errR := script.Run(pt, nil) if errR != nil { return fmt.Errorf("run script error: %w", errR) } diff --git a/pkg/ast/ast.go b/pkg/ast/ast.go index 0ad7b6a..47ab922 100644 --- a/pkg/ast/ast.go +++ b/pkg/ast/ast.go @@ -72,9 +72,9 @@ func (t NodeType) String() string { case TypeNilLiteral: return "NilLiteral" case TypeListLiteral: - return "ListInitExpr" + return "ListLiteral" case TypeMapLiteral: - return "MapInitExpr" + return "MapLiteral" case TypeParenExpr: return "ParenExpr" case TypeAttrExpr: diff --git a/pkg/ast/expr.go b/pkg/ast/expr.go index 0d15c2b..809fef6 100644 --- a/pkg/ast/expr.go +++ b/pkg/ast/expr.go @@ -292,7 +292,8 @@ type CallExpr struct { Name string - Param []*Node + Param []*Node + ParamNormalized []*Node PrivateData interface{} diff --git a/pkg/engine/engine.go b/pkg/engine/engine.go index 6c6d066..77166ba 100644 --- a/pkg/engine/engine.go +++ b/pkg/engine/engine.go @@ -11,7 +11,6 @@ import ( "path/filepath" plruntime "github.com/GuanceCloud/platypus/pkg/engine/runtime" - "github.com/GuanceCloud/platypus/pkg/errchain" "github.com/GuanceCloud/platypus/pkg/parser" ) @@ -35,8 +34,7 @@ func ParseScript(scripts map[string]string, Ast: stmts, } - if err := CheckScript(p, check); err != nil { - // TODO + if err := p.Check(check); err != nil { retErrMap[name] = err continue } @@ -51,22 +49,6 @@ func ParseScript(scripts map[string]string, return retMap, retErrMap } -func RunScriptWithoutMapIn(proc *plruntime.Script, data plruntime.InputWithoutMap, signal plruntime.Signal) *errchain.PlError { - return plruntime.RunScriptWithoutMapIn(proc, data, signal) -} - -func RunScriptWithRMapIn(proc *plruntime.Script, data plruntime.InputWithRMap, signal plruntime.Signal) *errchain.PlError { - return plruntime.RunScriptWithRMapIn(proc, data, signal) -} - -func RunScriptRef(ctx *plruntime.Context, proc *plruntime.Script) *errchain.PlError { - return plruntime.RefRunScript(ctx, proc) -} - -func CheckScript(proc *plruntime.Script, funcsCheck map[string]plruntime.FuncCheck) *errchain.PlError { - return plruntime.CheckScript(proc, funcsCheck) -} - func ReadPlScriptFromDir(dirPath string) (map[string]string, map[string]string, error) { ret := map[string]string{} retPath := map[string]string{} diff --git a/pkg/engine/op_test.go b/pkg/engine/op_test.go index bf5cd45..6a4e0b6 100644 --- a/pkg/engine/op_test.go +++ b/pkg/engine/op_test.go @@ -9,7 +9,6 @@ import ( "testing" "time" - "github.com/GuanceCloud/platypus/pkg/engine/runtime" "github.com/GuanceCloud/platypus/pkg/inimpl/guancecloud/funcs" "github.com/GuanceCloud/platypus/pkg/inimpl/guancecloud/input" "github.com/stretchr/testify/assert" @@ -111,7 +110,7 @@ for a = 0; a < 12; a = a + 1 { pt := input.GetPoint() pt = input.InitPt(pt, "test", nil, nil, time.Now()) - err := runtime.RunScriptWithRMapIn(script, pt, nil) + err := script.Run(pt, nil) if err != nil { t.Fatal(err.Error()) } diff --git a/pkg/engine/runtime/checkstmt.go b/pkg/engine/runtime/checkstmt.go index 8d89b76..cb010f9 100644 --- a/pkg/engine/runtime/checkstmt.go +++ b/pkg/engine/runtime/checkstmt.go @@ -19,7 +19,7 @@ type ContextCheck struct { continuestmt bool } -func RunStmtsCheck(ctx *Context, ctxCheck *ContextCheck, nodes ast.Stmts) *errchain.PlError { +func RunStmtsCheck(ctx *Task, ctxCheck *ContextCheck, nodes ast.Stmts) *errchain.PlError { for _, node := range nodes { if err := RunStmtCheck(ctx, ctxCheck, node); err != nil { return err @@ -28,7 +28,7 @@ func RunStmtsCheck(ctx *Context, ctxCheck *ContextCheck, nodes ast.Stmts) *errch return nil } -func RunStmtCheck(ctx *Context, ctxCheck *ContextCheck, node *ast.Node) *errchain.PlError { +func RunStmtCheck(ctx *Task, ctxCheck *ContextCheck, node *ast.Node) *errchain.PlError { if node == nil { return nil } @@ -87,7 +87,7 @@ func RunStmtCheck(ctx *Context, ctxCheck *ContextCheck, node *ast.Node) *errchai return nil } -func RunListInitExprCheck(ctx *Context, ctxCheck *ContextCheck, expr *ast.ListLiteral) *errchain.PlError { +func RunListInitExprCheck(ctx *Task, ctxCheck *ContextCheck, expr *ast.ListLiteral) *errchain.PlError { for _, v := range expr.List { if err := RunStmtCheck(ctx, ctxCheck, v); err != nil { return err.ChainAppend(ctx.name, expr.LBracket) @@ -96,7 +96,7 @@ func RunListInitExprCheck(ctx *Context, ctxCheck *ContextCheck, expr *ast.ListLi return nil } -func RunMapInitExprCheck(ctx *Context, ctxCheck *ContextCheck, expr *ast.MapLiteral) *errchain.PlError { +func RunMapInitExprCheck(ctx *Task, ctxCheck *ContextCheck, expr *ast.MapLiteral) *errchain.PlError { for _, v := range expr.KeyValeList { switch v[0].NodeType { //nolint:exhaustive case ast.TypeFloatLiteral, ast.TypeIntegerLiteral, @@ -116,11 +116,11 @@ func RunMapInitExprCheck(ctx *Context, ctxCheck *ContextCheck, expr *ast.MapLite return nil } -func RunParenExprCheck(ctx *Context, ctxCheck *ContextCheck, expr *ast.ParenExpr) *errchain.PlError { +func RunParenExprCheck(ctx *Task, ctxCheck *ContextCheck, expr *ast.ParenExpr) *errchain.PlError { return RunStmtCheck(ctx, ctxCheck, expr.Param) } -func RunAttrExprCheck(ctx *Context, ctxCheck *ContextCheck, expr *ast.AttrExpr) *errchain.PlError { +func RunAttrExprCheck(ctx *Task, ctxCheck *ContextCheck, expr *ast.AttrExpr) *errchain.PlError { if err := RunStmtCheck(ctx, ctxCheck, expr.Obj); err != nil { return err } @@ -131,7 +131,7 @@ func RunAttrExprCheck(ctx *Context, ctxCheck *ContextCheck, expr *ast.AttrExpr) return nil } -func RunArithmeticExprCheck(ctx *Context, ctxCheck *ContextCheck, expr *ast.ArithmeticExpr) *errchain.PlError { +func RunArithmeticExprCheck(ctx *Task, ctxCheck *ContextCheck, expr *ast.ArithmeticExpr) *errchain.PlError { if err := RunStmtCheck(ctx, ctxCheck, expr.LHS); err != nil { return err } @@ -145,7 +145,7 @@ func RunArithmeticExprCheck(ctx *Context, ctxCheck *ContextCheck, expr *ast.Arit return nil } -func RunConditionExprCheck(ctx *Context, ctxCheck *ContextCheck, expr *ast.ConditionalExpr) *errchain.PlError { +func RunConditionExprCheck(ctx *Task, ctxCheck *ContextCheck, expr *ast.ConditionalExpr) *errchain.PlError { if err := RunStmtCheck(ctx, ctxCheck, expr.LHS); err != nil { return err } @@ -155,14 +155,14 @@ func RunConditionExprCheck(ctx *Context, ctxCheck *ContextCheck, expr *ast.Condi return nil } -func RunUnaryExprCheck(ctx *Context, ctxCheck *ContextCheck, expr *ast.UnaryExpr) *errchain.PlError { +func RunUnaryExprCheck(ctx *Task, ctxCheck *ContextCheck, expr *ast.UnaryExpr) *errchain.PlError { if err := RunStmtCheck(ctx, ctxCheck, expr.RHS); err != nil { return err } return nil } -func RunIndexExprGetCheck(ctx *Context, ctxCheck *ContextCheck, expr *ast.IndexExpr) *errchain.PlError { +func RunIndexExprGetCheck(ctx *Task, ctxCheck *ContextCheck, expr *ast.IndexExpr) *errchain.PlError { for _, v := range expr.Index { if err := RunStmtCheck(ctx, ctxCheck, v); err != nil { return err @@ -171,7 +171,7 @@ func RunIndexExprGetCheck(ctx *Context, ctxCheck *ContextCheck, expr *ast.IndexE return nil } -func RunCallExprCheck(ctx *Context, ctxCheck *ContextCheck, expr *ast.CallExpr) *errchain.PlError { +func RunCallExprCheck(ctx *Task, ctxCheck *ContextCheck, expr *ast.CallExpr) *errchain.PlError { _, ok := ctx.GetFuncCall(expr.Name) if !ok { return NewRunError(ctx, fmt.Sprintf( @@ -191,7 +191,7 @@ func RunCallExprCheck(ctx *Context, ctxCheck *ContextCheck, expr *ast.CallExpr) return funcCheck(ctx, expr) } -func RunAssignmentExprCheck(ctx *Context, ctxCheck *ContextCheck, expr *ast.AssignmentExpr) *errchain.PlError { +func RunAssignmentExprCheck(ctx *Task, ctxCheck *ContextCheck, expr *ast.AssignmentExpr) *errchain.PlError { if err := RunStmtCheck(ctx, ctxCheck, expr.RHS); err != nil { return err } @@ -201,7 +201,7 @@ func RunAssignmentExprCheck(ctx *Context, ctxCheck *ContextCheck, expr *ast.Assi return nil } -func RunIfElseStmtCheck(ctx *Context, ctxCheck *ContextCheck, stmt *ast.IfelseStmt) *errchain.PlError { +func RunIfElseStmtCheck(ctx *Task, ctxCheck *ContextCheck, stmt *ast.IfelseStmt) *errchain.PlError { ctx.StackEnterNew() defer ctx.StackExitCur() @@ -230,7 +230,7 @@ func RunIfElseStmtCheck(ctx *Context, ctxCheck *ContextCheck, stmt *ast.IfelseSt return nil } -func RunForStmtCheck(ctx *Context, ctxCheck *ContextCheck, stmt *ast.ForStmt) *errchain.PlError { +func RunForStmtCheck(ctx *Task, ctxCheck *ContextCheck, stmt *ast.ForStmt) *errchain.PlError { ctx.StackEnterNew() defer ctx.StackExitCur() @@ -268,7 +268,7 @@ func RunForStmtCheck(ctx *Context, ctxCheck *ContextCheck, stmt *ast.ForStmt) *e return nil } -func RunForInStmtCheck(ctx *Context, ctxCheck *ContextCheck, stmt *ast.ForInStmt) *errchain.PlError { +func RunForInStmtCheck(ctx *Task, ctxCheck *ContextCheck, stmt *ast.ForInStmt) *errchain.PlError { ctx.StackEnterNew() defer ctx.StackExitCur() @@ -303,7 +303,7 @@ func RunForInStmtCheck(ctx *Context, ctxCheck *ContextCheck, stmt *ast.ForInStmt return nil } -func RunBreakStmtCheck(ctx *Context, ctxCheck *ContextCheck, stmt *ast.BreakStmt) *errchain.PlError { +func RunBreakStmtCheck(ctx *Task, ctxCheck *ContextCheck, stmt *ast.BreakStmt) *errchain.PlError { if len(ctxCheck.forstmt) == 0 { return NewRunError(ctx, "break not in loop", stmt.Start) } @@ -311,7 +311,7 @@ func RunBreakStmtCheck(ctx *Context, ctxCheck *ContextCheck, stmt *ast.BreakStmt return nil } -func RunContinueStmtCheck(ctx *Context, ctxCheck *ContextCheck, stmt *ast.ContinueStmt) *errchain.PlError { +func RunContinueStmtCheck(ctx *Task, ctxCheck *ContextCheck, stmt *ast.ContinueStmt) *errchain.PlError { if len(ctxCheck.forstmt) == 0 { return NewRunError(ctx, "continue not in loop", stmt.Start) } diff --git a/pkg/engine/runtime/context.go b/pkg/engine/runtime/context.go index 7b95d76..9279641 100644 --- a/pkg/engine/runtime/context.go +++ b/pkg/engine/runtime/context.go @@ -7,7 +7,9 @@ package runtime import ( "encoding/json" + "errors" "fmt" + "reflect" "sync" "github.com/GuanceCloud/grok" @@ -20,26 +22,7 @@ const ( PlRunInfoField = "pl_msg" ) -type Script struct { - CallRef []*ast.CallExpr - - FuncCall map[string]FuncCall - - Name string - Namespace string - Category string - FilePath string - - Content string - - Ast ast.Stmts -} - -type Signal interface { - ExitSignal() bool -} - -type Context struct { +type Task struct { Regs PlReg stackHeader *PlProcStack @@ -48,9 +31,7 @@ type Context struct { funcCall map[string]FuncCall funcCheck map[string]FuncCheck - inType InType - inRMap InputWithRMap - inWithoutMap InputWithoutMap + input Input // for 循环结束后需要清理此标志 loopBreak bool @@ -60,82 +41,86 @@ type Context struct { procExit bool - callRCef []*ast.CallExpr + callRef []*ast.CallExpr - name string - content string - // namespace string - // filepath string -} + name string -func (ctx *Context) Name() string { - return ctx.name + withValue map[any]any } -func (ctx *Context) InData() any { - switch ctx.inType { - case InRMap: - return ctx.inRMap - default: - return ctx.inWithoutMap - } -} - -func (ctx *Context) Signal() Signal { - return ctx.signal +func (ctx *Task) Name() string { + return ctx.name } -func InitCtxWithoutMap(ctx *Context, inWithoutMap InputWithoutMap, funcs map[string]FuncCall, - callRef []*ast.CallExpr, signal Signal, name, content string, -) *Context { - ctx.Regs.Reset() +var ( + ErrNilKey = errors.New("key is nil") + ErrKeyNotComparable = errors.New("key is not comparable") + ErrKeyExists = errors.New("key exists") +) - ctx.inType = InWithoutMap - ctx.inWithoutMap = inWithoutMap +func (ctx *Task) WithVal(key, val any, force bool) error { + if key == nil { + return ErrNilKey + } + if !reflect.TypeOf(key).Comparable() { + return ErrKeyNotComparable + } + if ctx.withValue == nil { + ctx.withValue = map[any]any{ + key: val, + } + return nil + } - ctx.funcCall = funcs - ctx.funcCheck = nil + if _, ok := ctx.withValue[key]; !ok { + ctx.withValue[key] = val + } else { + if force { + ctx.withValue[key] = val + } else { + return ErrKeyExists + } + } - ctx.callRCef = callRef - ctx.loopBreak = false - ctx.loopContinue = false + return nil +} - ctx.signal = signal - ctx.procExit = false +func (ctx *Task) Val(key any) any { + if ctx.withValue == nil { + return nil + } + return ctx.withValue[key] +} - ctx.name = name - ctx.content = content +func (ctx *Task) InData() any { + return ctx.input +} - return ctx +func (ctx *Task) Signal() Signal { + return ctx.signal } -func InitCtxWithRMap(ctx *Context, inWithRMap InputWithRMap, funcs map[string]FuncCall, - callRef []*ast.CallExpr, signal Signal, name, content string, -) *Context { +func InitCtx(ctx *Task, input Input, script *Script, signal Signal) *Task { ctx.Regs.Reset() - ctx.inType = InRMap - ctx.inRMap = inWithRMap + ctx.input = input - ctx.funcCall = funcs + ctx.funcCall = script.FuncCall ctx.funcCheck = nil - ctx.callRCef = callRef + ctx.callRef = script.CallRef ctx.loopBreak = false ctx.loopContinue = false ctx.signal = signal ctx.procExit = false - ctx.name = name - ctx.content = content + ctx.name = script.Name return ctx } -func InitCtxForCheck(ctx *Context, funcs map[string]FuncCall, funcsCheck map[string]FuncCheck, - name, content string, -) *Context { +func InitCtxForCheck(ctx *Task, script *Script, checkFn map[string]FuncCheck) *Task { ctx.stackHeader = &PlProcStack{ data: map[string]*Varb{}, } @@ -143,22 +128,20 @@ func InitCtxForCheck(ctx *Context, funcs map[string]FuncCall, funcsCheck map[str ctx.Regs.Reset() - ctx.funcCall = funcs - ctx.funcCheck = funcsCheck + ctx.funcCall = script.FuncCall + ctx.funcCheck = checkFn - ctx.callRCef = []*ast.CallExpr{} + ctx.callRef = []*ast.CallExpr{} ctx.loopBreak = false ctx.loopContinue = false ctx.procExit = false - ctx.name = name - ctx.content = content - + ctx.name = script.Name return ctx } -func (ctx *Context) SetVarb(key string, value any, dtype ast.DType) error { +func (ctx *Task) SetVarb(key string, value any, dtype ast.DType) error { if key == "_" { key = ploriginkey } @@ -167,18 +150,18 @@ func (ctx *Context) SetVarb(key string, value any, dtype ast.DType) error { return nil } -func (ctx *Context) SetExit() { +func (ctx *Task) SetExit() { ctx.procExit = true } -func (ctx *Context) SetCallRef(expr *ast.CallExpr) { - if ctx.callRCef == nil { - ctx.callRCef = []*ast.CallExpr{} +func (ctx *Task) SetCallRef(expr *ast.CallExpr) { + if ctx.callRef == nil { + ctx.callRef = []*ast.CallExpr{} } - ctx.callRCef = append(ctx.callRCef, expr) + ctx.callRef = append(ctx.callRef, expr) } -func (ctx *Context) GetKey(key string) (*Varb, error) { +func (ctx *Task) GetKey(key string) (*Varb, error) { if key == "_" { key = ploriginkey } @@ -186,20 +169,17 @@ func (ctx *Context) GetKey(key string) (*Varb, error) { return v, nil } - switch ctx.inType { - case InRMap: - if v, t, err := ctx.inRMap.Get(key); err == nil { - return &Varb{ - Value: v, - DType: t, - }, nil - } + if v, t, err := ctx.input.Get(key); err == nil { + return &Varb{ + Value: v, + DType: t, + }, nil } return nil, fmt.Errorf("key not found") } -func (ctx *Context) GetKeyConv2Str(key string) (string, error) { +func (ctx *Task) GetKeyConv2Str(key string) (string, error) { if key == "_" { key = ploriginkey } @@ -208,17 +188,14 @@ func (ctx *Context) GetKeyConv2Str(key string) (string, error) { return Conv2String(v.Value, v.DType) } - switch ctx.inType { - case InRMap: - if v, t, err := ctx.inRMap.Get(key); err == nil { - return Conv2String(v, t) - } + if v, t, err := ctx.input.Get(key); err == nil { + return Conv2String(v, t) } return "", fmt.Errorf("nil") } -func (ctx *Context) GetFuncCall(key string) (FuncCall, bool) { +func (ctx *Task) GetFuncCall(key string) (FuncCall, bool) { if ctx.funcCall == nil { return nil, false } @@ -226,7 +203,7 @@ func (ctx *Context) GetFuncCall(key string) (FuncCall, bool) { return v, ok } -func (ctx *Context) GetFuncCheck(key string) (FuncCheck, bool) { +func (ctx *Task) GetFuncCheck(key string) (FuncCheck, bool) { if ctx.funcCheck == nil { return nil, false } @@ -234,7 +211,7 @@ func (ctx *Context) GetFuncCheck(key string) (FuncCheck, bool) { return v, ok } -func (ctx *Context) StackEnterNew() { +func (ctx *Task) StackEnterNew() { next := &PlProcStack{ data: map[string]*Varb{}, before: ctx.stackCur, @@ -243,18 +220,18 @@ func (ctx *Context) StackEnterNew() { ctx.stackCur = next } -func (ctx *Context) StackExitCur() { +func (ctx *Task) StackExitCur() { ctx.stackCur.data = nil ctx.stackCur.checkPattern = nil ctx.stackCur = ctx.stackCur.before } -func (ctx *Context) StackClear() { +func (ctx *Task) StackClear() { ctx.stackCur.Clear() } -func (ctx *Context) GetPattern(pattern string) (*grok.GrokPattern, bool) { +func (ctx *Task) GetPattern(pattern string) (*grok.GrokPattern, bool) { v, ok := ctx.stackCur.GetPattern(pattern) if ok { return v, ok @@ -268,18 +245,18 @@ func (ctx *Context) GetPattern(pattern string) (*grok.GrokPattern, bool) { return nil, false } -func (ctx *Context) SetPattern(patternAlias string, gPattern *grok.GrokPattern) { +func (ctx *Task) SetPattern(patternAlias string, gPattern *grok.GrokPattern) { ctx.stackCur.SetPattern(patternAlias, gPattern) } -func (ctx *Context) StmtRetrun() bool { +func (ctx *Task) StmtRetrun() bool { if ctx.ProcExit() || ctx.loopBreak || ctx.loopContinue { return true } return false } -func (ctx *Context) ProcExit() bool { +func (ctx *Task) ProcExit() bool { if !ctx.procExit && ctx.signal != nil { if ctx.signal.ExitSignal() { ctx.procExit = true @@ -290,12 +267,12 @@ func (ctx *Context) ProcExit() bool { var ctxPool sync.Pool = sync.Pool{ New: func() any { - return &Context{} + return &Task{} }, } -func GetContext() *Context { - ctx, _ := ctxPool.Get().(*Context) +func GetContext() *Task { + ctx, _ := ctxPool.Get().(*Task) ctx.stackHeader = &PlProcStack{ data: map[string]*Varb{}, @@ -304,25 +281,8 @@ func GetContext() *Context { return ctx } -func PutContext(ctx *Context) { - ctx.stackHeader = nil - ctx.stackCur = nil - - ctx.funcCall = nil - ctx.funcCheck = nil - - ctx.inRMap = nil - ctx.inRMap = nil - ctx.inWithoutMap = nil - ctx.inType = InNoSet - - ctx.loopBreak = false - ctx.loopContinue = false - - ctx.procExit = false - - ctx.callRCef = nil - +func PutContext(ctx *Task) { + *ctx = Task{} ctxPool.Put(ctx) } diff --git a/pkg/engine/runtime/error.go b/pkg/engine/runtime/error.go index b5584e3..83b945b 100644 --- a/pkg/engine/runtime/error.go +++ b/pkg/engine/runtime/error.go @@ -10,6 +10,6 @@ import ( "github.com/GuanceCloud/platypus/pkg/token" ) -func NewRunError(ctx *Context, err string, pos token.LnColPos) *errchain.PlError { +func NewRunError(ctx *Task, err string, pos token.LnColPos) *errchain.PlError { return errchain.NewErr(ctx.name, pos, err) } diff --git a/pkg/engine/runtime/input.go b/pkg/engine/runtime/input.go index b9006bd..34f2658 100644 --- a/pkg/engine/runtime/input.go +++ b/pkg/engine/runtime/input.go @@ -2,16 +2,6 @@ package runtime import "github.com/GuanceCloud/platypus/pkg/ast" -type InType uint8 - -const ( - InNoSet = iota - InWithoutMap - InRMap -) - -type InputWithRMap interface { +type Input interface { Get(key string) (any, ast.DType, error) } - -type InputWithoutMap interface{} diff --git a/pkg/engine/runtime/runtime.go b/pkg/engine/runtime/runtime.go index a5a1cad..20b3348 100644 --- a/pkg/engine/runtime/runtime.go +++ b/pkg/engine/runtime/runtime.go @@ -18,68 +18,83 @@ import ( ) type ( - FuncCheck func(*Context, *ast.CallExpr) *errchain.PlError - FuncCall func(*Context, *ast.CallExpr) *errchain.PlError + FuncCheck func(*Task, *ast.CallExpr) *errchain.PlError + FuncCall func(*Task, *ast.CallExpr) *errchain.PlError ) -func RunScriptWithoutMapIn(proc *Script, data InputWithoutMap, signal Signal) *errchain.PlError { - if proc == nil { - return nil - } +type Script struct { + CallRef []*ast.CallExpr - ctx := GetContext() - defer PutContext(ctx) + FuncCall map[string]FuncCall + + Name string + Namespace string + Category string + FilePath string + + Content string // deprecated + + Ast ast.Stmts +} + +type Signal interface { + ExitSignal() bool +} - ctx = InitCtxWithoutMap(ctx, data, proc.FuncCall, proc.CallRef, signal, proc.Name, proc.Content) - return RunStmts(ctx, proc.Ast) +func WithVal(key string, val any) TaskFn { + return func(ctx *Task) { + _ = ctx.WithVal(key, val, false) + } } -func RunScriptWithRMapIn(proc *Script, data InputWithRMap, signal Signal) *errchain.PlError { - if proc == nil { +type TaskFn func(ctx *Task) + +func (s *Script) Run(data Input, signal Signal, fn ...TaskFn) *errchain.PlError { + if s == nil { return nil } ctx := GetContext() defer PutContext(ctx) - ctx = InitCtxWithRMap(ctx, data, proc.FuncCall, proc.CallRef, signal, proc.Name, proc.Content) - return RunStmts(ctx, proc.Ast) + for _, fn := range fn { + fn(ctx) + } + + ctx = InitCtx(ctx, data, s, signal) + return RunStmts(ctx, s.Ast) } -func RefRunScript(ctx *Context, proc *Script) *errchain.PlError { - if proc == nil { +func (s *Script) RefRun(ctx *Task) *errchain.PlError { + if s == nil { return nil } newctx := GetContext() defer PutContext(newctx) - switch ctx.inType { - case InRMap: - InitCtxWithRMap(newctx, ctx.inRMap, proc.FuncCall, proc.CallRef, ctx.signal, proc.Name, proc.Content) - case InWithoutMap: - InitCtxWithoutMap(newctx, ctx.inWithoutMap, proc.FuncCall, proc.CallRef, ctx.signal, proc.Name, proc.Content) - default: - // TODO - return nil - } + InitCtx(newctx, ctx.input, s, ctx.signal) - return RunStmts(newctx, proc.Ast) + return RunStmts(newctx, s.Ast) } -func CheckScript(proc *Script, funcsCheck map[string]FuncCheck) *errchain.PlError { +func (s *Script) Check(funcsCheck map[string]FuncCheck) *errchain.PlError { + if s == nil { + return nil + } + ctx := GetContext() defer PutContext(ctx) - InitCtxForCheck(ctx, proc.FuncCall, funcsCheck, proc.Name, proc.Content) - if err := RunStmtsCheck(ctx, &ContextCheck{}, proc.Ast); err != nil { + InitCtxForCheck(ctx, s, funcsCheck) + if err := RunStmtsCheck(ctx, &ContextCheck{}, s.Ast); err != nil { return err } - proc.CallRef = ctx.callRCef + s.CallRef = ctx.callRef return nil } -func RunStmts(ctx *Context, nodes ast.Stmts) *errchain.PlError { +func RunStmts(ctx *Task, nodes ast.Stmts) *errchain.PlError { for _, node := range nodes { if _, _, err := RunStmt(ctx, node); err != nil { ctx.procExit = true @@ -93,7 +108,7 @@ func RunStmts(ctx *Context, nodes ast.Stmts) *errchain.PlError { return nil } -func RunIfElseStmt(ctx *Context, stmt *ast.IfelseStmt) (any, ast.DType, *errchain.PlError) { +func RunIfElseStmt(ctx *Task, stmt *ast.IfelseStmt) (any, ast.DType, *errchain.PlError) { ctx.StackEnterNew() defer ctx.StackExitCur() @@ -169,7 +184,7 @@ func condTrue(val any, dtype ast.DType) bool { return true } -func RunForStmt(ctx *Context, stmt *ast.ForStmt) (any, ast.DType, *errchain.PlError) { +func RunForStmt(ctx *Task, stmt *ast.ForStmt) (any, ast.DType, *errchain.PlError) { ctx.StackEnterNew() defer ctx.StackExitCur() @@ -226,7 +241,7 @@ func RunForStmt(ctx *Context, stmt *ast.ForStmt) (any, ast.DType, *errchain.PlEr return nil, ast.Void, nil } -func RunForInStmt(ctx *Context, stmt *ast.ForInStmt) (any, ast.DType, *errchain.PlError) { +func RunForInStmt(ctx *Task, stmt *ast.ForInStmt) (any, ast.DType, *errchain.PlError) { ctx.StackEnterNew() defer ctx.StackExitCur() @@ -322,7 +337,7 @@ func RunForInStmt(ctx *Context, stmt *ast.ForInStmt) (any, ast.DType, *errchain. return nil, ast.Void, nil } -func forbreak(ctx *Context) bool { +func forbreak(ctx *Task) bool { if ctx.loopBreak { ctx.loopBreak = false return true @@ -330,24 +345,24 @@ func forbreak(ctx *Context) bool { return false } -func forcontinue(ctx *Context) { +func forcontinue(ctx *Task) { if ctx.loopContinue { ctx.loopContinue = false } } -func RunBreakStmt(ctx *Context, stmt *ast.BreakStmt) (any, ast.DType, *errchain.PlError) { +func RunBreakStmt(ctx *Task, stmt *ast.BreakStmt) (any, ast.DType, *errchain.PlError) { ctx.loopBreak = true return nil, ast.Void, nil } -func RunContinueStmt(ctx *Context, stmt *ast.ContinueStmt) (any, ast.DType, *errchain.PlError) { +func RunContinueStmt(ctx *Task, stmt *ast.ContinueStmt) (any, ast.DType, *errchain.PlError) { ctx.loopContinue = true return nil, ast.Void, nil } // RunStmt for all expr. -func RunStmt(ctx *Context, node *ast.Node) (any, ast.DType, *errchain.PlError) { +func RunStmt(ctx *Task, node *ast.Node) (any, ast.DType, *errchain.PlError) { // TODO // 存在个别 node 为 nil 的情况 if node == nil { @@ -417,7 +432,7 @@ func RunStmt(ctx *Context, node *ast.Node) (any, ast.DType, *errchain.PlError) { } } -func RunUnaryExpr(ctx *Context, expr *ast.UnaryExpr) (any, ast.DType, *errchain.PlError) { +func RunUnaryExpr(ctx *Task, expr *ast.UnaryExpr) (any, ast.DType, *errchain.PlError) { switch expr.Op { case ast.SUB, ast.ADD: v, dtype, err := RunStmt(ctx, expr.RHS) @@ -515,7 +530,7 @@ func RunUnaryExpr(ctx *Context, expr *ast.UnaryExpr) (any, ast.DType, *errchain. } } -func RunListInitExpr(ctx *Context, expr *ast.ListLiteral) (any, ast.DType, *errchain.PlError) { +func RunListInitExpr(ctx *Task, expr *ast.ListLiteral) (any, ast.DType, *errchain.PlError) { ret := []any{} for _, v := range expr.List { v, _, err := RunStmt(ctx, v) @@ -527,7 +542,7 @@ func RunListInitExpr(ctx *Context, expr *ast.ListLiteral) (any, ast.DType, *errc return ret, ast.List, nil } -func RunMapInitExpr(ctx *Context, expr *ast.MapLiteral) (any, ast.DType, *errchain.PlError) { +func RunMapInitExpr(ctx *Task, expr *ast.MapLiteral) (any, ast.DType, *errchain.PlError) { ret := map[string]any{} for _, v := range expr.KeyValeList { @@ -567,7 +582,7 @@ func RunMapInitExpr(ctx *Context, expr *ast.MapLiteral) (any, ast.DType, *errcha // } // } -func RunIndexExprGet(ctx *Context, expr *ast.IndexExpr) (any, ast.DType, *errchain.PlError) { +func RunIndexExprGet(ctx *Task, expr *ast.IndexExpr) (any, ast.DType, *errchain.PlError) { key := expr.Obj.Name varb, err := ctx.GetKey(key) @@ -597,7 +612,7 @@ func RunIndexExprGet(ctx *Context, expr *ast.IndexExpr) (any, ast.DType, *errcha return searchListAndMap(ctx, varb.Value, expr.Index) } -func searchListAndMap(ctx *Context, obj any, index []*ast.Node) (any, ast.DType, *errchain.PlError) { +func searchListAndMap(ctx *Task, obj any, index []*ast.Node) (any, ast.DType, *errchain.PlError) { cur := obj for _, i := range index { @@ -643,13 +658,13 @@ func searchListAndMap(ctx *Context, obj any, index []*ast.Node) (any, ast.DType, return cur, dtype, nil } -func RunParenExpr(ctx *Context, expr *ast.ParenExpr) (any, ast.DType, *errchain.PlError) { +func RunParenExpr(ctx *Task, expr *ast.ParenExpr) (any, ast.DType, *errchain.PlError) { return RunStmt(ctx, expr.Param) } // BinarayExpr -func RunInExpr(ctx *Context, expr *ast.InExpr) (any, ast.DType, *errchain.PlError) { +func RunInExpr(ctx *Task, expr *ast.InExpr) (any, ast.DType, *errchain.PlError) { lhs, lhsT, err := RunStmt(ctx, expr.LHS) if err != nil { return nil, ast.Invalid, err @@ -702,7 +717,7 @@ func RunInExpr(ctx *Context, expr *ast.InExpr) (any, ast.DType, *errchain.PlErro } } -func RunConditionExpr(ctx *Context, expr *ast.ConditionalExpr) (any, ast.DType, *errchain.PlError) { +func RunConditionExpr(ctx *Task, expr *ast.ConditionalExpr) (any, ast.DType, *errchain.PlError) { lhs, lhsT, err := RunStmt(ctx, expr.LHS) if err != nil { return nil, ast.Invalid, err @@ -733,7 +748,7 @@ func RunConditionExpr(ctx *Context, expr *ast.ConditionalExpr) (any, ast.DType, } } -func RunArithmeticExpr(ctx *Context, expr *ast.ArithmeticExpr) (any, ast.DType, *errchain.PlError) { +func RunArithmeticExpr(ctx *Task, expr *ast.ArithmeticExpr) (any, ast.DType, *errchain.PlError) { // 允许字符串通过操作符 '+' 进行拼接 lhsVal, lhsValType, errOpInt := RunStmt(ctx, expr.LHS) @@ -791,7 +806,7 @@ func RunArithmeticExpr(ctx *Context, expr *ast.ArithmeticExpr) (any, ast.DType, return v, dtype, nil } -func runAssignArith(ctx *Context, l, r *Varb, op ast.Op, pos token.LnColPos) ( +func runAssignArith(ctx *Task, l, r *Varb, op ast.Op, pos token.LnColPos) ( any, ast.DType, *errchain.PlError) { arithOp, ok := assign2arithOp(op) @@ -846,7 +861,7 @@ func runAssignArith(ctx *Context, l, r *Varb, op ast.Op, pos token.LnColPos) ( } // RunAssignmentExpr runs assignment expression, but actually it is a stmt -func RunAssignmentExpr(ctx *Context, expr *ast.AssignmentExpr) (any, ast.DType, *errchain.PlError) { +func RunAssignmentExpr(ctx *Task, expr *ast.AssignmentExpr) (any, ast.DType, *errchain.PlError) { v, dtype, err := RunStmt(ctx, expr.RHS) if err != nil { return nil, ast.Invalid, err @@ -918,7 +933,7 @@ func RunAssignmentExpr(ctx *Context, expr *ast.AssignmentExpr) (any, ast.DType, } } -func changeListOrMapValue(ctx *Context, obj any, index []*ast.Node, val any, dtype ast.DType) (any, ast.DType, *errchain.PlError) { +func changeListOrMapValue(ctx *Task, obj any, index []*ast.Node, val any, dtype ast.DType) (any, ast.DType, *errchain.PlError) { cur := obj lenIdx := len(index) @@ -975,7 +990,7 @@ func changeListOrMapValue(ctx *Context, obj any, index []*ast.Node, val any, dty return nil, ast.Nil, nil } -func RunCallExpr(ctx *Context, expr *ast.CallExpr) (any, ast.DType, *errchain.PlError) { +func RunCallExpr(ctx *Task, expr *ast.CallExpr) (any, ast.DType, *errchain.PlError) { defer ctx.Regs.Reset() if funcCall, ok := ctx.GetFuncCall(expr.Name); ok { if err := funcCall(ctx, expr); err != nil { diff --git a/pkg/engine/runtime/runtime_test.go b/pkg/engine/runtime/runtime_test.go index d6c4e7a..7ad2daf 100644 --- a/pkg/engine/runtime/runtime_test.go +++ b/pkg/engine/runtime/runtime_test.go @@ -170,7 +170,7 @@ add_key(len2, len("123")) Content: pl, Ast: stmts, } - errR := CheckScript(script, map[string]FuncCheck{ + errR := script.Check(map[string]FuncCheck{ "add_key": addkeycheck, "len": lencheck, }) @@ -182,7 +182,7 @@ add_key(len2, len("123")) data: map[string]any{}, } - errR = RunScriptWithRMapIn(script, inData, nil) + errR = script.Run(inData, nil) if errR != nil { t.Fatal(errR.Error()) } @@ -258,7 +258,7 @@ add_key("a", a) Content: c.s, Ast: stmts, } - errR := CheckScript(script, map[string]FuncCheck{ + errR := script.Check(map[string]FuncCheck{ "add_key": addkeycheck, }) if errR != nil { @@ -269,7 +269,7 @@ add_key("a", a) data: map[string]any{}, } - errR = RunScriptWithRMapIn(script, inData, nil) + errR = script.Run(inData, nil) if errR != nil { t.Fatal(errR.Error()) } @@ -316,7 +316,7 @@ func TestInExpr(t *testing.T) { Content: pl, Ast: stmts, } - errR := CheckScript(script, map[string]FuncCheck{ + errR := script.Check(map[string]FuncCheck{ "add_key": addkeycheck, "len": lencheck, }) @@ -328,7 +328,7 @@ func TestInExpr(t *testing.T) { data: map[string]any{}, } - errR = RunScriptWithRMapIn(script, inData, nil) + errR = script.Run(inData, nil) if errR != nil { t.Fatal(errR.Error()) } @@ -372,7 +372,7 @@ func TestUnaryExpr(t *testing.T) { Content: pl, Ast: stmts, } - errR := CheckScript(script, map[string]FuncCheck{ + errR := script.Check(map[string]FuncCheck{ "add_key": addkeycheck, "ckfn": ckfncheck, }) @@ -384,7 +384,7 @@ func TestUnaryExpr(t *testing.T) { data: map[string]any{}, } - errR = RunScriptWithRMapIn(script, inData, nil) + errR = script.Run(inData, nil) if errR != nil { t.Fatal(errR.Error()) } @@ -418,7 +418,7 @@ func TestUnaryErrExpr(t *testing.T) { Content: pl, Ast: stmts, } - errR := CheckScript(script, map[string]FuncCheck{ + errR := script.Check(map[string]FuncCheck{ "add_key": addkeycheck, "ckfn": ckfnErrcheck, }) @@ -441,7 +441,7 @@ func TestSignal(t *testing.T) { return (*sign)(nil) }() - ctx := &Context{ + ctx := &Task{ signal: s, } @@ -591,7 +591,7 @@ func TestUnaryAndAssignOP(t *testing.T) { Content: v.pl, Ast: stmts, } - errR := CheckScript(script, map[string]FuncCheck{ + errR := script.Check(map[string]FuncCheck{ "add_key": addkeycheck, "len": lencheck, }) @@ -603,7 +603,7 @@ func TestUnaryAndAssignOP(t *testing.T) { data: map[string]any{}, } - errR = RunScriptWithRMapIn(script, inData, nil) + errR = script.Run(inData, nil) if errR != nil { t.Fatal(errR.Error()) } @@ -1003,11 +1003,11 @@ func parseScript(content string) (ast.Stmts, error) { return parser.ParsePipeline("", content) } -func callexprtest(ctx *Context, callExpr *ast.CallExpr) *errchain.PlError { +func callexprtest(ctx *Task, callExpr *ast.CallExpr) *errchain.PlError { return nil } -func addkeytest(ctx *Context, callExpr *ast.CallExpr) *errchain.PlError { +func addkeytest(ctx *Task, callExpr *ast.CallExpr) *errchain.PlError { var key string switch callExpr.Param[0].NodeType { case ast.TypeIdentifier: @@ -1023,30 +1023,27 @@ func addkeytest(ctx *Context, callExpr *ast.CallExpr) *errchain.PlError { if err != nil { return err } - if ctx.inType == InRMap { - if v, ok := ctx.inRMap.(*inputImpl); ok { - switch dtype { - case ast.Map, ast.List: - if res, err := json.Marshal(val); err == nil { - v.data[key] = string(res) - } - default: - v.data[key] = val + if v, ok := ctx.input.(*inputImpl); ok { + switch dtype { + case ast.Map, ast.List: + if res, err := json.Marshal(val); err == nil { + v.data[key] = string(res) } + default: + v.data[key] = val } } + } if varb, err := ctx.GetKey(key); err == nil { - if ctx.inType == InRMap { - if v, ok := ctx.inRMap.(*inputImpl); ok { - switch varb.DType { - case ast.Map, ast.List: - if res, err := json.Marshal(varb.Value); err == nil { - v.data[key] = string(res) - } - default: - v.data[key] = varb.Value + if v, ok := ctx.input.(*inputImpl); ok { + switch varb.DType { + case ast.Map, ast.List: + if res, err := json.Marshal(varb.Value); err == nil { + v.data[key] = string(res) } + default: + v.data[key] = varb.Value } } } @@ -1054,11 +1051,11 @@ func addkeytest(ctx *Context, callExpr *ast.CallExpr) *errchain.PlError { return nil } -func addkeycheck(ctx *Context, callExpr *ast.CallExpr) *errchain.PlError { +func addkeycheck(ctx *Task, callExpr *ast.CallExpr) *errchain.PlError { return nil } -func lentest(ctx *Context, callExpr *ast.CallExpr) *errchain.PlError { +func lentest(ctx *Task, callExpr *ast.CallExpr) *errchain.PlError { val, dtype, err := RunStmt(ctx, callExpr.Param[0]) if err != nil { return err @@ -1076,16 +1073,16 @@ func lentest(ctx *Context, callExpr *ast.CallExpr) *errchain.PlError { return nil } -func ckfncheck(ctx *Context, callexpr *ast.CallExpr) *errchain.PlError { +func ckfncheck(ctx *Task, callexpr *ast.CallExpr) *errchain.PlError { callexpr.PrivateData = 1 return nil } -func ckfnErrcheck(ctx *Context, callexpr *ast.CallExpr) *errchain.PlError { +func ckfnErrcheck(ctx *Task, callexpr *ast.CallExpr) *errchain.PlError { return NewRunError(ctx, "err", callexpr.NamePos) } -func ckfn(ctx *Context, callExpr *ast.CallExpr) *errchain.PlError { +func ckfn(ctx *Task, callExpr *ast.CallExpr) *errchain.PlError { if callExpr.PrivateData == nil { ctx.Regs.ReturnAppend(true, ast.Bool) } else { @@ -1094,6 +1091,6 @@ func ckfn(ctx *Context, callExpr *ast.CallExpr) *errchain.PlError { return nil } -func lencheck(ctx *Context, callexpr *ast.CallExpr) *errchain.PlError { +func lencheck(ctx *Task, callexpr *ast.CallExpr) *errchain.PlError { return nil } diff --git a/pkg/inimpl/guancecloud/funcs/all_test.go b/pkg/inimpl/guancecloud/funcs/all_test.go index f3ae833..e3b1eeb 100644 --- a/pkg/inimpl/guancecloud/funcs/all_test.go +++ b/pkg/inimpl/guancecloud/funcs/all_test.go @@ -42,6 +42,6 @@ func runScript(proc *runtime.Script, measurement string, input.InitPt(pt, measurement, tags, fields, tn) - _ = engine.RunScriptWithRMapIn(proc, pt, nil) + _ = proc.Run(pt, nil) return pt.Measurement, pt.Tags, pt.Fields, pt.Time, pt.Drop, nil } diff --git a/pkg/inimpl/guancecloud/funcs/fn_addkey.go b/pkg/inimpl/guancecloud/funcs/fn_addkey.go index 453a797..fffac1a 100644 --- a/pkg/inimpl/guancecloud/funcs/fn_addkey.go +++ b/pkg/inimpl/guancecloud/funcs/fn_addkey.go @@ -15,7 +15,7 @@ import ( "github.com/GuanceCloud/platypus/pkg/token" ) -func AddkeyChecking(ctx *runtime.Context, funcExpr *ast.CallExpr) *errchain.PlError { +func AddkeyChecking(ctx *runtime.Task, funcExpr *ast.CallExpr) *errchain.PlError { if len(funcExpr.Param) > 2 || len(funcExpr.Param) < 1 { return runtime.NewRunError(ctx, fmt.Sprintf( "func %s expected 1 or 2 args", funcExpr.Name), funcExpr.NamePos) @@ -28,7 +28,7 @@ func AddkeyChecking(ctx *runtime.Context, funcExpr *ast.CallExpr) *errchain.PlEr return nil } -func AddKey(ctx *runtime.Context, funcExpr *ast.CallExpr) *errchain.PlError { +func AddKey(ctx *runtime.Task, funcExpr *ast.CallExpr) *errchain.PlError { if funcExpr == nil { return runtime.NewRunError(ctx, "unreachable", token.InvalidLnColPos) } diff --git a/pkg/inimpl/guancecloud/funcs/fn_addpattern.go b/pkg/inimpl/guancecloud/funcs/fn_addpattern.go index 57b6b91..083f377 100644 --- a/pkg/inimpl/guancecloud/funcs/fn_addpattern.go +++ b/pkg/inimpl/guancecloud/funcs/fn_addpattern.go @@ -14,7 +14,7 @@ import ( "github.com/GuanceCloud/platypus/pkg/errchain" ) -func AddPatternChecking(ctx *runtime.Context, funcExpr *ast.CallExpr) *errchain.PlError { +func AddPatternChecking(ctx *runtime.Task, funcExpr *ast.CallExpr) *errchain.PlError { if len(funcExpr.Param) != 2 { return runtime.NewRunError(ctx, fmt.Sprintf( "func %s expected 2 args", funcExpr.Name), funcExpr.NamePos) @@ -45,6 +45,6 @@ func AddPatternChecking(ctx *runtime.Context, funcExpr *ast.CallExpr) *errchain. return nil } -func AddPattern(ctx *runtime.Context, funcExpr *ast.CallExpr) *errchain.PlError { +func AddPattern(ctx *runtime.Task, funcExpr *ast.CallExpr) *errchain.PlError { return nil } diff --git a/pkg/inimpl/guancecloud/funcs/fn_cast.go b/pkg/inimpl/guancecloud/funcs/fn_cast.go index e301c5d..e7fe4d4 100644 --- a/pkg/inimpl/guancecloud/funcs/fn_cast.go +++ b/pkg/inimpl/guancecloud/funcs/fn_cast.go @@ -14,7 +14,7 @@ import ( "github.com/GuanceCloud/platypus/pkg/inimpl/guancecloud/input" ) -func CastChecking(ctx *runtime.Context, funcExpr *ast.CallExpr) *errchain.PlError { +func CastChecking(ctx *runtime.Task, funcExpr *ast.CallExpr) *errchain.PlError { if len(funcExpr.Param) != 2 { return runtime.NewRunError(ctx, fmt.Sprintf( "func `%s' expected 2 args", funcExpr.Name), funcExpr.NamePos) @@ -38,7 +38,7 @@ func CastChecking(ctx *runtime.Context, funcExpr *ast.CallExpr) *errchain.PlErro return nil } -func Cast(ctx *runtime.Context, funcExpr *ast.CallExpr) *errchain.PlError { +func Cast(ctx *runtime.Task, funcExpr *ast.CallExpr) *errchain.PlError { if len(funcExpr.Param) != 2 { return runtime.NewRunError(ctx, fmt.Sprintf( "func `%s' expected 2 args", funcExpr.Name), funcExpr.NamePos) diff --git a/pkg/inimpl/guancecloud/funcs/fn_datetime.go b/pkg/inimpl/guancecloud/funcs/fn_datetime.go index e8e8b79..d480ad6 100644 --- a/pkg/inimpl/guancecloud/funcs/fn_datetime.go +++ b/pkg/inimpl/guancecloud/funcs/fn_datetime.go @@ -14,7 +14,7 @@ import ( "github.com/GuanceCloud/platypus/pkg/inimpl/guancecloud/input" ) -func DateTimeChecking(ctx *runtime.Context, funcExpr *ast.CallExpr) *errchain.PlError { +func DateTimeChecking(ctx *runtime.Task, funcExpr *ast.CallExpr) *errchain.PlError { if len(funcExpr.Param) != 3 { return runtime.NewRunError(ctx, fmt.Sprintf( "func %s expected 3 args", funcExpr.Name), funcExpr.NamePos) @@ -42,7 +42,7 @@ func DateTimeChecking(ctx *runtime.Context, funcExpr *ast.CallExpr) *errchain.Pl return nil } -func DateTime(ctx *runtime.Context, funcExpr *ast.CallExpr) *errchain.PlError { +func DateTime(ctx *runtime.Task, funcExpr *ast.CallExpr) *errchain.PlError { if len(funcExpr.Param) != 3 { return runtime.NewRunError(ctx, fmt.Sprintf( "func %s expected 3 args", funcExpr.Name), funcExpr.NamePos) diff --git a/pkg/inimpl/guancecloud/funcs/fn_default_time.go b/pkg/inimpl/guancecloud/funcs/fn_default_time.go index 4531ebd..3ebd14d 100644 --- a/pkg/inimpl/guancecloud/funcs/fn_default_time.go +++ b/pkg/inimpl/guancecloud/funcs/fn_default_time.go @@ -15,7 +15,7 @@ import ( "github.com/GuanceCloud/platypus/pkg/inimpl/guancecloud/input" ) -func DefaultTimeChecking(ctx *runtime.Context, funcExpr *ast.CallExpr) *errchain.PlError { +func DefaultTimeChecking(ctx *runtime.Task, funcExpr *ast.CallExpr) *errchain.PlError { if len(funcExpr.Param) < 1 { return runtime.NewRunError(ctx, fmt.Sprintf( "func %s Expect at least one arg", funcExpr.Name), funcExpr.NamePos) @@ -37,7 +37,7 @@ func DefaultTimeChecking(ctx *runtime.Context, funcExpr *ast.CallExpr) *errchain return nil } -func DefaultTime(ctx *runtime.Context, funcExpr *ast.CallExpr) *errchain.PlError { +func DefaultTime(ctx *runtime.Task, funcExpr *ast.CallExpr) *errchain.PlError { if len(funcExpr.Param) < 1 { return runtime.NewRunError(ctx, fmt.Sprintf( "func %s expect at least one arg", funcExpr.Name), funcExpr.NamePos) @@ -84,7 +84,7 @@ func DefaultTime(ctx *runtime.Context, funcExpr *ast.CallExpr) *errchain.PlError return nil } -func usePointTime(ctx *runtime.Context, key string, err error) { +func usePointTime(ctx *runtime.Task, key string, err error) { _ = key _ = addKey2PtWithVal(ctx.InData(), runtime.PlRunInfoField, fmt.Sprintf("time convert failed: %v", err), ast.String, input.KindPtDefault) diff --git a/pkg/inimpl/guancecloud/funcs/fn_dropkey.go b/pkg/inimpl/guancecloud/funcs/fn_dropkey.go index 9567938..6d22234 100644 --- a/pkg/inimpl/guancecloud/funcs/fn_dropkey.go +++ b/pkg/inimpl/guancecloud/funcs/fn_dropkey.go @@ -13,7 +13,7 @@ import ( "github.com/GuanceCloud/platypus/pkg/errchain" ) -func DropkeyChecking(ctx *runtime.Context, funcExpr *ast.CallExpr) *errchain.PlError { +func DropkeyChecking(ctx *runtime.Task, funcExpr *ast.CallExpr) *errchain.PlError { if len(funcExpr.Param) != 1 { return runtime.NewRunError(ctx, fmt.Sprintf( "func %s expected 1 args", funcExpr.Name), funcExpr.NamePos) @@ -26,7 +26,7 @@ func DropkeyChecking(ctx *runtime.Context, funcExpr *ast.CallExpr) *errchain.PlE return nil } -func Dropkey(ctx *runtime.Context, funcExpr *ast.CallExpr) *errchain.PlError { +func Dropkey(ctx *runtime.Task, funcExpr *ast.CallExpr) *errchain.PlError { if len(funcExpr.Param) != 1 { return runtime.NewRunError(ctx, fmt.Sprintf( "func %s expected 1 args", funcExpr.Name), funcExpr.NamePos) diff --git a/pkg/inimpl/guancecloud/funcs/fn_exit.go b/pkg/inimpl/guancecloud/funcs/fn_exit.go index 9bd1a99..6a9a408 100644 --- a/pkg/inimpl/guancecloud/funcs/fn_exit.go +++ b/pkg/inimpl/guancecloud/funcs/fn_exit.go @@ -11,11 +11,11 @@ import ( "github.com/GuanceCloud/platypus/pkg/errchain" ) -func ExitChecking(ctx *runtime.Context, node *ast.CallExpr) *errchain.PlError { +func ExitChecking(ctx *runtime.Task, node *ast.CallExpr) *errchain.PlError { return nil } -func Exit(ctx *runtime.Context, node *ast.CallExpr) *errchain.PlError { +func Exit(ctx *runtime.Task, node *ast.CallExpr) *errchain.PlError { ctx.SetExit() return nil } diff --git a/pkg/inimpl/guancecloud/funcs/fn_getkey.go b/pkg/inimpl/guancecloud/funcs/fn_getkey.go index a52dc19..f743a56 100644 --- a/pkg/inimpl/guancecloud/funcs/fn_getkey.go +++ b/pkg/inimpl/guancecloud/funcs/fn_getkey.go @@ -14,7 +14,7 @@ import ( "github.com/GuanceCloud/platypus/pkg/token" ) -func GetkeyChecking(ctx *runtime.Context, funcExpr *ast.CallExpr) *errchain.PlError { +func GetkeyChecking(ctx *runtime.Task, funcExpr *ast.CallExpr) *errchain.PlError { if len(funcExpr.Param) != 1 { return runtime.NewRunError(ctx, fmt.Sprintf( "func %s expected 1 args", funcExpr.Name), funcExpr.NamePos) @@ -27,7 +27,7 @@ func GetkeyChecking(ctx *runtime.Context, funcExpr *ast.CallExpr) *errchain.PlEr return nil } -func Getkey(ctx *runtime.Context, funcExpr *ast.CallExpr) *errchain.PlError { +func Getkey(ctx *runtime.Task, funcExpr *ast.CallExpr) *errchain.PlError { if funcExpr == nil { return runtime.NewRunError(ctx, "unreachable", token.InvalidLnColPos) } diff --git a/pkg/inimpl/guancecloud/funcs/fn_grok.go b/pkg/inimpl/guancecloud/funcs/fn_grok.go index 8744421..910c2ea 100644 --- a/pkg/inimpl/guancecloud/funcs/fn_grok.go +++ b/pkg/inimpl/guancecloud/funcs/fn_grok.go @@ -15,7 +15,7 @@ import ( "github.com/GuanceCloud/platypus/pkg/inimpl/guancecloud/input" ) -func GrokChecking(ctx *runtime.Context, funcExpr *ast.CallExpr) *errchain.PlError { +func GrokChecking(ctx *runtime.Task, funcExpr *ast.CallExpr) *errchain.PlError { if funcExpr.Grok != nil { return nil } @@ -57,7 +57,7 @@ func GrokChecking(ctx *runtime.Context, funcExpr *ast.CallExpr) *errchain.PlErro return nil } -func Grok(ctx *runtime.Context, funcExpr *ast.CallExpr) *errchain.PlError { +func Grok(ctx *runtime.Task, funcExpr *ast.CallExpr) *errchain.PlError { grokRe := funcExpr.Grok if grokRe == nil { ctx.Regs.ReturnAppend(false, ast.Bool) diff --git a/pkg/inimpl/guancecloud/funcs/fn_len.go b/pkg/inimpl/guancecloud/funcs/fn_len.go index bcd1be4..e96bc9b 100644 --- a/pkg/inimpl/guancecloud/funcs/fn_len.go +++ b/pkg/inimpl/guancecloud/funcs/fn_len.go @@ -13,7 +13,7 @@ import ( "github.com/GuanceCloud/platypus/pkg/errchain" ) -func LenChecking(ctx *runtime.Context, funcExpr *ast.CallExpr) *errchain.PlError { +func LenChecking(ctx *runtime.Task, funcExpr *ast.CallExpr) *errchain.PlError { if len(funcExpr.Param) != 1 { return runtime.NewRunError(ctx, fmt.Sprintf( "func %s expected 1", funcExpr.Name), funcExpr.NamePos) @@ -21,7 +21,7 @@ func LenChecking(ctx *runtime.Context, funcExpr *ast.CallExpr) *errchain.PlError return nil } -func Len(ctx *runtime.Context, funcExpr *ast.CallExpr) *errchain.PlError { +func Len(ctx *runtime.Task, funcExpr *ast.CallExpr) *errchain.PlError { val, dtype, err := runtime.RunStmt(ctx, funcExpr.Param[0]) if err != nil { return err diff --git a/pkg/inimpl/guancecloud/funcs/fn_load_json.go b/pkg/inimpl/guancecloud/funcs/fn_load_json.go index 1840e27..fa2179c 100644 --- a/pkg/inimpl/guancecloud/funcs/fn_load_json.go +++ b/pkg/inimpl/guancecloud/funcs/fn_load_json.go @@ -14,7 +14,7 @@ import ( "github.com/GuanceCloud/platypus/pkg/errchain" ) -func LoadJSONChecking(ctx *runtime.Context, funcExpr *ast.CallExpr) *errchain.PlError { +func LoadJSONChecking(ctx *runtime.Task, funcExpr *ast.CallExpr) *errchain.PlError { if len(funcExpr.Param) != 1 { return runtime.NewRunError(ctx, fmt.Sprintf( "func %s expected 1", funcExpr.Name), funcExpr.NamePos) @@ -22,7 +22,7 @@ func LoadJSONChecking(ctx *runtime.Context, funcExpr *ast.CallExpr) *errchain.Pl return nil } -func LoadJSON(ctx *runtime.Context, funcExpr *ast.CallExpr) *errchain.PlError { +func LoadJSON(ctx *runtime.Task, funcExpr *ast.CallExpr) *errchain.PlError { val, dtype, err := runtime.RunStmt(ctx, funcExpr.Param[0]) if err != nil { return err diff --git a/pkg/inimpl/guancecloud/funcs/fn_printf.go b/pkg/inimpl/guancecloud/funcs/fn_printf.go index 3f9c372..f5be111 100644 --- a/pkg/inimpl/guancecloud/funcs/fn_printf.go +++ b/pkg/inimpl/guancecloud/funcs/fn_printf.go @@ -14,7 +14,7 @@ import ( "github.com/spf13/cast" ) -func PrintfChecking(ctx *runtime.Context, funcExpr *ast.CallExpr) *errchain.PlError { +func PrintfChecking(ctx *runtime.Task, funcExpr *ast.CallExpr) *errchain.PlError { if len(funcExpr.Param) < 1 { return runtime.NewRunError(ctx, "function `%s' requires at least one argument", funcExpr.NamePos) } @@ -24,7 +24,7 @@ func PrintfChecking(ctx *runtime.Context, funcExpr *ast.CallExpr) *errchain.PlEr return nil } -func Printf(ctx *runtime.Context, funcExpr *ast.CallExpr) *errchain.PlError { +func Printf(ctx *runtime.Task, funcExpr *ast.CallExpr) *errchain.PlError { outdata := make([]interface{}, 0) if len(funcExpr.Param) < 1 { @@ -52,7 +52,7 @@ func Printf(ctx *runtime.Context, funcExpr *ast.CallExpr) *errchain.PlError { return nil } -func getArgStr(ctx *runtime.Context, node *ast.Node) string { +func getArgStr(ctx *runtime.Task, node *ast.Node) string { if node == nil { return "" } diff --git a/pkg/inimpl/guancecloud/funcs/fn_rename.go b/pkg/inimpl/guancecloud/funcs/fn_rename.go index 538c446..478712b 100644 --- a/pkg/inimpl/guancecloud/funcs/fn_rename.go +++ b/pkg/inimpl/guancecloud/funcs/fn_rename.go @@ -13,7 +13,7 @@ import ( "github.com/GuanceCloud/platypus/pkg/errchain" ) -func RenameChecking(ctx *runtime.Context, funcExpr *ast.CallExpr) *errchain.PlError { +func RenameChecking(ctx *runtime.Task, funcExpr *ast.CallExpr) *errchain.PlError { if len(funcExpr.Param) != 2 { return runtime.NewRunError(ctx, fmt.Sprintf( "func %s expected 2 args", funcExpr.Name), funcExpr.NamePos) @@ -33,7 +33,7 @@ func RenameChecking(ctx *runtime.Context, funcExpr *ast.CallExpr) *errchain.PlEr return nil } -func Rename(ctx *runtime.Context, funcExpr *ast.CallExpr) *errchain.PlError { +func Rename(ctx *runtime.Task, funcExpr *ast.CallExpr) *errchain.PlError { if len(funcExpr.Param) != 2 { return runtime.NewRunError(ctx, fmt.Sprintf( "func %s expected 2 args", funcExpr.Name), funcExpr.NamePos) diff --git a/pkg/inimpl/guancecloud/funcs/fn_replace.go b/pkg/inimpl/guancecloud/funcs/fn_replace.go index 9835f0b..115af5f 100644 --- a/pkg/inimpl/guancecloud/funcs/fn_replace.go +++ b/pkg/inimpl/guancecloud/funcs/fn_replace.go @@ -16,7 +16,7 @@ import ( "github.com/GuanceCloud/platypus/pkg/inimpl/guancecloud/input" ) -func ReplaceChecking(ctx *runtime.Context, funcExpr *ast.CallExpr) *errchain.PlError { +func ReplaceChecking(ctx *runtime.Task, funcExpr *ast.CallExpr) *errchain.PlError { if len(funcExpr.Param) != 3 { return runtime.NewRunError(ctx, fmt.Sprintf( "func %s expects 3 args", funcExpr.Name), funcExpr.NamePos) @@ -43,7 +43,7 @@ func ReplaceChecking(ctx *runtime.Context, funcExpr *ast.CallExpr) *errchain.PlE return nil } -func Replace(ctx *runtime.Context, funcExpr *ast.CallExpr) *errchain.PlError { +func Replace(ctx *runtime.Task, funcExpr *ast.CallExpr) *errchain.PlError { if len(funcExpr.Param) != 3 { return runtime.NewRunError(ctx, fmt.Sprintf( "func %s expects 3 args", funcExpr.Name), funcExpr.NamePos) diff --git a/pkg/inimpl/guancecloud/funcs/fn_set_measurement.go b/pkg/inimpl/guancecloud/funcs/fn_set_measurement.go index 7c504df..54bfb77 100644 --- a/pkg/inimpl/guancecloud/funcs/fn_set_measurement.go +++ b/pkg/inimpl/guancecloud/funcs/fn_set_measurement.go @@ -13,7 +13,7 @@ import ( "github.com/GuanceCloud/platypus/pkg/errchain" ) -func SetMeasurementChecking(ctx *runtime.Context, funcExpr *ast.CallExpr) *errchain.PlError { +func SetMeasurementChecking(ctx *runtime.Task, funcExpr *ast.CallExpr) *errchain.PlError { if len(funcExpr.Param) != 2 && len(funcExpr.Param) != 1 { return runtime.NewRunError(ctx, fmt.Sprintf( "func `%s' expected 1 or 2 args", funcExpr.Name), funcExpr.NamePos) @@ -34,7 +34,7 @@ func SetMeasurementChecking(ctx *runtime.Context, funcExpr *ast.CallExpr) *errch return nil } -func SetMeasurement(ctx *runtime.Context, funcExpr *ast.CallExpr) *errchain.PlError { +func SetMeasurement(ctx *runtime.Task, funcExpr *ast.CallExpr) *errchain.PlError { if len(funcExpr.Param) != 2 && len(funcExpr.Param) != 1 { return runtime.NewRunError(ctx, fmt.Sprintf( "func `%s' expected 1 or 2 args", funcExpr.Name), funcExpr.NamePos) diff --git a/pkg/inimpl/guancecloud/funcs/fn_set_tag.go b/pkg/inimpl/guancecloud/funcs/fn_set_tag.go index 1182b11..91b5d69 100644 --- a/pkg/inimpl/guancecloud/funcs/fn_set_tag.go +++ b/pkg/inimpl/guancecloud/funcs/fn_set_tag.go @@ -14,7 +14,7 @@ import ( "github.com/GuanceCloud/platypus/pkg/inimpl/guancecloud/input" ) -func SetTagChecking(ctx *runtime.Context, funcExpr *ast.CallExpr) *errchain.PlError { +func SetTagChecking(ctx *runtime.Task, funcExpr *ast.CallExpr) *errchain.PlError { if len(funcExpr.Param) != 2 && len(funcExpr.Param) != 1 { return runtime.NewRunError(ctx, fmt.Sprintf( "func `%s' expected 1 or 2 args", funcExpr.Name), funcExpr.NamePos) @@ -35,7 +35,7 @@ func SetTagChecking(ctx *runtime.Context, funcExpr *ast.CallExpr) *errchain.PlEr return nil } -func SetTag(ctx *runtime.Context, funcExpr *ast.CallExpr) *errchain.PlError { +func SetTag(ctx *runtime.Task, funcExpr *ast.CallExpr) *errchain.PlError { if len(funcExpr.Param) != 2 && len(funcExpr.Param) != 1 { return runtime.NewRunError(ctx, fmt.Sprintf( "func `%s' expected 1 or 2 args", funcExpr.Name), funcExpr.NamePos) diff --git a/pkg/inimpl/guancecloud/funcs/fn_sql_cover.go b/pkg/inimpl/guancecloud/funcs/fn_sql_cover.go index 0029c20..3d6b522 100644 --- a/pkg/inimpl/guancecloud/funcs/fn_sql_cover.go +++ b/pkg/inimpl/guancecloud/funcs/fn_sql_cover.go @@ -15,7 +15,7 @@ import ( "github.com/GuanceCloud/platypus/pkg/inimpl/guancecloud/input" ) -func SQLCoverChecking(ctx *runtime.Context, funcExpr *ast.CallExpr) *errchain.PlError { +func SQLCoverChecking(ctx *runtime.Task, funcExpr *ast.CallExpr) *errchain.PlError { if len(funcExpr.Param) != 1 { return runtime.NewRunError(ctx, fmt.Sprintf( "func %s expects 1 args", funcExpr.Name), funcExpr.NamePos) @@ -26,7 +26,7 @@ func SQLCoverChecking(ctx *runtime.Context, funcExpr *ast.CallExpr) *errchain.Pl return nil } -func SQLCover(ctx *runtime.Context, funcExpr *ast.CallExpr) *errchain.PlError { +func SQLCover(ctx *runtime.Task, funcExpr *ast.CallExpr) *errchain.PlError { o := obfuscate.NewObfuscator(obfuscate.Config{}) if len(funcExpr.Param) != 1 { return runtime.NewRunError(ctx, fmt.Sprintf( diff --git a/pkg/inimpl/guancecloud/funcs/fn_strfmt.go b/pkg/inimpl/guancecloud/funcs/fn_strfmt.go index ee04aad..3cec9fe 100644 --- a/pkg/inimpl/guancecloud/funcs/fn_strfmt.go +++ b/pkg/inimpl/guancecloud/funcs/fn_strfmt.go @@ -14,7 +14,7 @@ import ( "github.com/GuanceCloud/platypus/pkg/inimpl/guancecloud/input" ) -func StrfmtChecking(ctx *runtime.Context, funcExpr *ast.CallExpr) *errchain.PlError { +func StrfmtChecking(ctx *runtime.Task, funcExpr *ast.CallExpr) *errchain.PlError { if len(funcExpr.Param) < 2 { return runtime.NewRunError(ctx, fmt.Sprintf( "func `%s' expects more than 2 args", funcExpr.Name), funcExpr.NamePos) @@ -31,7 +31,7 @@ func StrfmtChecking(ctx *runtime.Context, funcExpr *ast.CallExpr) *errchain.PlEr return nil } -func Strfmt(ctx *runtime.Context, funcExpr *ast.CallExpr) *errchain.PlError { +func Strfmt(ctx *runtime.Task, funcExpr *ast.CallExpr) *errchain.PlError { outdata := make([]interface{}, 0) if len(funcExpr.Param) < 2 { diff --git a/pkg/inimpl/guancecloud/funcs/fn_trim.go b/pkg/inimpl/guancecloud/funcs/fn_trim.go index a71b496..c7823ec 100644 --- a/pkg/inimpl/guancecloud/funcs/fn_trim.go +++ b/pkg/inimpl/guancecloud/funcs/fn_trim.go @@ -15,7 +15,7 @@ import ( "github.com/GuanceCloud/platypus/pkg/inimpl/guancecloud/input" ) -func TrimChecking(ctx *runtime.Context, funcExpr *ast.CallExpr) *errchain.PlError { +func TrimChecking(ctx *runtime.Task, funcExpr *ast.CallExpr) *errchain.PlError { if len(funcExpr.Param) < 1 || len(funcExpr.Param) > 2 { return runtime.NewRunError(ctx, fmt.Sprintf( "func `%s' expected 1 or 2 args", funcExpr.Name), funcExpr.NamePos) @@ -34,7 +34,7 @@ func TrimChecking(ctx *runtime.Context, funcExpr *ast.CallExpr) *errchain.PlErro return nil } -func Trim(ctx *runtime.Context, funcExpr *ast.CallExpr) *errchain.PlError { +func Trim(ctx *runtime.Task, funcExpr *ast.CallExpr) *errchain.PlError { key, err := getKeyName(funcExpr.Param[0]) if err != nil { return runtime.NewRunError(ctx, err.Error(), funcExpr.Param[0].StartPos()) diff --git a/pkg/inimpl/guancecloud/funcs/fn_uppercase.go b/pkg/inimpl/guancecloud/funcs/fn_uppercase.go index e2b283b..f6ea349 100644 --- a/pkg/inimpl/guancecloud/funcs/fn_uppercase.go +++ b/pkg/inimpl/guancecloud/funcs/fn_uppercase.go @@ -15,7 +15,7 @@ import ( "github.com/GuanceCloud/platypus/pkg/inimpl/guancecloud/input" ) -func UppercaseChecking(ctx *runtime.Context, funcExpr *ast.CallExpr) *errchain.PlError { +func UppercaseChecking(ctx *runtime.Task, funcExpr *ast.CallExpr) *errchain.PlError { if len(funcExpr.Param) != 1 { return runtime.NewRunError(ctx, fmt.Sprintf( "func %s expects 1 arg", funcExpr.Name), funcExpr.NamePos) @@ -26,7 +26,7 @@ func UppercaseChecking(ctx *runtime.Context, funcExpr *ast.CallExpr) *errchain.P return nil } -func Uppercase(ctx *runtime.Context, funcExpr *ast.CallExpr) *errchain.PlError { +func Uppercase(ctx *runtime.Task, funcExpr *ast.CallExpr) *errchain.PlError { if len(funcExpr.Param) != 1 { return runtime.NewRunError(ctx, fmt.Sprintf( "func %s expects 1 args", funcExpr.Name), funcExpr.NamePos) diff --git a/pkg/inimpl/guancecloud/funcs/fn_urldecode.go b/pkg/inimpl/guancecloud/funcs/fn_urldecode.go index c370662..24b8caf 100644 --- a/pkg/inimpl/guancecloud/funcs/fn_urldecode.go +++ b/pkg/inimpl/guancecloud/funcs/fn_urldecode.go @@ -14,7 +14,7 @@ import ( "github.com/GuanceCloud/platypus/pkg/inimpl/guancecloud/input" ) -func URLDecodeChecking(ctx *runtime.Context, funcExpr *ast.CallExpr) *errchain.PlError { +func URLDecodeChecking(ctx *runtime.Task, funcExpr *ast.CallExpr) *errchain.PlError { if len(funcExpr.Param) != 1 { return runtime.NewRunError(ctx, fmt.Sprintf( "func `%s' expected 1 args", funcExpr.Name), funcExpr.NamePos) @@ -25,7 +25,7 @@ func URLDecodeChecking(ctx *runtime.Context, funcExpr *ast.CallExpr) *errchain.P return nil } -func URLDecode(ctx *runtime.Context, funcExpr *ast.CallExpr) *errchain.PlError { +func URLDecode(ctx *runtime.Task, funcExpr *ast.CallExpr) *errchain.PlError { if len(funcExpr.Param) != 1 { return runtime.NewRunError(ctx, fmt.Sprintf( "func `%s' expected 1 args", funcExpr.Name), funcExpr.NamePos) diff --git a/pkg/inimpl/guancecloud/funcs/fn_use.go b/pkg/inimpl/guancecloud/funcs/fn_use.go index e70fe9d..1eb4b66 100644 --- a/pkg/inimpl/guancecloud/funcs/fn_use.go +++ b/pkg/inimpl/guancecloud/funcs/fn_use.go @@ -13,7 +13,7 @@ import ( "github.com/GuanceCloud/platypus/pkg/errchain" ) -func UseChecking(ctx *runtime.Context, funcExpr *ast.CallExpr) *errchain.PlError { +func UseChecking(ctx *runtime.Task, funcExpr *ast.CallExpr) *errchain.PlError { if len(funcExpr.Param) != 1 { return runtime.NewRunError(ctx, fmt.Sprintf( "func %s expects 1 args", funcExpr.Name), funcExpr.NamePos) @@ -30,7 +30,7 @@ func UseChecking(ctx *runtime.Context, funcExpr *ast.CallExpr) *errchain.PlError return nil } -func Use(ctx *runtime.Context, funcExpr *ast.CallExpr) *errchain.PlError { +func Use(ctx *runtime.Task, funcExpr *ast.CallExpr) *errchain.PlError { if len(funcExpr.Param) != 1 { return runtime.NewRunError(ctx, fmt.Sprintf( "func %s expects 1 args", funcExpr.Name), funcExpr.NamePos) @@ -56,7 +56,7 @@ func Use(ctx *runtime.Context, funcExpr *ast.CallExpr) *errchain.PlError { funcExpr.Param[0].NodeType), funcExpr.Param[0].StartPos()) } - err := runtime.RefRunScript(ctx, refScript) + err := refScript.RefRun(ctx) if err != nil { return err.ChainAppend(ctx.Name(), funcExpr.NamePos) } diff --git a/pkg/inimpl/guancecloud/funcs/fn_xml.go b/pkg/inimpl/guancecloud/funcs/fn_xml.go index 19c9dac..c25ec55 100644 --- a/pkg/inimpl/guancecloud/funcs/fn_xml.go +++ b/pkg/inimpl/guancecloud/funcs/fn_xml.go @@ -17,7 +17,7 @@ import ( "github.com/antchfx/xmlquery" ) -func XMLChecking(ctx *runtime.Context, funcExpr *ast.CallExpr) *errchain.PlError { +func XMLChecking(ctx *runtime.Task, funcExpr *ast.CallExpr) *errchain.PlError { if len(funcExpr.Param) != 3 { return runtime.NewRunError(ctx, fmt.Sprintf( "func %s expects 3 args", funcExpr.Name), funcExpr.NamePos) @@ -48,7 +48,7 @@ func XMLChecking(ctx *runtime.Context, funcExpr *ast.CallExpr) *errchain.PlError return nil } -func XML(ctx *runtime.Context, funcExpr *ast.CallExpr) *errchain.PlError { +func XML(ctx *runtime.Task, funcExpr *ast.CallExpr) *errchain.PlError { var ( xmlKey, fieldName string xpathExpr string