コード例 #1
0
ファイル: readable_things.py プロジェクト: Bad-ptr/parser.py
 def _read_from(self:object, tr : TextReader, **options) -> ReadResult:
     escaped = False
     while True:
         for th in self.thseq:
             rslt = tr.read_thing(th, **options)
             if rslt.is_fullmatch():
                 tr.push_back(rslt.readedlist)
                 if not escaped:
                     return Nomatch()
         rslt = tr.read_next(**options)
         if rslt.is_fullmatch():
             if escaped:
                 escaped = False
                 return rslt
             else:
                 if self.allow_escaped and self.escape_char == rslt.readedlist[0]:
                     escaped = True
                     continue
                 else:
                     return rslt
         else:
             if escaped:
                 tr.push_back(self.escape_char)
             rslt.readed_object = self
             return rslt
     return Nomatch([], self)
コード例 #2
0
ファイル: readable_things.py プロジェクト: Bad-ptr/parser.py
    def _read_from(self:object, tr:TextReader, **options) -> ReadResult:
        n_chars = 0
        acc = ""
        if 'char' == self.mode:
            while True:
                if self.max_chars >= 0 and n_chars >= self.max_chars:
                    break
                ch = tr.read_next(**options)
                if not ch.is_fullmatch():
                    break
                if None is not re.match(self.regexp, thing_as_string(ch.readedlist)):
                    acc += thing_as_string(ch.readedlist)
                else:
                    tr.push_back(ch.readedlist)
                    break
                n_chars += 1
        elif 'string' == self.mode:
            acc = ""
            while True:
                if self.max_chars >= 0 and n_chars >= self.max_chars:
                    break
                ch = tr.read_next(**options)
                if not ch.is_fullmatch():
                    break
                if None is re.match(self.regexp, acc + thing_as_string(ch.readedlist)):
                    tr.push_back(ch.readedlist)
                    break
                else:
                   acc += thing_as_string(ch.readedlist)
                n_chars += 1
        else:
            return Nomatch([], self)

        if n_chars >= self.min_chars:
            return Fullmatch(thing_as_string(acc), self)
        else:
            tr.push_back(acc)
            return Nomatch(thing_as_string(acc), self)