// NumberValue 将所有整型和浮点型处理为 Float ,其它类型不接受 func NumberValue(st p.State) (interface{}, error) { v, err := st.Next() if err != nil { return nil, err } switch val := v.(type) { case int: return Float(val), nil case int8: return Float(val), nil case int16: return Float(val), nil case int32: return Float(val), nil case int64: return Float(val), nil case Int: return Float(val), nil case float32: return Float(val), nil case float64: return Float(val), nil case Float: return val, nil default: return nil, NotNumberError{v} } }
// IntValue 将所有整型处理为 Int ,其它类型不接受 func IntValue(st p.State) (interface{}, error) { v, err := st.Next() if err != nil { return nil, err } switch val := v.(type) { case int: return Int(val), nil case int8: return Int(val), nil case int16: return Int(val), nil case int32: return Int(val), nil case int64: return Int(val), nil case Int: return val, nil default: return nil, NotIntError{v} } }
// not equals function, NotEqual or !=, if anyone is nil, return false func neqsOption(st p.State) (interface{}, error) { x, err := st.Next() if err != nil { return nil, err } if x == nil { return false, nil } for { y, err := st.Next() if err != nil { if reflect.DeepEqual(err, io.EOF) { return false, nil } return nil, err } if y == nil { return false, nil } if !reflect.DeepEqual(x, y) { return true, nil } } }