OCaml Parser combinator library as powerful as fastparse(Scala)?

The JSON parser in Orsetto (see Json_scan.ml) is about 500 lines, about half of which is the lexical analyzer, and about 100 lines is some logic that I’m trying to make obsolescent in a future release.

Parsing JSON objects is an illustrative example of where a backtracking feature of some kind is necessary. First, all the object members need to scanned into a map of member names associated with the stream position of the value, then you need to backtrack to parse according to the type associated with the member name. In the Orsetto framework (with the forthcoming 1.1 release), this is generalized by the Cf_structure_scan module.

Allows you to write parsers that looks like this:

type abc = Record of { a: string; b: int option; c: float }

module S = Json_scan
open S.Structure.Affix

let parser : abc S.t =
  "alfa" %: S.text @>
  "bravo" %? S.integer @>
  "charlie" %= (S.float, 1.0) @>
  S.Structure.return <@ fun a b c -> Record { a; b; c }

The CBOR parser contains a similar mechanism for parsing maps.