コード例 #1
0
ファイル: sym_kchar.py プロジェクト: 4sp1r3/appreal
    def accept(self, text):
        """
            If symbol is at the beginning of the text, is removed from the text and reminder is returned. Otherwise accept_exception is raised.
            
            :param text: Text to be parsed.
            :type text: string
            
            :returns: Text without begining.
            :rtype: string
            
            :rises: accept_exception if symbol is not at the begining of the text.
        """
        acceptable = True
        epsCnt = 0

        search_len = len(self.kchar) - self.last
        
        if len(text) < search_len:
            raise pattern_exceptions.symbol_string_to_short()

        for i in range(0, search_len):
            if isinstance(self.kchar[i], frozenset):
                kacceptable = False
                for char in self.kchar[i]:
                    if char == "":
                        kacceptable = True
                        epsCnt += 1
                    if text[i] == char[0]:
                        kacceptable = True
                if kacceptable == True:
                    acceptable = True
                else:
                    raise pattern_exceptions.symbol_accept_exception()
            else:
                if self.kchar[i] == "":
                    acceptable = True
                    epsCnt += 1
                if text[i] == self.kchar[i][0]:
                    acceptable = True
                else:
                    raise pattern_exceptions.symbol_accept_exception()

        if self.eof == True and len(text) > search_len:
            acceptable = False
                
        if acceptable == True:
            if epsCnt == len(self.kchar):
                return text
            else:
                return text[search_len:]
        else:
            raise pattern_exceptions.symbol_accept_exception()
コード例 #2
0
    def accept(self, text):
        """
            If symbol is at the beginning of the text, it's removed from the text and reminder is returned. Otherwise accept_exception is raised.
            
            :param text: Text to be parsed.
            :type text: string
            
            :returns: Text without begining.
            :rtype: string
            
            :rises: accept_exception if symbol is not at the begining of the text.
        """
        found = False
        output = str()

        if len(text) == 0:
            raise pattern_exceptions.symbol_string_to_short()

        if "" in self.charClass:
            found = True
            output = text
        if text[0] in self.charClass:
            found = True
            output = text[1:]

        if found == True:
            return output
        else:
            raise pattern_exceptions.symbol_accept_exception()
コード例 #3
0
ファイル: sym_char_class.py プロジェクト: 4sp1r3/appreal
    def accept(self, text):
        """
            If symbol is at the beginning of the text, it's removed from the text and reminder is returned. Otherwise accept_exception is raised.
            
            :param text: Text to be parsed.
            :type text: string
            
            :returns: Text without begining.
            :rtype: string
            
            :rises: accept_exception if symbol is not at the begining of the text.
        """
        found = False
        output = str()

        if len(text) == 0:
            raise pattern_exceptions.symbol_string_to_short()

        if "" in self.charClass:
            found = True
            output = text
        if text[0] in self.charClass:
            found = True
            output = text[1:]

        if found == True:
            return output
        else:
            raise pattern_exceptions.symbol_accept_exception()
コード例 #4
0
ファイル: sym_kstring.py プロジェクト: 4sp1r3/appreal
    def accept(self, text):
        """
            If symbol is at the beginning of the text, is removed from the text and reminder is returned. Otherwise accept_exception is raised.
            
            :param text: Text to be parsed.
            :type text: string
            
            :returns: Text without begining.
            :rtype: string
            
            :rises: accept_exception if symbol is not at the begining of the text.
        """
        if len(self.string) == 0:
            return text

        max_len = len(self.string) * self.stride - self.last
        
        if len(text) < max_len:
            raise pattern_exceptions.symbol_string_to_short()

        for i in range(0, len(self.string)):
            for j in range(0, self.stride):
                matched = False
                position = i * self.stride + j
                if position < max_len:
                    for char in self.string[i][j]:
                        if text[position] == self.string[i][j]:
                            matched = True
                    if matched == False:
                        raise pattern_exceptions.symbol_accept_exception()

        return text[max_len:]
コード例 #5
0
ファイル: sym_class_string.py プロジェクト: vhavlena/appreal
    def accept(self, text):
        """
            If symbol is at the beginning of the text, is removed from the text and reminder is returned. Otherwise accept_exception is raised.
            
            :param text: Text to be parsed.
            :type text: string
            
            :returns: Text without begining.
            :rtype: string
            
            :rises: accept_exception if symbol is not at the begining of the text.
        """
        if self.string == "":
            return text

        if len(text) < len(self.string):
            raise pattern_exceptions.symbol_string_to_short()

        for i in range(0, len(self.string)):
            matched = False
            for char in self.string[i]:
                if text[i] == self.string[i]:
                    matched = True
            if matched == False:
                raise pattern_exceptions.symbol_accept_exception()

        return text[len(self.string):]
コード例 #6
0
    def accept(self, text):
        """
            If symbol is at the beginning of the text, is removed from the text and reminder is returned. Otherwise accept_exception is raised.
            
            :param text: Text to be parsed.
            :type text: string
            
            :returns: Text without begining.
            :rtype: string
            
            :rises: accept_exception if symbol is not at the begining of the text.
        """
        if len(self.string) == 0:
            return text

        max_len = len(self.string) * self.stride - self.last

        if len(text) < max_len:
            raise pattern_exceptions.symbol_string_to_short()

        for i in range(0, len(self.string)):
            for j in range(0, self.stride):
                matched = False
                position = i * self.stride + j
                if position < max_len:
                    for char in self.string[i][j]:
                        if text[position] == self.string[i][j]:
                            matched = True
                    if matched == False:
                        raise pattern_exceptions.symbol_accept_exception()

        return text[max_len:]
