Skip to content

Commit

Permalink
Dunify project, additional tuning
Browse files Browse the repository at this point in the history
  • Loading branch information
hhugo committed Sep 1, 2018
1 parent bc42455 commit 3856d00
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 27 deletions.
44 changes: 18 additions & 26 deletions src/oDate.ml
Original file line number Diff line number Diff line change
Expand Up @@ -383,11 +383,10 @@ module Make(Implem : Implem) = struct
length = String.length str
}

(*
let parse_constant s =
let _parse_constant s =
let size = String.length s in
(fun ptr ->
let {str;pos; _} = ptr in
let {str;pos;_} = ptr in
let rec loop i =
if i = size
then ()
Expand All @@ -398,7 +397,6 @@ module Make(Implem : Implem) = struct
let () = loop 0 in
ptr.pos <- ptr.pos + size
)
*)

let parse_constant_i s =
let (+++) a i = char_of_int ( int_of_char a + i) in
Expand Down Expand Up @@ -476,22 +474,20 @@ module Make(Implem : Implem) = struct
end)

let parse_single_char = parse_char ~min:1 ~max:1
(* let parse_char_plus x = parse_char ~min:1 x *)

let _parse_char_plus x = parse_char ~min:1 x
let ignore' f = (fun ptr -> ignore (f ptr))

let (>>==) f g =
(fun ptr -> g (f ptr))
let (>>=|) f c =
(fun ptr -> ignore (f ptr); c)
(fun ptr -> f ptr; c)

(*
let parse_remaining ptr =
let _parse_remaining ptr =
let size = String.length ptr.str in
let s = String.sub ptr.str ptr.pos (size - ptr.pos) in
ptr.pos <- size;
s
*)


let parse_option p ptr=
try Some (p ptr) with _ -> None

Expand All @@ -504,7 +500,7 @@ let parse_remaining ptr =
let s = Weekday.to_string w in
let s = if short then String.sub s 0 3 else s in
loop (succ i) ((parse_constant_i s >>=| w) :: acc) in
parse_sum (loop 0 [(fun _ -> failwith "weekday")])
parse_sum (loop 0 [(fun _ptr -> failwith "weekday")])

let parse_month short =
let rec loop i acc =
Expand All @@ -517,26 +513,22 @@ let parse_remaining ptr =
loop (succ i) ((parse_constant_i s >>=| m) :: acc) in
parse_sum (loop 1 [])

(*
let parse_seq l ptr =
let _parse_seq l ptr =
let rec loop acc = function
| [] -> List.rev acc
| x::xs -> loop (x ptr :: acc) xs in
loop [] l
*)

(*
let parse_fold f acc l ptr =

let _parse_fold f acc l ptr =
let rec loop acc = function
| [] -> acc
| x::xs -> loop (f acc (x ptr)) xs in
loop acc l
*)


let parse_sign =
parse_sum [
parse_single_char '-' >>=| (-);
parse_single_char '+' >>=| (+)
(ignore' (parse_single_char '-') >>=| (-));
(ignore' (parse_single_char '+') >>=| (+))
]

let parse_timezone =
Expand Down Expand Up @@ -621,7 +613,7 @@ let parse_remaining ptr =
let tokens = date_token s in
let l = List.rev_map (function
| String s -> parse_constant_i s >>=| (fun d -> d)
| Space -> parse_space >>=| (fun d -> d)
| Space -> ignore' parse_space >>=| (fun d -> d)
| Directive (p,c) -> parse_directive (p,c)
| EOL -> assert false) tokens
in
Expand All @@ -643,7 +635,7 @@ let parse_remaining ptr =
) abbreviations in
List.iter add_abbr abbr

let human ?tz {s;m;h;day;month;year;tz=tz';_} =
let human ?tz {s;m;h;day;month;year;tz=tz';wday=_} =
let tz = match tz with
| None -> tz'
| Some x -> x in
Expand Down Expand Up @@ -776,7 +768,7 @@ let parse_remaining ptr =
let a = a mod n in
if a < 0 then a + n else a

let calendar_advance t {D.forward;h;m;s;day;month;year;_} =
let calendar_advance t {D.forward;h;m;s;day;month;year;ms=_} =
let human = To.human t in
let add = if forward then (fun a x -> a + x) else (fun a x -> a - x) in
let human = {human with
Expand Down Expand Up @@ -987,7 +979,7 @@ module MakeImplem(C : Clock) : Implem = struct
}
let now () = C.time ()
let now_milliseconds () = C.gettimeofday () *. 1000.
let from_human ?tz {s;m;h;day;month;year;tz=tz';_} =
let from_human ?tz {s;m;h;day;month;year;tz=tz';wday=_} =
let tz = match tz with
| None -> tz'
| Some tz -> tz in
Expand Down
3 changes: 2 additions & 1 deletion src/oDuration.ml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ module type S = sig
val human : human_readable -> t
end
module To : sig
val ms : t -> int
val s : t -> int
val s_float : t -> float
val m : t -> int
Expand Down Expand Up @@ -90,7 +91,7 @@ module D : S = struct
end

module To = struct
(* let ms t = int_of_float (O.to_float t) *)
let ms t = int_of_float (O.to_float t)
let s_float t = O.(to_float (t / ms_in_s))
let aux divide t = int_of_float (O.to_float t /. O.to_float divide)
let s = aux ms_in_s
Expand Down
1 change: 1 addition & 0 deletions src/oDuration.mli
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ module type S = sig
val human : human_readable -> t
end
module To : sig
val ms : t -> int
val s : t -> int
val s_float : t -> float
val m : t -> int
Expand Down

0 comments on commit 3856d00

Please sign in to comment.