Pure OCaml Yaml 1.2 reader and writer using Bytesrw
1(*---------------------------------------------------------------------------
2 Copyright (c) 2025 Anil Madhavapeddy <anil@recoil.org>. All rights reserved.
3 SPDX-License-Identifier: ISC
4 ---------------------------------------------------------------------------*)
5
6(** Character input source with lookahead, based on Bytes.Reader.t
7
8 This module wraps a bytesrw [Bytes.Reader.t] to provide character-by-character
9 access with lookahead for the YAML scanner. *)
10
11(** {2 Re-exported Character Classification} *)
12
13include module type of Char_class
14
15(** {2 Input Type} *)
16
17type t
18
19(** {2 Constructors} *)
20
21val of_reader : ?initial_position:Position.t -> Bytesrw.Bytes.Reader.t -> t
22(** Create input from a Bytes.Reader.t *)
23
24val of_string : string -> t
25(** Create input from a string *)
26
27(** {2 Position and State} *)
28
29val position : t -> Position.t
30(** Get current position *)
31
32val is_eof : t -> bool
33(** Check if at end of input *)
34
35val mark : t -> Position.t
36(** Mark current position for span creation *)
37
38(** {2 Lookahead} *)
39
40val peek : t -> char option
41(** Peek at current character without advancing *)
42
43val peek_exn : t -> char
44(** Peek at current character, raising on EOF *)
45
46val peek_nth : t -> int -> char option
47(** Peek at nth character (0-indexed from current position) *)
48
49val peek_string : t -> int -> string
50(** Peek at up to n characters as a string *)
51
52val peek_back : t -> char option
53(** Get the character before the current position *)
54
55(** {2 Consumption} *)
56
57val next : t -> char option
58(** Consume and return next character *)
59
60val next_exn : t -> char
61(** Consume and return next character, raising on EOF *)
62
63val skip : t -> int -> unit
64(** Skip n characters *)
65
66val skip_while : t -> (char -> bool) -> unit
67(** Skip characters while predicate holds *)
68
69val consume_break : t -> unit
70(** Consume line break, handling \r\n as single break *)
71
72(** {2 Predicates} *)
73
74val next_is : (char -> bool) -> t -> bool
75(** Check if next char satisfies predicate *)
76
77val next_is_break : t -> bool
78val next_is_blank : t -> bool
79val next_is_whitespace : t -> bool
80val next_is_digit : t -> bool
81val next_is_hex : t -> bool
82val next_is_alpha : t -> bool
83val next_is_indicator : t -> bool
84
85val at_document_boundary : t -> bool
86(** Check if at document boundary (--- or ...) *)
87
88(** {2 Utilities} *)
89
90val remaining : t -> string
91(** Get remaining content from current position *)
92
93val source : t -> string
94(** Get a sample of the source for encoding detection *)
95
96val byte_pos : t -> int
97(** Get the byte position in the underlying stream *)