Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make_tokenizer tokenisers return generators, Parser expects sequences #44

Closed
gsnedders opened this issue Jun 28, 2016 · 3 comments
Closed
Assignees

Comments

@gsnedders
Copy link

from funcparserlib.lexer import make_tokenizer
from funcparserlib.parser import some

tokenize = make_tokenizer([
    (u'x', (ur'x',)),
])

some(lambda t: t.type == "x").parse(tokenize("x"))

results in

Traceback (most recent call last):
  File "/Users/gsnedders/Documents/other-projects/funcparserlib/funcparserlib/funcparserlib/tests/test_parsing.py", line 76, in test_tokenize
    some(lambda t: t.type == "x").parse(tokenize("x"))
  File "/Users/gsnedders/Documents/other-projects/funcparserlib/funcparserlib/funcparserlib/parser.py", line 121, in parse
    (tree, _) = self.run(tokens, State())
  File "/Users/gsnedders/Documents/other-projects/funcparserlib/funcparserlib/funcparserlib/parser.py", line 309, in _some
    if s.pos >= len(tokens):
TypeError: object of type 'generator' has no len()

tokenize("x") is a generator, and you can't call len on a generator.

@jtprobst
Copy link

jtprobst commented Nov 4, 2016

I'm facing the same issue. Are there any updates?

@jtprobst
Copy link

jtprobst commented Nov 4, 2016

I have temporarily worked around it by doing parse(list(tokenize(s)))

@gsnedders
Copy link
Author

Per @vlasovskikh in #45 (comment), this is intended behaviour, which yes, means if you can't pass the return value of make_tokenizer to parse and instead need to wrap it in list.

@gsnedders gsnedders closed this as not planned Won't fix, can't repro, duplicate, stale Apr 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants