J-F-Liu / pom

PEG parser combinators using operator overloading without macros.
MIT License
496 stars 30 forks source link

Equivalent of nom's map_res #1

Closed jeanm closed 7 years ago

jeanm commented 7 years ago

nom has a very useful map_res combinator:

applies a function returning a Result to the output of IResult, returns Done(input, o) if the result is Ok(o), or Error(0)

Something like that would come in handy to get rid of all the unwrap()s in places like:

.map(|bytes|String::from_utf8(bytes).unwrap())

(there are a few cases of this in your JSON example code)

J-F-Liu commented 7 years ago

Added p.convert(f), this makes the parser code neater.