forked from influxdata/kapacitor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
scope.go
38 lines (31 loc) · 770 Bytes
/
scope.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package tick
// Contains a set of variables references and their values.
type Scope struct {
variables map[string]interface{}
}
//Initialize a new Scope object.
func NewScope() *Scope {
return &Scope{
variables: make(map[string]interface{}),
}
}
// Set defines a name -> value pairing in the scope.
func (s *Scope) Set(name string, value interface{}) {
s.variables[name] = value
}
// Get returns the value of 'name' or nil if it does not exist.
func (s *Scope) Get(name string) interface{} {
if v, ok := s.variables[name]; ok {
return v
}
return nil
}
// Evaluate a given DSL script for a given scope.
func Evaluate(script string, scope *Scope) (err error) {
ast, err := parse(script)
if err != nil {
return err
}
err = ast.Eval(scope)
return
}