operator-post-inc.go: new post int decrement operator '--'
This commit is contained in:
parent
ffe1fa3aac
commit
ab06702e5e
@ -35,7 +35,39 @@ func evalPostInc(ctx ExprContext, opTerm *term) (v any, err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// -------- post decrement term
|
||||||
|
|
||||||
|
func newPostDecTerm(tk *Token) *term {
|
||||||
|
return &term{
|
||||||
|
tk: *tk,
|
||||||
|
parent: nil,
|
||||||
|
children: make([]*term, 0, 1),
|
||||||
|
position: posPostfix,
|
||||||
|
priority: priIncDec,
|
||||||
|
evalFunc: evalPostDec,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func evalPostDec(ctx ExprContext, opTerm *term) (v any, err error) {
|
||||||
|
var childValue any
|
||||||
|
if childValue, err = opTerm.evalPrefix(ctx); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
/* if it, ok := childValue.(Iterator); ok {
|
||||||
|
v, err = it.Next()
|
||||||
|
} else */if IsInteger(childValue) && opTerm.children[0].symbol() == SymVariable {
|
||||||
|
v = childValue
|
||||||
|
i, _ := childValue.(int64)
|
||||||
|
ctx.SetVar(opTerm.children[0].source(), i-1)
|
||||||
|
} else {
|
||||||
|
err = opTerm.errIncompatibleType(childValue)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// init
|
// init
|
||||||
func init() {
|
func init() {
|
||||||
registerTermConstructor(SymDoublePlus, newPostIncTerm)
|
registerTermConstructor(SymDoublePlus, newPostIncTerm)
|
||||||
|
registerTermConstructor(SymDoubleMinus, newPostDecTerm)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user