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 classification for YAML parsing *)
7
8(** Line break characters *)
9let is_break c = c = '\n' || c = '\r'
10
11(** Blank (space or tab) *)
12let is_blank c = c = ' ' || c = '\t'
13
14(** Whitespace (break or blank) *)
15let is_whitespace c = is_break c || is_blank c
16
17(** Decimal digit *)
18let is_digit c = c >= '0' && c <= '9'
19
20(** Hexadecimal digit *)
21let is_hex c =
22 (c >= '0' && c <= '9') ||
23 (c >= 'a' && c <= 'f') ||
24 (c >= 'A' && c <= 'F')
25
26(** Alphabetic character *)
27let is_alpha c =
28 (c >= 'a' && c <= 'z') ||
29 (c >= 'A' && c <= 'Z')
30
31(** Alphanumeric character *)
32let is_alnum c = is_alpha c || is_digit c
33
34(** YAML indicator characters *)
35let is_indicator c =
36 match c with
37 | '-' | '?' | ':' | ',' | '[' | ']' | '{' | '}'
38 | '#' | '&' | '*' | '!' | '|' | '>' | '\'' | '"'
39 | '%' | '@' | '`' -> true
40 | _ -> false
41
42(** Flow context indicator characters *)
43let is_flow_indicator c =
44 match c with
45 | ',' | '[' | ']' | '{' | '}' -> true
46 | _ -> false