package parseff

  1. Overview
  2. Docs
Direct-style parser combinator library for OCaml 5 powered by algebraic effects

Install

dune-project
 Dependency

Authors

Maintainers

Sources

parseff-0.1.0.tbz
sha256=097c71a38b39ab5925518e16c0efdf3b77a6b3b2185c82f168e0f1f4cb0772bf
sha512=811fbd770148bf3004ffc764dc08fa1a3ded9b4613f5749a6d2841c1af868de7afff4dd6b808b38254d28592433e23613573707159dfa171687839c520e93bb3

Description

Parseff is a direct-style parser combinator library for OCaml 5 where parsers are plain functions (unit -> 'a), errors are typed via polymorphic variants, and algebraic effects handle control flow, backtracking, and streaming input. Designed for performance with zero-copy span APIs and fused operations.

Published: 18 Mar 2026

README

Parseff

Parseff is a direct-style parser combinator library for OCaml 5 where parsers are plain functions (unit -> 'a), errors are typed via polymorphic variants, and algebraic effects handle control flow, backtracking, and streaming input. Designed for performance with zero-copy span APIs and fused operations.

Documentation

Installation

$ opam install parseff -y

Example

let number () =
  let digits = Parseff.many1 Parseff.digit () in
  let n = List.fold_left (fun acc d -> (acc * 10) + d) 0 digits in
  if n >= 0 && n <= 255 then n
  else Parseff.error (`Out_of_range n)

let ip_address () =
  let a = number () in
  let _ = Parseff.char '.' in
  let b = number () in
  let _ = Parseff.char '.' in
  let c = number () in
  let _ = Parseff.char '.' in
  let d = number () in
  Parseff.end_of_input ();
  (a, b, c, d)

let () =
  match Parseff.parse "192.168.1.1" ip_address with
  | Ok ((a, b, c, d)) ->
      Printf.printf "Parsed: %d.%d.%d.%d\n" a b c d
  | Error { pos; error = `Out_of_range n } ->
      Printf.printf "Error at %d: %d out of range (0-255)\n" pos n
  | Error { pos; error = `Unexpected_end_of_input } ->
      Printf.printf "Error at %d: unexpected end of input\n" pos
  | Error { pos; error = `Expected msg } ->
      Printf.printf "Error at %d: %s\n" pos msg
  | Error { pos; error = `Depth_limit_exceeded msg } ->
      Printf.printf "Error at %d: %s\n" pos msg

Features

Performance

Parseff is faster than Angstrom and MParser by a factor of 2 to 4x. In case of equal implementations, Parseff is ~2x faster than Angstrom and MParser. With an optimized version using zero-copy span APIs, that gap widens to ~4x. See the full comparison for details and bench/bench_vs_angstrom.ml for the benchmark.

Documentation

Contributing

  • Open an issue to discuss proposed changes
  • Write tests for new features
  • Run make fmt before submitting
  • Ensure all tests pass with make test

License

MIT. See LICENSE for details.

Dependencies (3)

  1. re >= "1.9.0"
  2. ocaml >= "5.3"
  3. dune >= "3.20"

Dev Dependencies (9)

  1. mdx with-test
  2. odoc-parser with-doc
  3. odoc >= "3.1.0" & with-doc
  4. ocaml-lsp-server with-dev-setup
  5. ocamlformat >= "0.26.1" & with-dev-setup
  6. mparser with-test
  7. angstrom with-test
  8. benchmark with-test
  9. alcotest with-test

Used by

None

Conflicts

None