Beispiel #1
0
 def match(self, text_iterator: TextIterator):
     try:
         text_iterator.skip_whitespace()
         self._start_pos = text_iterator.current_pos().copy()
         self._text = ''
         while not text_iterator.is_after_end():
             if text_iterator.is_valid_pos():
                 self._text += next(text_iterator)
             if text_iterator.current_pos().r > self._start_pos.r:
                 break
             self._last_pos = text_iterator.current_pos().copy()
     except StopIteration:
         log.debug("GAny - StopIteration")
     return len(self._text) > 0
Beispiel #2
0
 def find_last_pos(self, text_iterator: TextIterator):
     pos = None
     for i in range(0, len(self._word)):
         pos = text_iterator.current_pos().copy()
         v = next(text_iterator)
         if v != self._word[i]:
             log.debug("Word: {} mismatch at pos {}".format(
                 self._word, pos))
             return None
     log.debug("Found word: {} at pos: {}".format(self._word, pos))
     return pos
Beispiel #3
0
 def match(self, text_iterator: TextIterator):
     try:
         start_pos = text_iterator.current_pos().copy()
         if self._object.match(text_iterator):
             self._found_obj = self._object
             self._start_pos = self._object.get_start_pos().copy()
             self._last_pos = self._object.get_last_pos().copy()
             return True
     except StopIteration:
         log.debug("GObject:match - StopIteration")
     text_iterator.set_current_pos(start_pos)
     return True
Beispiel #4
0
 def find_last_pos(self, text_iterator: TextIterator) -> Position:
     self._name = ''
     last_pos = None
     it = iter(text_iterator)
     try:
         while text_iterator.is_valid_pos():
             prev_pos = text_iterator.current_pos().copy()
             char = next(it)
             if not GName.is_name_char(char):
                 text_iterator.set_current_pos(prev_pos)
                 break
             last_pos = prev_pos
             self._name += char
     except StopIteration:
         log.debug("GName:StopIteration")
     if len(self._name) > 0:
         log.debug("Found GName: {} ending at pos {}".format(self._name, last_pos))
         return last_pos
     return None
Beispiel #5
0
    def match(self, text_iterator: TextIterator):
        log.debug("match start")
        start_pos = text_iterator.current_pos().copy()
        if self._find_matching_braces(text_iterator):
            content_start = self._start_pos.copy().move(
                1, text_iterator.get_lines())
            content_end = self._last_pos.copy().move(-1,
                                                     text_iterator.get_lines())
            inside_text = text_iterator.get_substr(content_start, content_end)
            log.debug("Parsing inside definition: {}\n".format(inside_text))
            if self._definitions is not None:
                self._body = GObject.parse_definitions(inside_text,
                                                       self._definitions)
                self._body.set_recursive_definitions(self._definitions)
            else:
                self._body = GWord(inside_text)
            return True

        text_iterator.set_current_pos(start_pos)
        return False