-
Notifications
You must be signed in to change notification settings - Fork 42
Open
Description
seq provides a convenient way to return a nicely structured result (and close enough, if not exactly what you want most of the time), namely by using it with kwargs.
e.g.
>>> seq(a=any_char, b=any_char).parse("ab")
{'a': 'a', 'b': 'b'}This is basically an encoding of a product type.
It would be nice if there was a similarly convenient way to return something analogous for alternatives (i.e. alt or the | operator), the result of which is encodable as a tagged union/is an encoding of a sum type.
Example pseudocode:
>>> alt(a=any_char, b=any_char).parse("a")
{'a': 'a'}
>>> alt(a=any_char, b=any_char).parse("b")
{'b': 'b'}
I don't see a way to use this together with an operator without hacks like passing it tuples or something (like (name, parser) | (name,parser)), but i think this would still be nice to have for the alt() form.
Metadata
Metadata
Assignees
Labels
No labels