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
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
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