Parseff.Utf8Sourcesatisfy pred ~label decodes the next UTF-8 code point and checks it against pred. Advances by the number of bytes in the UTF-8 encoding (1--4). Fails with label if the predicate returns false, the input ends, or the bytes are not valid UTF-8.
Example:
let cjk () =
Parseff.Utf8.satisfy
(fun u -> Uchar.to_int u >= 0x4E00 && Uchar.to_int u <= 0x9FFF)
~label:"CJK character"char u matches the exact Unicode code point u.
Example:
let lambda () = Parseff.Utf8.char (Uchar.of_int 0x03BB) (* λ *)any_char () decodes and returns the next UTF-8 code point, whatever it is. Fails on end of input or invalid UTF-8.
take_while pred decodes code points and consumes them while pred returns true. Returns the matched UTF-8 bytes as a string (may be empty). Fails on invalid UTF-8 encountered during scanning.
When ~at_least is specified, requires at least that many code points (not bytes) to match. Fails with ~label if fewer match.
Example:
let unicode_word () =
Parseff.Utf8.take_while ~at_least:1 Uucp.Alpha.is_alphabetic
~label:"letter"skip_while pred advances past code points while pred returns true. Like take_while but returns unit — no string allocation.
take_while_span pred like take_while but returns a zero-copy span.
skip_while_then_char pred u skips code points where pred returns true, then matches the exact code point u. More efficient than calling skip_while followed by char separately.
is_whitespace u returns true for Unicode whitespace characters, using the full Unicode White_Space property. This includes ASCII whitespace plus characters like NO-BREAK SPACE (U+00A0), EM SPACE (U+2003), IDEOGRAPHIC SPACE (U+3000), and others.
letter () parses a Unicode alphabetic character. Uses the Unicode Alphabetic property via Uucp.Alpha.is_alphabetic, which covers Latin, Greek, Cyrillic, CJK, Arabic, Devanagari, and all other Unicode scripts.
Example:
(* Matches 'a', 'é', 'λ', '中', 'д', etc. *)
let l = Parseff.Utf8.letter ()digit () parses an ASCII digit (0--9) and returns its integer value. Only matches ASCII digits; does not match Unicode digit characters from other scripts.
alphanum () parses a Unicode alphabetic character or an ASCII digit.
whitespace () parses zero or more Unicode whitespace characters. Returns the matched UTF-8 string. Uses the full Unicode White_Space property.
When ~at_least is specified, requires at least that many whitespace code points.
skip_whitespace () skips zero or more Unicode whitespace characters. More efficient than whitespace when you don't need the matched string.