diff options
author | Wim <wim@42.be> | 2023-08-05 20:43:19 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-05 20:43:19 +0200 |
commit | 56e7bd01ca09ad52b0c4f48f146a20a4f1b78696 (patch) | |
tree | b1355645342667209263cbd355dc0b4254f1e8fe /vendor/github.com/d5/tengo/v2 | |
parent | 9459495484d6e06a3d46de64fccd8d06f7ccc72c (diff) | |
download | matterbridge-msglm-56e7bd01ca09ad52b0c4f48f146a20a4f1b78696.tar.gz matterbridge-msglm-56e7bd01ca09ad52b0c4f48f146a20a4f1b78696.tar.bz2 matterbridge-msglm-56e7bd01ca09ad52b0c4f48f146a20a4f1b78696.zip |
Diffstat (limited to 'vendor/github.com/d5/tengo/v2')
-rw-r--r-- | vendor/github.com/d5/tengo/v2/parser/parser.go | 1 | ||||
-rw-r--r-- | vendor/github.com/d5/tengo/v2/script.go | 4 | ||||
-rw-r--r-- | vendor/github.com/d5/tengo/v2/stdlib/json/decode.go | 16 | ||||
-rw-r--r-- | vendor/github.com/d5/tengo/v2/stdlib/math.go | 36 | ||||
-rw-r--r-- | vendor/github.com/d5/tengo/v2/stdlib/times.go | 68 |
5 files changed, 106 insertions, 19 deletions
diff --git a/vendor/github.com/d5/tengo/v2/parser/parser.go b/vendor/github.com/d5/tengo/v2/parser/parser.go index eaa9dc93..a12af614 100644 --- a/vendor/github.com/d5/tengo/v2/parser/parser.go +++ b/vendor/github.com/d5/tengo/v2/parser/parser.go @@ -143,6 +143,7 @@ func (p *Parser) ParseFile() (file *File, err error) { } stmts := p.parseStmtList() + p.expect(token.EOF) if p.errors.Len() > 0 { return nil, p.errors.Err() } diff --git a/vendor/github.com/d5/tengo/v2/script.go b/vendor/github.com/d5/tengo/v2/script.go index 4cca4d04..16f2944b 100644 --- a/vendor/github.com/d5/tengo/v2/script.go +++ b/vendor/github.com/d5/tengo/v2/script.go @@ -247,8 +247,8 @@ func (c *Compiled) RunContext(ctx context.Context) (err error) { // Clone creates a new copy of Compiled. Cloned copies are safe for concurrent // use by multiple goroutines. func (c *Compiled) Clone() *Compiled { - c.lock.Lock() - defer c.lock.Unlock() + c.lock.RLock() + defer c.lock.RUnlock() clone := &Compiled{ globalIndexes: c.globalIndexes, diff --git a/vendor/github.com/d5/tengo/v2/stdlib/json/decode.go b/vendor/github.com/d5/tengo/v2/stdlib/json/decode.go index 6d468ef0..557fb9ea 100644 --- a/vendor/github.com/d5/tengo/v2/stdlib/json/decode.go +++ b/vendor/github.com/d5/tengo/v2/stdlib/json/decode.go @@ -62,9 +62,12 @@ func (d *decodeState) scanNext() { // scanWhile processes bytes in d.data[d.off:] until it // receives a scan code not equal to op. -func (d *decodeState) scanWhile(op int) { +func (d *decodeState) scanWhile(op int) (isFloat bool) { s, data, i := &d.scan, d.data, d.off for i < len(data) { + if data[i] == '.' || data[i] == 'e' || data[i] == 'E' { + isFloat = true + } newOp := s.step(s, data[i]) i++ if newOp != op { @@ -76,6 +79,7 @@ func (d *decodeState) scanWhile(op int) { d.off = len(data) + 1 // mark processed EOF with len+1 d.opcode = d.scan.eof() + return } func (d *decodeState) value() (tengo.Object, error) { @@ -185,7 +189,7 @@ func (d *decodeState) object() (tengo.Object, error) { func (d *decodeState) literal() (tengo.Object, error) { // All bytes inside literal return scanContinue op code. start := d.readIndex() - d.scanWhile(scanContinue) + isFloat := d.scanWhile(scanContinue) item := d.data[start:d.readIndex()] @@ -210,8 +214,12 @@ func (d *decodeState) literal() (tengo.Object, error) { if c != '-' && (c < '0' || c > '9') { panic(phasePanicMsg) } - n, _ := strconv.ParseFloat(string(item), 10) - return &tengo.Float{Value: n}, nil + if isFloat { + n, _ := strconv.ParseFloat(string(item), 10) + return &tengo.Float{Value: n}, nil + } + n, _ := strconv.ParseInt(string(item), 10, 64) + return &tengo.Int{Value: n}, nil } } diff --git a/vendor/github.com/d5/tengo/v2/stdlib/math.go b/vendor/github.com/d5/tengo/v2/stdlib/math.go index 633ea09f..1bd9ba69 100644 --- a/vendor/github.com/d5/tengo/v2/stdlib/math.go +++ b/vendor/github.com/d5/tengo/v2/stdlib/math.go @@ -7,17 +7,31 @@ import ( ) var mathModule = map[string]tengo.Object{ - "e": &tengo.Float{Value: math.E}, - "pi": &tengo.Float{Value: math.Pi}, - "phi": &tengo.Float{Value: math.Phi}, - "sqrt2": &tengo.Float{Value: math.Sqrt2}, - "sqrtE": &tengo.Float{Value: math.SqrtE}, - "sqrtPi": &tengo.Float{Value: math.SqrtPi}, - "sqrtPhi": &tengo.Float{Value: math.SqrtPhi}, - "ln2": &tengo.Float{Value: math.Ln2}, - "log2E": &tengo.Float{Value: math.Log2E}, - "ln10": &tengo.Float{Value: math.Ln10}, - "log10E": &tengo.Float{Value: math.Log10E}, + "e": &tengo.Float{Value: math.E}, + "pi": &tengo.Float{Value: math.Pi}, + "phi": &tengo.Float{Value: math.Phi}, + "sqrt2": &tengo.Float{Value: math.Sqrt2}, + "sqrtE": &tengo.Float{Value: math.SqrtE}, + "sqrtPi": &tengo.Float{Value: math.SqrtPi}, + "sqrtPhi": &tengo.Float{Value: math.SqrtPhi}, + "ln2": &tengo.Float{Value: math.Ln2}, + "log2E": &tengo.Float{Value: math.Log2E}, + "ln10": &tengo.Float{Value: math.Ln10}, + "log10E": &tengo.Float{Value: math.Log10E}, + "maxFloat32": &tengo.Float{Value: math.MaxFloat32}, + "smallestNonzeroFloat32": &tengo.Float{Value: math.SmallestNonzeroFloat32}, + "maxFloat64": &tengo.Float{Value: math.MaxFloat64}, + "smallestNonzeroFloat64": &tengo.Float{Value: math.SmallestNonzeroFloat64}, + "maxInt": &tengo.Int{Value: math.MaxInt}, + "minInt": &tengo.Int{Value: math.MinInt}, + "maxInt8": &tengo.Int{Value: math.MaxInt8}, + "minInt8": &tengo.Int{Value: math.MinInt8}, + "maxInt16": &tengo.Int{Value: math.MaxInt16}, + "minInt16": &tengo.Int{Value: math.MinInt16}, + "maxInt32": &tengo.Int{Value: math.MaxInt32}, + "minInt32": &tengo.Int{Value: math.MinInt32}, + "maxInt64": &tengo.Int{Value: math.MaxInt64}, + "minInt64": &tengo.Int{Value: math.MinInt64}, "abs": &tengo.UserFunction{ Name: "abs", Value: FuncAFRF(math.Abs), diff --git a/vendor/github.com/d5/tengo/v2/stdlib/times.go b/vendor/github.com/d5/tengo/v2/stdlib/times.go index 0b6f7bd4..dc9a1a56 100644 --- a/vendor/github.com/d5/tengo/v2/stdlib/times.go +++ b/vendor/github.com/d5/tengo/v2/stdlib/times.go @@ -180,6 +180,10 @@ var timesModule = map[string]tengo.Object{ Name: "to_utc", Value: timesToUTC, }, // to_utc(time) => time + "in_location": &tengo.UserFunction{ + Name: "in_location", + Value: timesInLocation, + }, // in_location(time, location) => time } func timesSleep(args ...tengo.Object) (ret tengo.Object, err error) { @@ -430,7 +434,7 @@ func timesDate(args ...tengo.Object) ( ret tengo.Object, err error, ) { - if len(args) != 7 { + if len(args) < 7 || len(args) > 8 { err = tengo.ErrWrongNumArguments return } @@ -499,9 +503,29 @@ func timesDate(args ...tengo.Object) ( return } + var loc *time.Location + if len(args) == 8 { + i8, ok := tengo.ToString(args[7]) + if !ok { + err = tengo.ErrInvalidArgumentType{ + Name: "eighth", + Expected: "string(compatible)", + Found: args[7].TypeName(), + } + return + } + loc, err = time.LoadLocation(i8) + if err != nil { + ret = wrapError(err) + return + } + } else { + loc = time.Now().Location() + } + ret = &tengo.Time{ Value: time.Date(i1, - time.Month(i2), i3, i4, i5, i6, i7, time.Now().Location()), + time.Month(i2), i3, i4, i5, i6, i7, loc), } return @@ -1113,6 +1137,46 @@ func timesTimeLocation(args ...tengo.Object) ( return } +func timesInLocation(args ...tengo.Object) ( + ret tengo.Object, + err error, +) { + if len(args) != 2 { + err = tengo.ErrWrongNumArguments + return + } + + t1, ok := tengo.ToTime(args[0]) + if !ok { + err = tengo.ErrInvalidArgumentType{ + Name: "first", + Expected: "time(compatible)", + Found: args[0].TypeName(), + } + return + } + + s2, ok := tengo.ToString(args[1]) + if !ok { + err = tengo.ErrInvalidArgumentType{ + Name: "second", + Expected: "string(compatible)", + Found: args[1].TypeName(), + } + return + } + + location, err := time.LoadLocation(s2) + if err != nil { + ret = wrapError(err) + return + } + + ret = &tengo.Time{Value: t1.In(location)} + + return +} + func timesTimeString(args ...tengo.Object) (ret tengo.Object, err error) { if len(args) != 1 { err = tengo.ErrWrongNumArguments |