-
Notifications
You must be signed in to change notification settings - Fork 42
Open
Description
Hi, thanks for making parsy, I like it!
I'm currently succeeding at shooting myself in the foot with heterogeneous inputs, because I want to be able to process a list of "symbols" and strings:
#some context for the following snippets
from dataclasses import dataclass
@dataclass
class Indent:
depth: int
@generate
def indent():
return (yield test_item(lambda i: isinstance(i, Indent), "not indent"))
sideToken = indent
newline = string("\r\n")
preline_ = (newline.should_fail("not newline") >> any_char).many().concat()
line = preline_ << newline
take = test_item(lambda x: True, "any nested")I'm probably not understanding something, why do I need to use .bind like this?:
>>> wrap = lambda fn: lambda res: success(fn.parse(res))
>>> ( sideToken >> take.bind(wrap(line)) ).many()
.parse([Indent(0), "asd\r\n", Indent(1), "asdf\r\n"])
['asd', 'asdf']instead of: (the following is pseudocode)
>>> ( sideToken >> take.bind(line) ).many() \
.parse([Indent(0), "asd\r\n", Indent(1), "asdf\r\n"])
['asd', 'asdf']Which is to say, why do I have to add an extra layer of wrapping and calling .parse?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels