def many(p):
    """Parser(a, b) -> Parser(a, [b])

    Returns a parser that infinitely applies the parser p to the input sequence
    of tokens while it successfully parsers them. The resulting parser returns a
    list of parsed values.
    """

    @Parser
    def _many(tokens, s):
        """Iterative implementation preventing the stack overflow."""
        res = []
        try:
            while True:
                (v, s) = p.run(tokens, s)
                res.append(v)
        except NoParseError, e:
            return res, State(s.pos, e.state.max)

    _many.name = u'{ %s }' % p.name
    return _many
def many ( p ) : @ Parser def _many ( tokens , s ) : res = [ ] try : while True : ( v , s ) = p . run ( tokens , s ) res . append ( v ) except NoParseError , e : return res , State ( s . pos , e . state . max ) _many . name = u'{ %s }' % p . name return _many
Parser(a, b) -> Parser(a, [b])

    Returns a parser that infinitely applies the parser p to the input sequence
    of tokens while it successfully parsers them. The resulting parser returns a
    list of parsed values.