Skip to content

.parse doesn't support arbitrary iterables #78

@Kodiologist

Description

@Kodiologist
>>> from funcparserlib.parser import a, many
>>> many(a("x")).parse("xxxxxxx")
['x', 'x', 'x', 'x', 'x', 'x', 'x']
>>> many(a("x")).parse(x for x in "xxxxxxx")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/hippo/Scratch/Python-venv/lib/python3.11/site-packages/funcparserlib/parser.py", line 221, in parse
    (tree, _) = self.run(tokens, State(0, 0, None))
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/hippo/Scratch/Python-venv/lib/python3.11/site-packages/funcparserlib/parser.py", line 569, in _many
    (v, s) = p.run(tokens, s)
             ^^^^^^^^^^^^^^^^
  File "/home/hippo/Scratch/Python-venv/lib/python3.11/site-packages/funcparserlib/parser.py", line 614, in _some
    if s.pos >= len(tokens):
                ^^^^^^^^^^^
TypeError: object of type 'generator' has no len()

It seems likely one would want to parse an iterable stream of tokens at times.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions