Compare commits

...

2 Commits

Author SHA1 Message Date
Elara 1196942801 Clean up ParseValue() 2021-03-02 00:27:28 -08:00
Elara 412079c20a Remove index variable after loop completion 2021-03-02 00:18:52 -08:00
2 changed files with 48 additions and 41 deletions

1
ast.go
View File

@ -115,6 +115,7 @@ func executeCmd(cmd *Command) error {
}
}
}
delete(Vars, *RptLoop.IndexVar)
}
}
return nil

16
scpt.go
View File

@ -98,16 +98,24 @@ func ParseValue(val *Value) (interface{}, error) {
// Return value of provided key
return Vars[*val.VarVal], nil
} else if val.Expr != nil {
// Return evaluated expression
return evalExpr(*val.Expr)
}
return nil, nil
}
// Evaluate given expression, returning its value and optionally an error
func evalExpr(expression Expression) (interface{}, error) {
// Parse value of left side of expression
left, _ := callIfFunc(ParseValue(val.Expr.Left))
left, _ := callIfFunc(ParseValue(expression.Left))
// If value is string, requote
if isStr(left) {
left = requoteStr(left.(string))
}
// Create new nil string
var right string
// For every right segment
for _, segment := range val.Expr.RightSegs {
// For every right gsegment
for _, segment := range expression.RightSegs {
// Parse value of right segment, calling it if it is a function
rVal, _ := callIfFunc(ParseValue(segment.Right))
// If value is string, requote
@ -139,8 +147,6 @@ func ParseValue(val *Value) (interface{}, error) {
}
// Return expression output value
return out, nil
}
return nil, nil
}
// Add quotes to an unquoted string