Пример #1
0
 def grammar_parse(cls, text, index, sessiondata):
     i = index
     ind_depth = 0
     string = text.string
     while i < len( string ):
         c = string[i]
         if c in cls.ending_chars and ind_depth <= 0:
             yield( i - index, cls( string[index:i] ) )
             break
         if len( cls.independent_bracket_pair ) > 0:
             if c == cls.independent_bracket_pair[0]:
                 ind_depth += 1
             elif c == cls.independent_bracket_pair[1]:
                 ind_depth = max( 0, ind_depth - 1 )
         for bracket_pair in cls.bracket_pairs:
             if c == bracket_pair[0]:
                 depth = 1
                 while depth > 0:
                     i += 1
                     i = cls.read_until( string, i, ( bracket_pair[0], bracket_pair[1] ) )
                     if not i:
                         yield error_result( index, cls )
                     if string[i] == bracket_pair[0]:
                         depth += 1
                     else:
                         depth -= 1
                 break
         i += 1
     yield error_result( index, cls )
Пример #2
0
 def grammar_parse(cls, text, index, sessiondata):
     i = index
     ind_depth = 0
     string = text.string
     while i < len(string):
         c = string[i]
         if c in cls.ending_chars and ind_depth <= 0:
             yield (i - index, cls(string[index:i]))
             break
         if len(cls.independent_bracket_pair) > 0:
             if c == cls.independent_bracket_pair[0]:
                 ind_depth += 1
             elif c == cls.independent_bracket_pair[1]:
                 ind_depth = max(0, ind_depth - 1)
         for bracket_pair in cls.bracket_pairs:
             if c == bracket_pair[0]:
                 depth = 1
                 while depth > 0:
                     i += 1
                     i = cls.read_until(string, i,
                                        (bracket_pair[0], bracket_pair[1]))
                     if not i:
                         yield error_result(index, cls)
                     if string[i] == bracket_pair[0]:
                         depth += 1
                     else:
                         depth -= 1
                 break
         i += 1
     yield error_result(index, cls)
Пример #3
0
    def grammar_parse(cls, text, index, sessiondata):
        i = index
        depth = 0
        string = text.string
        while i < len( string ):
            c = string[i]
            if c == cls.opening_char:
                depth += 1
            elif c == cls.closing_char:
                depth -= 1

            elif c == "\"":
                i += 1
                while i < len( string ):
                    if string[i] == "\"" and string[i-1] != "\\":
                        break
                    i += 1
            elif c == "'":
                i += 1
                while i < len( string ):
                    if string[i] == "'" and string[i-1] != "\\":
                        break
                    i += 1
            if depth < 0:
                yield( i - index, cls( string[index:i] ) )
                break
            i += 1
        yield error_result( index, cls )
Пример #4
0
    def grammar_parse(cls, text, index, sessiondata):
        i = index
        depth = 0
        string = text.string
        while i < len(string):
            c = string[i]
            if c == cls.opening_char:
                depth += 1
            elif c == cls.closing_char:
                depth -= 1

            elif c == "\"":
                i += 1
                while i < len(string):
                    if string[i] == "\"" and string[i - 1] != "\\":
                        break
                    i += 1
            elif c == "'":
                i += 1
                while i < len(string):
                    if string[i] == "'" and string[i - 1] != "\\":
                        break
                    i += 1
            if depth < 0:
                yield (i - index, cls(string[index:i]))
                break
            i += 1
        yield error_result(index, cls)
Пример #5
0
 def grammar_parse(cls, text, index, sessiondata):
     string = text.string[index:]
     if len( string ) == 0:
         yield (0, cls(""))
     end_of_word_pattern = re.compile( "[^a-zA-Z0-9_]" )
     match = end_of_word_pattern.match( string )
     if match:
         yield (0, cls(""))
     yield error_result(index, cls)
Пример #6
0
 def grammar_parse(cls, text, index, sessiondata):
     string = text.string[index:]
     if len(string) == 0:
         yield (0, cls(""))
     end_of_word_pattern = re.compile("[^a-zA-Z0-9_]")
     match = end_of_word_pattern.match(string)
     if match:
         yield (0, cls(""))
     yield error_result(index, cls)