Example #1
0
 def add_to(self, other):
     """
     Concatenate String instances together.
     :param other: Other String instance.
     :return: New concatenated String instance.
     """
     if isinstance(other, String):
         return String(self.value + other.value).set_context(
             self.context), None
     return None, Value.illegal_operation(self, other)
Example #2
0
 def multiply_by(self, other):
     """
     Multiply a String by a Number instance.
     :param other: Number instance.
     :return: New String written out Number-times.
     """
     if isinstance(other, Number):
         return String(self.value * other.value).set_context(
             self.context), None
     return None, Value.illegal_operation(self, other)
Example #3
0
 def power_by(self, other):
     """
     Raise two Number values together.
     No possible errors can occur for power operations between Numbers.
     :param other: Number instance.
     :return: Number instance with the multiplied value.
     """
     if isinstance(other, Number):
         return Number(self.value**other.value).set_context(
             self.context), None
     else:
         return None, Value.illegal_operation(other)
Example #4
0
 def subtract_by(self, other):
     """
     Subtract two Number values together.
     No possible errors can occur for subtraction between Numbers.
     :param other: Number instance.
     :return: Number instance with the subtracted value.
     """
     if isinstance(other, Number):
         return Number(self.value - other.value).set_context(
             self.context), None
     else:
         return None, Value.illegal_operation(other)
Example #5
0
 def add_to(self, other):
     """
     Add two Number values together.
     No possible errors can occur for addition between Numbers.
     :param other: Number instance.
     :return: Number instance with the summed value.
     """
     if isinstance(other, Number):
         return Number(self.value + other.value).set_context(
             self.context), None
     else:
         return None, Value.illegal_operation(other)
Example #6
0
 def modulo_by(self, other):
     """
     Takes modulo of two Number values.
     :param other: Number instance.
     :return: Number instance with the modulo remainder value.
     """
     if isinstance(other, Number):
         if other.value == 0:
             return None, ActiveRuntimeError('Division by 0 not allowed',
                                             other.start_pos, other.end_pos,
                                             self.context)
         return Number(self.value % other.value).set_context(
             self.context), None
     else:
         return None, Value.illegal_operation(other)
Example #7
0
 def divide_by(self, other, clean=False):
     """
     Divide two Number values together.
     :param other: Number instance.
     :param clean: True to perform a clean division.
     :return: Number instance with the divided value.
     """
     if isinstance(other, Number):
         if other.value == 0:
             return None, ActiveRuntimeError('Division by 0 not allowed',
                                             other.start_pos, other.end_pos,
                                             self.context)
         if clean:  # Perform integer division
             return Number(self.value // other.value).set_context(
                 self.context), None
         else:  # Perform regular floating point division
             return Number(self.value / other.value).set_context(
                 self.context), None
     else:
         return None, Value.illegal_operation(other)