mirror of
https://github.com/chaisql/chai.git
synced 2025-10-08 00:50:52 +08:00
stream: clone stream before execution
This commit is contained in:
@@ -15,6 +15,12 @@ type Lower struct {
|
||||
Expr expr.Expr
|
||||
}
|
||||
|
||||
func (s *Lower) Clone() expr.Expr {
|
||||
return &Lower{
|
||||
Expr: expr.Clone(s.Expr),
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Lower) Eval(env *environment.Environment) (types.Value, error) {
|
||||
val, err := s.Expr.Eval(env)
|
||||
if err != nil {
|
||||
@@ -55,6 +61,12 @@ type Upper struct {
|
||||
Expr expr.Expr
|
||||
}
|
||||
|
||||
func (s *Upper) Clone() expr.Expr {
|
||||
return &Upper{
|
||||
Expr: expr.Clone(s.Expr),
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Upper) Eval(env *environment.Environment) (types.Value, error) {
|
||||
val, err := s.Expr.Eval(env)
|
||||
if err != nil {
|
||||
@@ -101,6 +113,18 @@ type Trim struct {
|
||||
|
||||
type TrimFunc func(string, string) string
|
||||
|
||||
func (s *Trim) Clone() expr.Expr {
|
||||
exprs := make([]expr.Expr, len(s.Expr))
|
||||
for i := range s.Expr {
|
||||
exprs[i] = expr.Clone(s.Expr[i])
|
||||
}
|
||||
return &Trim{
|
||||
Expr: exprs,
|
||||
TrimFunc: s.TrimFunc,
|
||||
Name: s.Name,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Trim) Eval(env *environment.Environment) (types.Value, error) {
|
||||
if len(s.Expr) > 2 {
|
||||
return nil, fmt.Errorf("misuse of string function %v()", s.Name)
|
||||
|
Reference in New Issue
Block a user