package parseff

  1. Overview
  2. Docs
Direct-style parser combinator library for OCaml 5 with zero-copy spans

Install

dune-project
 Dependency

Authors

Maintainers

Sources

parseff-0.4.0.tbz
sha256=e0f177f1bccee23e864be017229270932b7505fc2e44d94e55ab4f3a99c84fae
sha512=6405e5a2f04997bcaa5717c7868ce5f3d57989ab3105af9fdc3b98be87f35f5a901ea7375e475466adc3565d3b132159b356e7481924dc2c8fad65e19ad56beb

doc/CHANGES.html

0.4.0

  • Breaking: streaming now uses a bounded sliding buffer. parse_source and parse_source_until_end accept ~backtrack_window (default 65536) and fail with Backtrack_window_exceeded of backtrack_window_error</code> when a parser needs to keep more input than that for backtracking. This includes a single take_whileortake_while_spantoken longer than the window. Exhaustive matches on the error type must handle the new case. Raise~backtrack_window` if a parser needs more.
  • Add commit. commit () seals the innermost choice or repetition frame, improving error locality and allowing streaming sources to drop older buffered input earlier. It does not release outer frames: a commit inside the or_ of many (fun () -> or_ a b ()) leaves the many frame in place.
  • Breaking: streaming spans may be owned copies. take_while_span and sep_by_take_span keep zero-copy behavior for parse, but parse_source may materialize owned spans so bounded streaming can reclaim old prefixes.
  • Improve runtime performance and reduce allocation. Parseff now uses a lower-overhead runtime internally, making generic parsers and backtracking-heavy workloads faster while keeping the API largely unchanged.
  • Add peek_char. Provides cheap single-character lookahead without backtracking.
  • Fix streaming results that differed from parse. Utf8.take_while and related scans now report a truncated UTF-8 sequence at the end of input. match_regex now finds matches that need more than the buffered input, and Re.bol and word boundaries see the byte before the current position.
  • Fix location line numbers after backtracking. Lines were counted twice when a parser asked for location after backtracking to an earlier position.
  • match_regex reads ahead in streaming mode. It reads until about half the backtrack window is buffered ahead before it matches, so on an interactive source it waits for that input or the end of the source. A match cannot extend past the window.

0.3.0

  • Add Source.of_seq. Creates a source from a string Seq.t.
  • Add Source.of_chunks. Creates a source from a (unit -> string option) pull function.
  • fail now produces Failure of string</code> instead of <code>Expected.
  • Add catch combinator. catch parser handler intercepts `Failure errors, allowing recovery within backtracking contexts.
  • Add Parseff.Utf8 module for Unicode-aware parsing. satisfy, char, any_char, take_while, skip_while, letter, digit, alphanum, whitespace and take_while_span.
  • Add Parseff.BE and Parseff.LE binary parsing primitives. Big-endian and little-endian readers for any_uint8, any_int8, any_int16, any_uint16, any_int32, any_int64, any_float, any_double, and validators int16, int32, int64.
  • Add location and location_of_position for line/column tracking. location () returns { offset; line; col } during parsing (lazy, incremental, zero cost if unused). location_of_position input pos converts a byte offset after parsing — useful for error reporting.
  • BE/LE exact-match validators produce Expected</code> instead of <code>Failure. BE.int16, BE.int32, BE.int64 (and LE equivalents) are parser expectations, not user validation failures.
  • or_ now composes errors from both branches. When both branches fail at the same position, Expected messages are joined with " or " (e.g., expected "foo" or expected "bar"). When branches fail at different positions, the error from the branch that consumed more input is kept. This also improves one_of, which chains or_ and now naturally produces composed messages across all alternatives.
  • Register a printer for Unhandled effects, warning the user about bad organitzation of the parser function

0.2.0

  • Unified *1 variants into base combinators with ~at_least parameter. many1 → many ~at_least:1, take_while1 → take_while ~at_least:1, sep_by1 → sep_by ~at_least:1, end_by1 → end_by ~at_least:1, whitespace1 → whitespace ~at_least:1. The ~at_least parameter generalizes beyond the binary zero-vs-one distinction (e.g., many ~at_least:3 requires at least three matches). The old chainl1 and chainr1 were also removed in favor of making the default argument optional (see next item).
  • Renamed chainl/chainr to fold_left/fold_right with ~otherwise. chainl1 p op → fold_left p op, chainl p op default → fold_left p op ~otherwise:default, and likewise for chainr/fold_right. The new names better describe what the combinators do (parse and fold with associativity) and align with OCaml's List.fold_left/List.fold_right naming conventions. The ~otherwise labeled argument replaces the old positional default parameter, providing a fallback value when zero elements match.

0.1.0

Initial release of Parseff