Skip to content

Commit

Permalink
3.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
SGrondin committed Nov 26, 2022
1 parent 74e654a commit 9bd401a
Show file tree
Hide file tree
Showing 19 changed files with 100 additions and 104 deletions.
52 changes: 28 additions & 24 deletions .ocamlformat
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# "Asemio Style" v1.0
# Last updated for ocamlformat 0.15.0
# "Asemio Style" v1.2
# Last updated for ocamlformat 0.21.0

# All available options are listed.
# An option is commented out when the value matches the default
Expand All @@ -8,53 +8,36 @@
# - try out new values for existing options
# - if a default changed, see if we should follow it or not

# align-cases = false
align-constructors-decl = true
align-variants-decl = true
# assignment-operator = end-line
# break-before-in = fit-or-vertical
break-cases = all
# break-collection-expressions = fit-or-vertical
# break-fun-decl = wrap
# break-fun-sig = wrap
break-infix = fit-or-vertical
# break-infix-before-func = false
# break-separators = after
# break-sequences = true
# break-string-literals = auto
# break-struct = force
cases-exp-indent = 2
# cases-matching-exp-indent = normal
disambiguate-non-breaking-match = true
doc-comments = before
# doc-comments-padding = 2
# doc-comments-tag-only = default
# dock-collection-brackets = true
exp-grouping = preserve
# extension-indent = 2
field-space = tight-decl
function-indent = 0
# function-indent-nested = never
if-then-else = keyword-first
# indent-after-in = 0
indicate-multiline-delimiters = closing-on-separate-line
# indicate-multiline-delimiters = no
indicate-nested-or-patterns = space
# infix-precedence = indent
# leading-nested-match-parens = false
let-and = sparse
# let-binding-indent = 2
# let-binding-spacing = compact
# let-module = compact
# let-open = preserve
line-endings = lf
margin = 106
# match-indent = 0
# match-indent-nested = never
max-indent = 3
# module-item-spacing = sparse
# nested-match = wrap
module-item-spacing = sparse
parens-ite = true
parens-tuple = multi-line-only
# parens-tuple-patterns = multi-line-only
# parse-docstrings = false
# sequence-blank-line = preserve-one
# sequence-style = terminator
Expand All @@ -63,8 +46,29 @@ single-case = sparse
# space-around-lists = true
# space-around-records = true
# space-around-variants = true
# stritem-extension-indent = 0
type-decl = sparse
# type-decl-indent = 2
# wrap-comments = false
# wrap-fun-args = true


# DEPRECATED

# align-cases = false
align-constructors-decl = true
align-variants-decl = true
# break-before-in = fit-or-vertical
# break-collection-expressions = fit-or-vertical
# break-string-literals = auto
# break-struct = force
disambiguate-non-breaking-match = true
# extension-indent = 2
function-indent = 0
# function-indent-nested = never
# indent-after-in = 0
# let-binding-indent = 2
# match-indent = 0
# match-indent-nested = never
# nested-match = wrap
# parens-tuple-patterns = multi-line-only
# stritem-extension-indent = 0
# type-decl-indent = 2
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -232,11 +232,11 @@ Manually resolve a single SST reference.

#### `parse_date`

XLSX uses its `number` type (OCaml float) to encode Date cells. This function converts one such float into a Core_kernel `Date.t`.
XLSX uses its `number` type (OCaml float) to encode Date cells. This function converts one such float into a Core `Date.t`.

#### `parse_datetime`

XLSX uses its `number` type (OCaml float) to encode DateTime cells. This function converts one such float into a Core_kernel `Time.t`.
XLSX uses its `number` type (OCaml float) to encode DateTime cells. This function converts one such float into a Core `Time.t`.

#### `index_of_column`

