Bind parsers; reparse consumed data

71 Views Asked by At

I have a parser for a URI's query. The query is hex-/URI-encoded.

I also have a parser for the decoded string; one that yields the key-value-option pairs from the query params.

I'd like to do a two-phase pass; one to detect the query string, another to parse the contents of the query string; and combine these into a single FParsec parser.

Or in short;

let private Predicate i =
        isPchar i
     || i = 0x2f // /
     || i = 0x3f // ?

let contentP =
    PercentEncoding.makeParser Predicate

let paramsP =
    contentP >>= fun q ->
    run QueryParams.queryParamsP q

However, contentP advances the state of the CharStream, and run ... yields a ParseResult, not a parser. I'd really like to do something like contentP |> Parser.bindSuccess queryParamsP, while returning expected parser state.

How to express this with FParsec?

0

There are 0 best solutions below