Esempio n. 1
0
    def __mod__(self, other):
        if isinstance(other, (Integer, Float)):
            return Float(self.value % other.value)

        else:
            raise FXException("Can't calculate the modulo of a Float with a " +
                              str(type(other)))
Esempio n. 2
0
    def __floordiv__(self, other):
        if isinstance(other, (Integer, Float)):
            return Float(self.value // other.value)

        else:
            raise FXException("Can't floor divide Float by " +
                              str(type(other)))
Esempio n. 3
0
    def __sub__(self, other):
        if isinstance(other, (Integer, Float)):
            return Float(self.value - other.value)

        else:
            raise FXException("Can't subtract " + str(type(other)) +
                              " from Float")
Esempio n. 4
0
 def eval(self, cell, attrib, config, cell_dict):  # TODO
     if (self.name == "R"):
         return Integer(cell.row)
     elif (self.name == "C"):
         return Integer(cell.col)
     elif (self.name == "true"):
         return Boolean(True)
     elif (self.name == "false"):
         return Boolean(False)
     else:
         raise FXException("Unknown variable: " + self.name)
     ranges = file.File.parse_cell_ranges(self.name)
     if (len(ranges) > 1):
         raise FXException("Only 1 range can be specified as variable")
     coordinates = ranges[0].get_coordinates()
     if (len(coordinates) != 1):
         raise FXException("Only 1 cell can be specified as variable")
Esempio n. 5
0
    def __pow__(self, other):
        if self.value < 0:
            if isinstance(other, Integer):
                return Float(self.value**other.value)

            else:
                raise FXException(
                    "Can't raise a (negative) Float to the power of a " +
                    str(type(other)))

        else:
            if isinstance(other, (Float, Integer)):
                return Float(self.value**other.value)

            else:
                raise FXException("Can't raise a Float to the power of a " +
                                  str(type(other)))
Esempio n. 6
0
 def eval(self, cell, attrib, config, cell_dict):
     if self.op == '-':
         return -self.elem.eval(cell, attrib, config, cell_dict)
     elif self.op == '+':
         return +self.elem.eval(cell, attrib, config, cell_dict)
     elif self.op == 'not':
         return not self.elem.eval(cell, attrib, config, cell_dict)
     else:
         raise FXException()
Esempio n. 7
0
    def __truediv__(self, other):
        if isinstance(other, Integer):
            return Integer(self.value / other.value)

        elif isinstance(other, Float):
            return Float(self.value / other.value)

        else:
            raise FXException("Can't divide Integer by " + str(type(other)))
Esempio n. 8
0
    def __add__(self, other):
        if isinstance(other, Integer):
            return Integer(self.value + other.value)

        elif isinstance(other, Float):
            return Float(self.value + other.value)

        else:
            raise FXException("Can't add Integer to " + str(type(other)))
Esempio n. 9
0
    def __mul__(self, other):
        if isinstance(other, Integer):
            return Integer(self.value * other.value)

        elif isinstance(other, Float):
            return Float(self.value * other.value)

        else:
            raise FXException("Can't multiply Integer with " +
                              str(type(other)))
Esempio n. 10
0
    def eval_condition(self, lst, cell, attrib, config, cell_dict):
        if not lst:
            raise FXException("If statements need an else clause")

        if len(lst) == 1:
            return lst[0].eval(cell, attrib, config, cell_dict)

        else:
            if lst[0].eval(cell, attrib, config, cell_dict):
                return lst[1].eval(cell, attrib, config, cell_dict)
            else:
                return self.eval_condition(lst[2:], cell, attrib, config,
                                           cell_dict)
Esempio n. 11
0
    def __init__(self, path):
        self.path = path
        self.statements = []
        self.attrib = None
        self.expressions = {}

        if 'config.fx' != os.path.basename(self.path):
            try:
                self.attrib = constants.attrib_dict[os.path.basename(path)
                                                    [:-3]]
            except KeyError:
                raise FXException('Invalid file name: ' +
                                  os.path.basename(path))
Esempio n. 12
0
    def parse_cell_ranges(text):
        text = ''.join(text.split())

        cell_ranges = []
        cell_ranges_str = text.split(',')
        for cell_range_str in cell_ranges_str:
            matches = re.findall(r"([rcRC][0-9]+(:[0-9]+)?)", cell_range_str)
            matches = {s[0][0].upper(): s[0][1:] for s in matches}

            if len(matches) == 0:
                raise FXException("Invalid syntax")

            cell_ranges.append(CellRange(matches.get('R'), matches.get('C')))

        return cell_ranges
Esempio n. 13
0
    def parse(self):
        if not 'config.fx' in os.listdir(self.directory):
            raise FXException('Every FRuTeX project needs a config file')
        
        fx_files = [filename for filename in os.listdir(self.directory)
            if os.path.splitext(filename)[1] == '.fx'
            and os.path.basename(filename) != 'config.fx']

        self.config = Config(self.directory + '/config.fx')
        self.config.parse()
    
        files = {}
        for filename in fx_files:
            file = File(self.directory + '/' + filename)
            file.parse()
            files.update({file.attrib: file})
            
        self.files = files
        
        for file in self.files.values():
            file.apply_statements(self.config, self.cell_dict, None)
Esempio n. 14
0
    def __init__(self, args, dependent_info):
        if type(args) != list or len(args) != 1:
            raise FXException("Illegal arguments to getColor(): " + str(args))

        super().__init__(args, dependent_info)
Esempio n. 15
0
    def __ne__(self, other):
        if not isinstance(other, (Integer, Float)):
            raise FXException("Can't compare Integer to " + str(type(other)))

        return Boolean(self.value != other.value)