Expand Down
9 changes: 4 additions & 5 deletions SZXX.opam
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,19 @@ dev-repo: "git://github.com/asemio/SZXX"
doc: "https://github.com/asemio/SZXX"
bug-reports: "https://github.com/asemio/SZXX/issues"
depends: [
"ocaml" { >= "4.08.1" }
"ocaml" { >= "4.10.0" }
"dune" { >= "1.9.0" }

"angstrom" { >= "0.15.0" }
"core_kernel" { >= "v0.13.0" }
"core" { >= "v0.15.0" }
"decompress" { >= "1.4.1" }
"lwt" { >= "5.3.0" }

"alcotest-lwt" { with-test }
"angstrom-lwt-unix" { >= "0.15.0" & with-test }
# "ppx_jane" { with-test }
"yojson" { with-test }
"ppx_deriving_yojson" { >= "3.5.2" & with-test }
# "ocaml-lsp-server" { with-test }
# "ocamlformat" { = "0.15.0" & with-test }
# "ocamlformat" { = "0.21.0" } # Development
# "ocaml-lsp-server" # Development
]
build: ["dune" "build" "-p" name "-j" jobs]
2 changes: 1 addition & 1 deletion dune-project
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
(lang dune 1.9)
(name SZXX)
(version 2.3.0)
(version 3.0.0)
2 changes: 1 addition & 1 deletion src/SZXX.ml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
open! Core_kernel
open! Core
module Zip = Zip
module Xml = Xml
module Xlsx = Xlsx
2 changes: 1 addition & 1 deletion src/dune
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
(name SZXX)
(public_name SZXX)
(libraries
core_kernel
core
angstrom
checkseum.ocaml
decompress.de
Expand Down
5 changes: 2 additions & 3 deletions src/parsing.ml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
open! Core_kernel
open! Core
open Angstrom

type storage = {
Expand Down Expand Up @@ -75,8 +75,7 @@ let bounded_file_reader ~pattern { add; finalize } =
if len > slice_size
then (
add buf len;
pos := 0
)
pos := 0)
in
let rec loop window =
match same ~pattern table window (len - 1) with
Expand Down
24 changes: 8 additions & 16 deletions src/xlsx.ml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
open! Core_kernel
open! Core
open Lwt.Syntax
open Lwt.Infix

Expand Down Expand Up @@ -59,8 +59,7 @@ let fold_angstrom ~filter_path ~on_match =
let acc = Xml.SAX.Stream.folder ~filter_path ~on_match acc node in
match parse xml_parser with
| Partial feed -> (loop [@tailcall]) (feed (`Bigstring (Bigstring.sub_shared buf ~pos ~len))) acc
| state -> (loop [@tailcall]) state acc
)
| state -> (loop [@tailcall]) state acc)
| state -> state
in
let f _entry bs ~len = function
Expand All @@ -87,8 +86,7 @@ let parse_sheet ~sheet_number push =
done;
num := i
with
| _ -> incr num
));
| _ -> incr num));
push { sheet_number; row_number = !num; data = el.children }
in
fold_angstrom ~filter_path:[ "worksheet"; "sheetData"; "row" ] ~on_match
Expand Down Expand Up @@ -183,8 +181,7 @@ let unwrap_status cell_parser (sst : SST.t) (row : 'a status row) =
| Delayed { location; sst_index } -> (
match resolve_sst_index sst ~sst_index with
| Some index -> cell_parser.string location index
| None -> cell_parser.null
))
| None -> cell_parser.null))
in
{ row with data }

Expand All @@ -203,13 +200,11 @@ let extract_cell_sst, extract_cell_status =
| Some "str" -> (
match el |> dot_text "v" with
| None -> null
| Some s -> formula location s ~formula:(el |> dot_text "f" |> Option.value ~default:"")
)
| Some s -> formula location s ~formula:(el |> dot_text "f" |> Option.value ~default:""))
| Some "inlineStr" -> (
match dot "is" el with
| None -> null
| Some el -> string location (parse_string_cell el)
)
| Some el -> string location (parse_string_cell el))
| Some "e" -> el |> dot "v" |> extract ~null location error
| Some "b" -> el |> dot "v" |> extract ~null location boolean
| Some t -> failwithf "Unknown data type: %s ::: %s" t (sexp_of_element el |> Sexp.to_string) ()
Expand All @@ -222,18 +217,15 @@ let extract_cell_sst, extract_cell_status =
| Some { text = sst_index; _ } -> (
match resolve_sst_index sst ~sst_index with
| None -> cell_parser.null
| Some resolved -> cell_parser.string location resolved
)
)
| Some resolved -> cell_parser.string location resolved))
| ty -> extract_cell_base cell_parser location el ty
in
let extract_cell_status cell_parser location el =
match Xml.get_attr el.attrs "t" with
| Some "s" -> (
match el |> dot "v" with
| None -> Available cell_parser.null
| Some { text = sst_index; _ } -> Delayed { location; sst_index }
)
| Some { text = sst_index; _ } -> Delayed { location; sst_index })
| ty -> Available (extract_cell_base cell_parser location el ty)
in
extract_cell_sst, extract_cell_status
Expand Down
2 changes: 1 addition & 1 deletion src/xlsx.mli
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
open! Core_kernel
open! Core

type location = {
sheet_number: int;
Expand Down
14 changes: 5 additions & 9 deletions src/xml.ml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module STR = String
open! Core_kernel
open! Core
open Angstrom

type attr_list = (string * string) list [@@deriving sexp_of]
Expand Down Expand Up @@ -301,8 +301,7 @@ let decode_exn = function
|> Int.of_string
|> encode_utf_8_codepoint
| '#', '0' .. '9' -> String.slice str 1 0 |> Int.of_string |> encode_utf_8_codepoint
| _ -> raise (Invalid_argument str)
)
| _ -> raise (Invalid_argument str))

let unescape original =
let rec loop buf from =
Expand All @@ -316,8 +315,7 @@ let unescape original =
(match decode_exn (String.slice original (start + 1) stop) with
| s -> Buffer.add_string buf s
| exception _ -> Buffer.add_substring buf original ~pos:start ~len:(stop - start + 1));
loop buf (stop + 1)
)
loop buf (stop + 1))
in
(* Unroll first index call for performance *)
match String.index original '&' with
Expand Down Expand Up @@ -386,8 +384,7 @@ let make_parser { accept_html_boolean_attributes; accept_unquoted_attributes } =
false
| _ -> true)
in
choice [ dq_string; sq_string; uq_string ]
)
choice [ dq_string; sq_string; uq_string ])
else choice [ dq_string; sq_string ]
in
let attr_parser =
Expand All @@ -405,8 +402,7 @@ let make_parser { accept_html_boolean_attributes; accept_unquoted_attributes } =
(string "<!DOCTYPE" <|> string "<!doctype")
*> (skip_many (blank *> choice [ drop token_parser; drop xml_string_parser; declarations ])
<* blank
<* char '>'
)
<* char '>')
>>| const SAX.Nothing
in
let comment_parser = comment >>| const SAX.Nothing in
Expand Down
2 changes: 1 addition & 1 deletion src/xml.mli
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
open! Core_kernel
open! Core

type attr_list = (string * string) list [@@deriving sexp_of]

Expand Down
17 changes: 6 additions & 11 deletions src/zip.ml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
open! Core_kernel
open! Core
open Lwt.Syntax
open Lwt.Infix

Expand Down Expand Up @@ -276,17 +276,15 @@ let parser cb =
trailing_descriptor_present =
(flags land 0x008 <> 0
|| Int64.(descriptor.compressed_size = 0L)
|| Int64.(descriptor.uncompressed_size = 0L)
);
|| Int64.(descriptor.uncompressed_size = 0L));
methd;
descriptor;
filename;
extra_fields;
})
(flags_methd_parser
<* LE.any_uint16 (* last modified time *)
<* LE.any_uint16 (* last modified date *)
)
<* LE.any_uint16 (* last modified date *))
descriptor_parser dynamic_len_fields_parser
in
lift2 const entry_parser commit >>= fun entry ->
Expand Down Expand Up @@ -360,17 +358,14 @@ let stream_files ~feed:read cb =
let* () = Lwt_mutex.with_lock mutex (fun () -> bounded#push pair) in
match parse (parser cb) with
| Partial feed -> (loop [@tailcall]) (feed (`Bigstring (Bigstring.sub_shared buf ~pos ~len)))
| state -> (loop [@tailcall]) state
)
| state -> (loop [@tailcall]) state)
| Partial feed -> (
read () >>= function
| None -> (
match feed `Eof with
| Done (_, pair) -> Lwt_mutex.with_lock mutex (fun () -> bounded#push pair)
| _ -> Lwt.return_unit
)
| Some chunk -> (loop [@tailcall]) (feed chunk)
)
| _ -> Lwt.return_unit)
| Some chunk -> (loop [@tailcall]) (feed chunk))
in
let p =
Lwt.finalize
Expand Down
2 changes: 1 addition & 1 deletion src/zip.mli
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
open! Core_kernel
open! Core

type methd =
| Stored
Expand Down
2 changes: 1 addition & 1 deletion test/dune
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
angstrom-lwt-unix

alcotest-lwt
core_kernel
core
lwt
lwt.unix
yojson
Expand Down
6 changes: 2 additions & 4 deletions test/json_diff.ml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
open! Core_kernel
open! Core

type mismatch =
| Changed of (Yojson.Safe.t * Yojson.Safe.t)
Expand Down Expand Up @@ -43,9 +43,7 @@ let check left right =
| `Both (x, y) ->
sprintf "%s: %s %s %s"
(color (sprintf "+/- %s" key) `Yellow)
(stringify x)
(color "!=" `Yellow)
(stringify y)
(stringify x) (color "!=" `Yellow) (stringify y)
|> mismatch)
in
match Queue.length errors with
Expand Down
4 changes: 2 additions & 2 deletions test/xlsx.ml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
let flags = Unix.[ O_RDONLY; O_NONBLOCK ]

open! Core_kernel
open! Core
open Lwt.Syntax
open Lwt.Infix

Expand Down Expand Up @@ -154,7 +154,7 @@ let stream_rows filename () =
Lwt_io.with_file ~flags ~mode:Input xlsx_path (fun ic ->
let open SZXX.Xlsx in
let stream, sst, processed = stream_rows ~feed:(feed_bigstring ic) yojson_cell_parser in
let* sst = sst in
let* sst in
let json_list_p =
Lwt_stream.map
(fun status ->
Expand Down
Loading

0 comments on commit 9bd401a

Please sign in to comment.