Comment by maxbond
1 year ago
> Unfortunately there is not much info available [.]
Parser combinators are a bit hard to get into, the most helpful resource for me was `nom`'s "Choosing a Combinator" document [1], which is dense but gives you an overview of all the Lego bricks which you can then start imagining how to fit together.
I've not really read it, but there's also the original paper on the subject [2] (as linked to by the `parsec` documentation [3]) which describes the nuts and bolts theory behind it.
> [Can] you not just rescan the string for the escape sequences, after grabbing the full string?
Absolutely, this is just a convenience around that pattern that allows you to express that like:
let string = quoted_string.then(escaped(json_string_escapes)).parse(&input)?;
Where `escaped` does the rescanning using the parser `json_string_escapes` (which consumes all the input up to the next escape, if it doesn't start with an escape sequence, or else consumes an escape sequence and returns the transformed text - this API is a little awkward, it may change).
And also more generally for any parsers `foo`, `bar`, and `baz` as:
let quux = (foo, bar, baz).map().parse(&input)?;
[1] https://github.com/rust-bakery/nom/blob/main/doc/choosing_a_...
[2] https://web.archive.org/web/20140528151730/http://legacy.cs....
Thanks for the reply. I will check out those links.