示例#1
0
def get_next_unescaped_appearance(s,
                                  d1,
                                  search_from,
                                  next_char_not_word=False):
    while True:
        if not d1 in s[search_from:]:
            #             print('nope, no %r in s[%s:] = %r' % (d1,search_from, s[search_from:]))
            #             print('cannot find %r in s o f len = %s starting from %s' % (d1, len(s), search_from))
            raise NotFound()
        maybe = s.index(d1, search_from)
        if s[maybe - 1] == '\\':
            if 'space' in d1:
                w = Where(s, maybe, maybe + len(d1))
                msg = 'Skipping escaped sequence:\n\n' + w.__str__()
                logger.debug(msg)
#             print('found escaped match of %r (prev chars = %r)' % (d1, s[:maybe]))
            search_from = maybe + 1
        else:
            assert s[maybe:].startswith(d1)
            nextchar_i = maybe + len(d1)
            nextchar = s[nextchar_i] if nextchar_i < len(s) else 'o'
            if next_char_not_word and can_be_used_in_command(nextchar):
                #print('skipping because nextchar = %r' % nextchar)
                search_from = maybe + 1
                continue


#             print('found %r at %r ' % (d1, s[maybe:]))
            return maybe
示例#2
0
    def bb(tokens, loc, s):
        where = Where(s, loc)
        try:
            try:
                res = b(tokens)
            except TypeError as e:
                ttokens = list(tokens)
                s = "\n".join("- %s " % str(x) for x in ttokens)
                msg = 'Cannot invoke %r\nwith %d tokens:\n%s.' % (
                    b, len(ttokens), s)
                raise_wrapped(TypeError, e, msg)
        except DPSyntaxError as e:
            if e.where is None:
                e.where = where
                raise DPSyntaxError(str(e), where=where)
            else:
                raise
        except DPSemanticError as e:
            if e.where is None:
                raise DPSemanticError(str(e), where=where)
            else:
                raise
        except BaseException as e:
            raise_wrapped(DPInternalError,
                          e,
                          "Error while parsing.",
                          where=where.__str__(),
                          tokens=tokens)

        if isnamedtupleinstance(res) and res.where is None:
            res = get_copy_with_where(res, where=where)

        return res