Closed eignnx closed 3 years ago
so with ac34e5a and 61772cd we now have map
, flat_map
, and
, and_then
and or
methods. I'm not sure about adding opt
and cut
, and context
will not appear there, since I'm separating from the main error type (cf #1131)
The current map
syntax in 5.1.1 is the by far least ergonomic out of the combinators I listed, so I'm really glad to see it will be updated!
nom 6 is released now :partying_face:
Proposal
I think it could improve readability of some complicated parsers if specific combinators could be applied as postfix method calls.
Candidate Combinators
map
cut
context
opt
Example of Proposed Syntax
This change would allow the following code...
...to be rewritten:
This transformation allowed the
delimited
parser to be "un-nested" two levels.(The example is from here.)
Implementation
As I understand it,See recent commitnom
doesn't define anything like aParserCombinator
trait to which these methods could be attached, but maybe a new trait thatFn(I) -> IResult<I, O, E>
implements could be created (warning, pseudocode ahead):84d1ac0
where aParser
trait was defined.Syntactic changes like this probably shouldn't be high up on the priority list, but I just wanted to put this proposal out there in case other people are interested.