Minimal dependency-free XML parser and serializer
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

+45 -43
+1 -1
.ocamlformat
··· 1 - version = 0.28.1 1 + version = 0.29.0
+44 -42
lib/xmlt.ml
··· 156 156 let skip_while s f = 157 157 let continue = ref true in 158 158 while !continue do 159 - if s.buf_pos < s.buf_len then begin 160 - if f (Stdlib.Bytes.get s.buf s.buf_pos) then advance s 159 + if s.buf_pos < s.buf_len then 160 + begin if f (Stdlib.Bytes.get s.buf s.buf_pos) then advance s 161 161 else continue := false 162 - end 162 + end 163 163 else if s.eof then continue := false 164 164 else begin 165 165 ensure s 1; ··· 272 272 match read_entity_name s with 273 273 | None -> Error "unterminated entity reference" 274 274 | Some name -> ( 275 - if String.length name > 0 && name.[0] = '#' then begin 276 - match 275 + if String.length name > 0 && name.[0] = '#' then 276 + begin match 277 277 decode_char_ref (String.sub name 1 (String.length name - 1)) 278 278 with 279 279 | Ok str -> 280 280 Buffer.add_string buf str; 281 281 Ok () 282 282 | Error _ as e -> e 283 - end 283 + end 284 284 else 285 285 match decode_entity name with 286 286 | Ok c -> ··· 301 301 else 302 302 let c = consume s in 303 303 if c = quote then Ok (Buffer.contents buf) 304 - else if c = '&' then begin 305 - match decode_entity_buf buf s with 304 + else if c = '&' then 305 + begin match decode_entity_buf buf s with 306 306 | Ok () -> loop () 307 307 | Error _ as e -> e 308 - end 308 + end 309 309 else begin 310 310 Buffer.add_char buf c; 311 311 loop () ··· 533 533 | Error e -> Error e 534 534 | Ok text -> loop (Text text :: acc) 535 535 end 536 - else if P.starts_with s "<" then begin 537 - match parse_element s with 536 + else if P.starts_with s "<" then 537 + begin match parse_element s with 538 538 | Error e -> Error e 539 539 | Ok el -> loop (Element el :: acc) 540 - end 541 - else begin 542 - match P.parse_text s with 540 + end 541 + else 542 + begin match P.parse_text s with 543 543 | Error e -> Error e 544 544 | Ok text -> 545 545 if String.length text > 0 then loop (Text text :: acc) else loop acc 546 - end 546 + end 547 547 in 548 548 loop [] 549 549 ··· 758 758 Buffer.add_string buf text; 759 759 loop () 760 760 end 761 - else if P.starts_with s "<" then begin 761 + else if P.starts_with s "<" then 762 762 (* Child element -- skip it entirely *) 763 - match stream_skip_element s with 763 + begin match stream_skip_element s with 764 764 | Error e -> Error e 765 765 | Ok () -> loop () 766 - end 767 - else begin 768 - match P.parse_text s with 766 + end 767 + else 768 + begin match P.parse_text s with 769 769 | Error e -> Error e 770 770 | Ok text -> 771 771 if String.length text > 0 then Buffer.add_string buf text; 772 772 loop () 773 - end 773 + end 774 774 in 775 775 loop () 776 776 ··· 800 800 P.skip_n s 9; 801 801 match P.parse_cdata s with Error e -> Error e | Ok _text -> loop () 802 802 end 803 - else if P.starts_with s "<" then begin 804 - match stream_skip_element s with Error e -> Error e | Ok () -> loop () 805 - end 806 - else begin 807 - match P.parse_text s with Error e -> Error e | Ok _text -> loop () 808 - end 803 + else if P.starts_with s "<" then 804 + begin match stream_skip_element s with 805 + | Error e -> Error e 806 + | Ok () -> loop () 807 + end 808 + else 809 + begin match P.parse_text s with Error e -> Error e | Ok _text -> loop () 810 + end 809 811 in 810 812 loop () 811 813 ··· 1054 1056 Buffer.add_string text_buf text; 1055 1057 loop () 1056 1058 end 1057 - else if P.starts_with s "<" then begin 1059 + else if P.starts_with s "<" then 1058 1060 (* Child element start tag *) 1059 - match P.parse_start_tag s with 1061 + begin match P.parse_start_tag s with 1060 1062 | Error e -> error := Some e 1061 1063 | Ok (child_tag, child_attrs, child_self_close) -> 1062 1064 (* Try to find a matching field *) ··· 1118 1120 in 1119 1121 List.iter process_field fields; 1120 1122 (* If no field matched, skip the entire child element *) 1121 - if (not !matched) && !error = None then begin 1122 - if child_self_close then () 1123 + if (not !matched) && !error = None then 1124 + begin if child_self_close then () 1123 1125 else 1124 1126 match stream_skip_children s with 1125 1127 | Error e -> error := Some e ··· 1127 1129 match P.consume_end_tag s child_tag with 1128 1130 | Error e -> error := Some e 1129 1131 | Ok () -> ()) 1130 - end; 1132 + end; 1131 1133 if !error = None then loop () 1132 - end 1133 - else begin 1134 - match P.parse_text s with 1134 + end 1135 + else 1136 + begin match P.parse_text s with 1135 1137 | Error e -> error := Some e 1136 1138 | Ok text -> 1137 1139 if String.length text > 0 then Buffer.add_string text_buf text; 1138 1140 loop () 1139 - end 1141 + end 1140 1142 in 1141 1143 loop (); 1142 1144 match !error with ··· 1226 1228 P.skip_n s 9; 1227 1229 match P.parse_cdata s with Error e -> Error e | Ok _text -> loop acc 1228 1230 end 1229 - else if P.starts_with s "<" then begin 1230 - match P.parse_start_tag s with 1231 + else if P.starts_with s "<" then 1232 + begin match P.parse_start_tag s with 1231 1233 | Error e -> Error e 1232 1234 | Ok (child_tag, child_attrs, child_self_close) -> ( 1233 1235 match ··· 1241 1243 match P.consume_end_tag s child_tag with 1242 1244 | Error e -> Error e 1243 1245 | Ok () -> loop (v :: acc))) 1244 - end 1245 - else begin 1246 + end 1247 + else 1246 1248 (* Skip text content between child elements *) 1247 - match P.parse_text s with 1249 + begin match P.parse_text s with 1248 1250 | Error e -> Error e 1249 1251 | Ok _text -> loop acc 1250 - end 1252 + end 1251 1253 in 1252 1254 loop [] 1253 1255