Added new special operators like &= and <<=.
Also made a litle change to scanner function moveOn(): now it moves on the last char passed and only if there are more than one chars.
This commit is contained in:
+22
-30
@@ -4,7 +4,7 @@
|
||||
// operator-shift.go
|
||||
package expr
|
||||
|
||||
//-------- shift term
|
||||
//-------- bit right shift term
|
||||
|
||||
func newRightShiftTerm(tk *Token) (inst *term) {
|
||||
return &term{
|
||||
@@ -16,13 +16,7 @@ func newRightShiftTerm(tk *Token) (inst *term) {
|
||||
}
|
||||
}
|
||||
|
||||
func evalRightShift(ctx ExprContext, opTerm *term) (v any, err error) {
|
||||
var leftValue, rightValue any
|
||||
|
||||
if leftValue, rightValue, err = opTerm.evalInfix(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
func bitRightShift(opTerm *term, leftValue, rightValue any) (v any, err error) {
|
||||
if IsInteger(leftValue) && IsInteger(rightValue) {
|
||||
leftInt := leftValue.(int64)
|
||||
rightInt := rightValue.(int64)
|
||||
@@ -33,6 +27,17 @@ func evalRightShift(ctx ExprContext, opTerm *term) (v any, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func evalRightShift(ctx ExprContext, opTerm *term) (v any, err error) {
|
||||
var leftValue, rightValue any
|
||||
|
||||
if leftValue, rightValue, err = opTerm.evalInfix(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
v, err = bitRightShift(opTerm, leftValue, rightValue)
|
||||
return
|
||||
}
|
||||
|
||||
func newLeftShiftTerm(tk *Token) (inst *term) {
|
||||
return &term{
|
||||
tk: *tk,
|
||||
@@ -43,13 +48,7 @@ func newLeftShiftTerm(tk *Token) (inst *term) {
|
||||
}
|
||||
}
|
||||
|
||||
func evalLeftShift(ctx ExprContext, opTerm *term) (v any, err error) {
|
||||
var leftValue, rightValue any
|
||||
|
||||
if leftValue, rightValue, err = opTerm.evalInfix(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
func bitLeftShift(opTerm *term, leftValue, rightValue any) (v any, err error) {
|
||||
if IsInteger(leftValue) && IsInteger(rightValue) {
|
||||
leftInt := leftValue.(int64)
|
||||
rightInt := rightValue.(int64)
|
||||
@@ -60,23 +59,16 @@ func evalLeftShift(ctx ExprContext, opTerm *term) (v any, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
// func evalAssignAppend(ctx ExprContext, self *term) (v any, err error) {
|
||||
// var leftValue, rightValue any
|
||||
func evalLeftShift(ctx ExprContext, opTerm *term) (v any, err error) {
|
||||
var leftValue, rightValue any
|
||||
|
||||
// if leftValue, rightValue, err = self.evalInfix(ctx); err != nil {
|
||||
// return
|
||||
// }
|
||||
if leftValue, rightValue, err = opTerm.evalInfix(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
// if IsList(leftValue) {
|
||||
// list, _ := leftValue.(*ListType)
|
||||
// newList := append(*list, rightValue)
|
||||
// v = &newList
|
||||
// if
|
||||
// } else {
|
||||
// err = self.errIncompatibleTypes(leftValue, rightValue)
|
||||
// }
|
||||
// return
|
||||
// }
|
||||
v, err = bitLeftShift(opTerm, leftValue, rightValue)
|
||||
return
|
||||
}
|
||||
|
||||
// init
|
||||
func init() {
|
||||
|
||||
Reference in New Issue
Block a user