def _not_parser(tokens, s): if s.pos >= len(tokens): raise p.NoParseError('no tokens left in the stream', s) try: parser.run(tokens, s) except p.NoParseError: pos = s.pos + 1 s2 = p.State(pos, max(pos, s.max)) return None, s2 else: raise p.NoParseError('parsing failed', s)
def _helper(tokens, s): """Iterative implementation preventing the stack overflow.""" res = [] s2 = s while s2.pos < len(tokens): try: (v, s3) = p.run(tokens, s2) return res, s3 except fp.NoParseError as e: res.append(tokens[s2.pos]) pos = s2.pos + 1 s2 = fp.State(pos, max(pos, s2.max)) raise fp.NoParseError(u'no tokens left in the stream', s)
def _helper(tokens, s): """Iterative implementation preventing the stack overflow.""" res = [] start = s.pos end = start + len(xs) toks = tokens[start:end] if _DEBUG: vals = [t.value for t in toks] else: vals = toks if vals == xs: pos = s.pos + len(xs) s2 = fp.State(pos, max(pos, s.max)) return fp._Ignored(()), s2 else: raise fp.NoParseError(u'Did not match literal ' + xs, s)