Pure OCaml Yaml 1.2 reader and writer using Bytesrw
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Upgrade to ocamlformat 0.29.0; fix csvt/sexpt streaming; reformat

- Update .ocamlformat to 0.29.0 across all 591 files
- csvt: reuse single Buffer.t for field reads (no alloc per field)
- sexpt: Obj members decoded from stream into Dict, typed Variant GADT
- Reformat all source files for 0.29.0

+52 -52
+1 -1
.ocamlformat
··· 1 - version = 0.28.1 1 + version = 0.29.0
+10 -10
lib/eio/yamlrw_eio.mli
··· 21 21 22 22 Write YAML to a flow: 23 23 {[ 24 - Eio_main.run @@ fun env -> 25 - let fs = Eio.Stdenv.fs env in 26 - Eio.Path.with_open_out Eio.Path.(fs / "output.yaml") @@ fun flow -> 27 - Yaml_eio.Write.value flow (`O [ ("name", `String "test") ]) 24 + Eio_main.run @@ fun env -> 25 + let fs = Eio.Stdenv.fs env in 26 + Eio.Path.with_open_out Eio.Path.(fs / "output.yaml") @@ fun flow -> 27 + Yaml_eio.Write.value flow (`O [ ("name", `String "test") ]) 28 28 ]} 29 29 30 30 Stream events incrementally: 31 31 {[ 32 - Eio_main.run @@ fun env -> 33 - let fs = Eio.Stdenv.fs env in 34 - Eio.Path.with_open_in Eio.Path.(fs / "data.yaml") @@ fun flow -> 35 - Yaml_eio.Read.iter_events 36 - (fun event span -> Format.printf "Event at %a@." Yamlrw.Span.pp span) 37 - flow 32 + Eio_main.run @@ fun env -> 33 + let fs = Eio.Stdenv.fs env in 34 + Eio.Path.with_open_in Eio.Path.(fs / "data.yaml") @@ fun flow -> 35 + Yaml_eio.Read.iter_events 36 + (fun event span -> Format.printf "Event at %a@." Yamlrw.Span.pp span) 37 + flow 38 38 ]} 39 39 40 40 {2 Streaming Architecture}
+3 -3
lib/emitter.ml
··· 278 278 write_char t '*'; 279 279 write t anchor 280 280 end 281 - else begin 282 - match t.state with 281 + else 282 + begin match t.state with 283 283 | In_block_sequence _ -> 284 284 write_indent t; 285 285 write t "- *"; ··· 300 300 write_char t '*'; 301 301 write t anchor; 302 302 write_newline t 303 - end 303 + end 304 304 305 305 let emit_flow_scalar t ~anchor ~tag ~value ~plain_implicit ~style = 306 306 match t.state with
+6 -6
lib/input.ml
··· 113 113 (** Peek at up to n characters as a string *) 114 114 let rec peek_string t n = 115 115 if n <= 0 then "" 116 - else begin 117 - match t.current_slice with 116 + else 117 + begin match t.current_slice with 118 118 | Some slice -> 119 119 let slice_bytes = Bytes.Slice.bytes slice in 120 120 let slice_first = Bytes.Slice.first slice in ··· 134 134 Buffer.contents buf 135 135 end 136 136 | None -> if ensure_slice t then peek_string t n else "" 137 - end 137 + end 138 138 139 139 (** Consume next character *) 140 140 let next t = 141 - if ensure_slice t then begin 142 - match t.current_slice with 141 + if ensure_slice t then 142 + begin match t.current_slice with 143 143 | Some slice -> 144 144 let bytes = Bytes.Slice.bytes slice in 145 145 let first = Bytes.Slice.first slice in ··· 150 150 if t.slice_pos >= Bytes.Slice.length slice then t.current_slice <- None; 151 151 Some c 152 152 | None -> None 153 - end 153 + end 154 154 else None 155 155 156 156 let next_exn t =
+32 -32
lib/scanner.ml
··· 94 94 (* Check for comment *) 95 95 if Input.next_is (( = ) '#') t.input then begin 96 96 (* Validate: comment must be preceded by whitespace or be at start of line *) 97 - if not !has_whitespace then begin 97 + if not !has_whitespace then 98 98 (* Check if we're at the start of input or after whitespace (blank or line break) *) 99 - match Input.peek_back t.input with 99 + begin match Input.peek_back t.input with 100 100 | None -> () (* Start of input - OK *) 101 101 | Some c when Input.is_whitespace c -> () (* After whitespace - OK *) 102 102 | _ -> 103 103 (* Comment not preceded by whitespace - ERROR *) 104 104 Error.raise_at (Input.mark t.input) Invalid_comment 105 - end; 105 + end; 106 106 (* Skip to end of line *) 107 107 while (not (Input.is_eof t.input)) && not (Input.next_is_break t.input) do 108 108 ignore (Input.next t.input) ··· 163 163 t.leading_whitespace <- true; 164 164 skip_to_next_token t 165 165 end 166 - else if t.flow_level > 0 && Input.next_is_whitespace t.input then begin 167 - if Input.next_is_break t.input then 166 + else if t.flow_level > 0 && Input.next_is_whitespace t.input then 167 + begin if Input.next_is_break t.input then 168 168 handle_flow_line_break t (fun () -> skip_to_next_token t) 169 169 else begin 170 170 ignore (Input.next t.input); 171 171 skip_to_next_token t 172 172 end 173 - end 173 + end 174 174 175 175 (** Roll the indentation level *) 176 176 let roll_indent t col = ··· 723 723 (** Flush accumulated spaces to buf, applying fold rules for leading blanks *) 724 724 let flush_spaces_to_buf ~buf ~spaces ~leading_blanks = 725 725 if Buffer.length spaces > 0 then begin 726 - if !leading_blanks then begin 727 - if Buffer.contents spaces = "\n" then Buffer.add_char buf ' ' 726 + if !leading_blanks then 727 + begin if Buffer.contents spaces = "\n" then Buffer.add_char buf ' ' 728 728 else begin 729 729 let s = Buffer.contents spaces in 730 730 Buffer.add_substring buf s 1 (String.length s - 1) 731 731 end 732 - end 732 + end 733 733 else Buffer.add_buffer buf spaces; 734 734 Buffer.clear spaces 735 735 end ··· 809 809 skip_explicit_indent t ~literal ~content_indent ~trailing_breaks () 810 810 end 811 811 else if !spaces_skipped < !content_indent then !spaces_skipped 812 - else if Input.next_is_blank t.input then begin 813 - if literal then !content_indent 812 + else if Input.next_is_blank t.input then 813 + begin if literal then !content_indent 814 814 else begin 815 815 let idx = ref 0 in 816 816 while ··· 832 832 skip_explicit_indent t ~literal ~content_indent ~trailing_breaks () 833 833 | _ -> !content_indent 834 834 end 835 - end 835 + end 836 836 else !content_indent 837 837 838 838 (** Skip implicit-indent empty lines in a block scalar. Returns 0 when content ··· 884 884 (** Apply folded-style break collapsing to buf when there are trailing breaks *) 885 885 let apply_folded_breaks ~buf ~trailing_breaks ~leading_blank ~trailing_blank = 886 886 let breaks = Buffer.contents trailing_breaks in 887 - if (not !leading_blank) && not trailing_blank then begin 888 - if String.length breaks = 1 then Buffer.add_char buf ' ' 887 + if (not !leading_blank) && not trailing_blank then 888 + begin if String.length breaks = 1 then Buffer.add_char buf ' ' 889 889 else Buffer.add_substring buf breaks 1 (String.length breaks - 1) 890 - end 890 + end 891 891 else Buffer.add_buffer buf trailing_breaks 892 892 893 893 (** Add trailing breaks to buf applying folding rules for block scalars *) 894 894 let add_block_scalar_breaks ~buf ~trailing_breaks ~leading_blank ~trailing_blank 895 895 ~literal = 896 - if Buffer.length buf > 0 then begin 897 - if Buffer.length trailing_breaks > 0 then begin 898 - if literal then Buffer.add_buffer buf trailing_breaks 896 + if Buffer.length buf > 0 then 897 + begin if Buffer.length trailing_breaks > 0 then 898 + begin if literal then Buffer.add_buffer buf trailing_breaks 899 899 else 900 900 apply_folded_breaks ~buf ~trailing_breaks ~leading_blank ~trailing_blank 901 - end 901 + end 902 902 else if not literal then Buffer.add_char buf ' ' 903 - end 903 + end 904 904 else Buffer.add_buffer buf trailing_breaks; 905 905 Buffer.clear trailing_breaks 906 906 ··· 969 969 let first_line = !content_indent = 0 in 970 970 let base_level = base_indent - 1 in 971 971 let should_process = 972 - if !content_indent = 0 then begin 973 - if line_indent <= base_level then false 972 + if !content_indent = 0 then 973 + begin if line_indent <= base_level then false 974 974 else begin 975 975 if line_indent < !max_empty_line_indent && line_indent > base_level 976 976 then ··· 980 980 content_indent := line_indent; 981 981 true 982 982 end 983 - end 983 + end 984 984 else if line_indent < !content_indent then false 985 985 else true 986 986 in ··· 1107 1107 1108 1108 if Input.is_eof t.input then fetch_stream_end t 1109 1109 else if Input.at_document_boundary t.input then fetch_document_indicator t 1110 - else begin 1111 - match Input.peek t.input with 1110 + else 1111 + begin match Input.peek t.input with 1112 1112 | None -> fetch_stream_end t 1113 1113 | Some '%' when (Input.position t.input).column = 1 -> fetch_directive t 1114 1114 | Some '[' -> fetch_flow_collection_start t Token.Flow_sequence_start ··· 1132 1132 | Some ':' when can_start_plain t -> fetch_plain_scalar t 1133 1133 | Some c when can_start_plain_char c t -> fetch_plain_scalar t 1134 1134 | Some c -> Error.raise_at (Input.mark t.input) (Unexpected_character c) 1135 - end 1135 + end 1136 1136 1137 1137 and fetch_stream_end t = 1138 1138 if not t.stream_ended then begin ··· 1257 1257 1258 1258 (* Check for tabs after - : pattern like -\t- is invalid *) 1259 1259 let found_tabs, _found_spaces = skip_blanks_check_tabs t in 1260 - if found_tabs then begin 1260 + if found_tabs then 1261 1261 (* If we found tabs and next char is - followed by whitespace, error *) 1262 - match Input.peek t.input with 1262 + begin match Input.peek t.input with 1263 1263 | Some '-' -> ( 1264 1264 match Input.peek_nth t.input 1 with 1265 1265 | None -> Error.raise_at start Tab_in_indentation ··· 1267 1267 Error.raise_at start Tab_in_indentation 1268 1268 | Some _ -> ()) 1269 1269 | _ -> () 1270 - end; 1270 + end; 1271 1271 1272 1272 let span = Span.v ~start ~stop:(Input.mark t.input) in 1273 1273 emit t span Token.Block_entry ··· 1384 1384 let start = Input.mark t.input in 1385 1385 ignore (Input.next t.input); 1386 1386 let found_tabs, found_spaces = skip_blanks_check_tabs t in 1387 - if found_tabs && (not found_spaces) && t.flow_level = 0 then begin 1388 - match Input.peek t.input with 1387 + if found_tabs && (not found_spaces) && t.flow_level = 0 then 1388 + begin match Input.peek t.input with 1389 1389 | Some ('-' | '?') -> Error.raise_at start Tab_in_indentation 1390 1390 | Some c 1391 1391 when (c >= 'a' && c <= 'z') ··· 1393 1393 || (c >= '0' && c <= '9') -> 1394 1394 Error.raise_at start Tab_in_indentation 1395 1395 | _ -> () 1396 - end; 1396 + end; 1397 1397 skip_whitespace_and_comment t; 1398 1398 let span = Span.v ~start ~stop:(Input.mark t.input) in 1399 1399 emit t span Token.Value