Provide a new type impl Alt
which tries at last the parser which succeeded last time
#822
Replies: 1 comment 3 replies
-
Let me rephrase to see if I understand.
It is an interesting idea. I am concerned about generalizing that to being included in
The statefulness would have limited applicability because the state is recreated each time
We also have to weigh the API cost for new features. The more that exists in an API, the harder it is to find what you need and the less you use of everything that exists. We've been actively working to shrink our API (through composability). For things that we add, we need to ask if the cost of adding it is worth the benefit. For the benefit, we consider how strong the benefit is and how many people are likely to leverage it. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
It's a common pattern to parsing like
repeat(occurrences, alt((p1, p2, p3, ..., pn)))
, wherepi
never succeed if it succeeded last time.The current impls of
Alt
for tuples always try from the first parser to the last parser.We can add new type wrappers
AlternateI
for tuples, which records the index of last succeeded parser, and skip the parser when trying parsers in sequence and try it at last. We use it likerepeat(occurrences, alt(AlternateN((p1, p2, p3, ..., pn))))
. This will massively increase success rate when n is small, for example, when n = 2, we alternately try p1 and p2 which always succeed before exiting repeating.Beta Was this translation helpful? Give feedback.
All reactions