self param replaced as opTerm
This commit is contained in:
+6
-21
@@ -59,18 +59,18 @@ func verifyRange(indexTerm *term, indexList *ListType, maxValue int) (startIndex
|
||||
return
|
||||
}
|
||||
|
||||
func evalIndex(ctx ExprContext, self *term) (v any, err error) {
|
||||
func evalIndex(ctx ExprContext, opTerm *term) (v any, err error) {
|
||||
var leftValue, rightValue any
|
||||
var indexList *ListType
|
||||
var ok bool
|
||||
|
||||
if leftValue, rightValue, err = self.evalInfix(ctx); err != nil {
|
||||
if leftValue, rightValue, err = opTerm.evalInfix(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
indexTerm := self.children[1]
|
||||
indexTerm := opTerm.children[1]
|
||||
if indexList, ok = rightValue.(*ListType); !ok {
|
||||
err = self.Errorf("invalid index expression")
|
||||
err = opTerm.Errorf("invalid index expression")
|
||||
return
|
||||
} else if len(*indexList) != 1 {
|
||||
err = indexTerm.Errorf("one index only is allowed")
|
||||
@@ -90,16 +90,9 @@ func evalIndex(ctx ExprContext, self *term) (v any, err error) {
|
||||
v = string(unboxedValue[index])
|
||||
}
|
||||
case *DictType:
|
||||
/* var ok bool
|
||||
var indexValue any
|
||||
if indexValue, err = verifyKey(indexTerm, indexList); err == nil {
|
||||
if v, ok = (*unboxedValue)[indexValue]; !ok {
|
||||
err = indexTerm.Errorf("key %v does not belong to the dictionary", rightValue)
|
||||
}
|
||||
} */
|
||||
v, err = getDictItem(unboxedValue, indexTerm, indexList, rightValue)
|
||||
default:
|
||||
err = self.errIncompatibleTypes(leftValue, rightValue)
|
||||
err = opTerm.errIncompatibleTypes(leftValue, rightValue)
|
||||
}
|
||||
} else if isIntPair((*indexList)[0]) {
|
||||
switch unboxedValue := leftValue.(type) {
|
||||
@@ -115,18 +108,10 @@ func evalIndex(ctx ExprContext, self *term) (v any, err error) {
|
||||
v = unboxedValue[start:end]
|
||||
}
|
||||
default:
|
||||
err = self.errIncompatibleTypes(leftValue, rightValue)
|
||||
err = opTerm.errIncompatibleTypes(leftValue, rightValue)
|
||||
}
|
||||
} else if IsDict(leftValue) {
|
||||
d := leftValue.(*DictType)
|
||||
|
||||
/* var ok bool
|
||||
var indexValue any
|
||||
if indexValue, err = verifyKey(indexTerm, indexList); err == nil {
|
||||
if v, ok = (*d)[indexValue]; !ok {
|
||||
err = indexTerm.Errorf("key %v does not belong to the dictionary", rightValue)
|
||||
}
|
||||
}*/
|
||||
v, err = getDictItem(d, indexTerm, indexList, rightValue)
|
||||
}
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user