#!/usr/bin/env python
# -*- coding: utf8 -*-

from GenericFile import *

class FPParser (GenericFile):

    name = "Funkcja Przełączająca"
    extension = 'FP'

    def __init__(self, content=None):
        GenericFile.__init__(self, content)

        if content is not None:

            self._function = content

            self.in_alphabet = self.out_alphabet = 2

    def parse_body(self, content):
        values = pow(2, self.args)

        if not re.compile('^[\-\da-zA-Z]{' + str(values)
                + '}$').match(content[0]):
            #TODO: Exception - bad line
            pass

        self._function = [self.char_to_value(char) for char in content[0]]

    def prepare_body(self):
        result = ""

        for value in self._function:
            result += self.value_to_char(value)

        return result

    def convert_to_FP(self):
        return self._function