コード例 #7
0
ファイル: sym_eof.py プロジェクト: vhavlena/appreal
 def accept(self, text):
     """
         If symbol is at the beginning of the text, is removed from the text and reminder is returned. Otherwise accept_exception is raised.
         
         :param text: Text to be parsed.
         :type text: string
         
         :returns: Text without begining.
         :rtype: string
         
         :rises: accept_exception if symbol is not at the begining of the text.
     """
     if len(text) == 0:
         return text
     else:
         raise pattern_exceptions.symbol_accept_exception()
コード例 #8
0
ファイル: sym_eof.py プロジェクト: 4sp1r3/appreal
 def accept(self, text):
     """
         If symbol is at the beginning of the text, is removed from the text and reminder is returned. Otherwise accept_exception is raised.
         
         :param text: Text to be parsed.
         :type text: string
         
         :returns: Text without begining.
         :rtype: string
         
         :rises: accept_exception if symbol is not at the begining of the text.
     """
     if len(text) == 0:
         return text
     else:
         raise pattern_exceptions.symbol_accept_exception()
コード例 #9
0
ファイル: sym_cnt_constr.py プロジェクト: 4sp1r3/appreal
    def accept(self, text):
        """  
            If symbol is at the beginning of the text, is removed from the text and reminder is returned. Otherwise accept_exception is raised. Behavior of this method is controled by attributes greedy and limit. The limit attribute has bigger priority than the greedy one.  Limit sets exact number of accepted characters. If -1 is set, the greedy attribute will be used. If greedy is True, the accept() method will consume as much characters from input string as posible. If greedy is False, the accept() mathod will consume only minimal number of characters from input string with respect to the m parameter.
            
            :param text: Text to be parsed.
            :type text: string
            
            :returns: Text without begining.
            :rtype: string
            
            :rises: accept_exception if symbol is not at the begining of the text.
        """
        if self.limit > -1:
            if self.limit < self.m or self.limit > self.n:
                raise pattern_exceptions.symbol_accept_exception()

            if len(text) < self.limit:
                raise pattern_exceptions.symbol_accept_exception()

            if self.limit == 0:
                return text

            for i in range(0, self.limit):
                if isinstance(self.symbol, set) or isinstance(self.symbol, frozenset):
                    accepted = False
                    for char in self.symbol:
                        if char[0] == text[i]:
                            accepted = True
                    if accepted == False:
                        raise pattern_exceptions.symbol_accept_exception()
                else:
                    if self.symbol[0] != text[i]:
                        raise pattern_exceptions.symbol_accept_exception()

            return text[self.limit:]
        else:
            index = 0

            if len(text) < self.m:
                raise pattern_exceptions.symbol_accept_exception()

            for i in range(0, len(text)+1):
                if index == self.m and self.greedy == False:
                    break
                if index == self.n:
                    break
                if i == len(text):
                    return ""

                if isinstance(self.symbol, set) or isinstance(self.symbol, frozenset):
                    accepted = False
                    for char in self.symbol:
                        if char[0] == text[i]:
                            accepted = True
                    if accepted == False:
                        if index < self.m:
                            raise pattern_exceptions.symbol_accept_exception()
                        else:
                            return text[index:]
                else:
                    if self.symbol[0] != text[i]:
                        if index < self.m:
                            raise pattern_exceptions.symbol_accept_exception()
                        else:
                            return text[index:]
                    
                index = i

            return text[index:]
コード例 #10
0
    def accept(self, text):
        """  
            If symbol is at the beginning of the text, is removed from the text and reminder is returned. Otherwise accept_exception is raised. Behavior of this method is controled by attributes greedy and limit. The limit attribute has bigger priority than the greedy one.  Limit sets exact number of accepted characters. If -1 is set, the greedy attribute will be used. If greedy is True, the accept() method will consume as much characters from input string as posible. If greedy is False, the accept() mathod will consume only minimal number of characters from input string with respect to the m parameter.
            
            :param text: Text to be parsed.
            :type text: string
            
            :returns: Text without begining.
            :rtype: string
            
            :rises: accept_exception if symbol is not at the begining of the text.
        """
        if self.limit > -1:
            if self.limit < self.m or self.limit > self.n:
                raise pattern_exceptions.symbol_accept_exception()

            if len(text) < self.limit:
                raise pattern_exceptions.symbol_accept_exception()

            if self.limit == 0:
                return text

            for i in range(0, self.limit):
                if isinstance(self.symbol, set) or isinstance(
                        self.symbol, frozenset):
                    accepted = False
                    for char in self.symbol:
                        if char[0] == text[i]:
                            accepted = True
                    if accepted == False:
                        raise pattern_exceptions.symbol_accept_exception()
                else:
                    if self.symbol[0] != text[i]:
                        raise pattern_exceptions.symbol_accept_exception()

            return text[self.limit:]
        else:
            index = 0

            if len(text) < self.m:
                raise pattern_exceptions.symbol_accept_exception()

            for i in range(0, len(text) + 1):
                if index == self.m and self.greedy == False:
                    break
                if index == self.n:
                    break
                if i == len(text):
                    return ""

                if isinstance(self.symbol, set) or isinstance(
                        self.symbol, frozenset):
                    accepted = False
                    for char in self.symbol:
                        if char[0] == text[i]:
                            accepted = True
                    if accepted == False:
                        if index < self.m:
                            raise pattern_exceptions.symbol_accept_exception()
                        else:
                            return text[index:]
                else:
                    if self.symbol[0] != text[i]:
                        if index < self.m:
                            raise pattern_exceptions.symbol_accept_exception()
                        else:
                            return text[index:]

                index = i

            return text[index:]