provisional implementation of the postfix ++ operator

This commit is contained in:
Celestino Amoroso 2024-04-26 04:37:50 +02:00
parent d354102c6a
commit b14dc2f1ee

41
operator-post-inc.go Normal file
View File

@ -0,0 +1,41 @@
// Copyright (c) 2024 Celestino Amoroso (celestino.amoroso@gmail.com).
// All rights reserved.
// operator-post-inc.go
package expr
// -------- post increment term
func newPostIncTerm(tk *Token) *term {
return &term{
tk: *tk,
parent: nil,
children: make([]*term, 0, 1),
position: posPostfix,
priority: priPrePost,
evalFunc: evalPostInc,
}
}
func evalPostInc(ctx ExprContext, self *term) (v any, err error) {
var leftValue any
if leftValue, err = self.evalPrefix(ctx); err != nil {
return
}
if dc, ok := leftValue.(*dataCursor); ok {
v, err = dc.Next()
} else if isInteger(leftValue) && self.children[0].symbol() == SymIdentifier {
v = leftValue
i, _ := leftValue.(int64)
ctx.SetVar(self.children[0].source(), i+1)
} else {
self.errIncompatibleType(leftValue)
}
return
}
// init
func init() {
registerTermConstructor(SymDoublePlus, newPostIncTerm)
}