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