From a67ad9ca27c5e2909c852a61f34b18a3414efc46 Mon Sep 17 00:00:00 2001 From: Jon French Date: Thu, 10 May 2018 11:19:41 +0100 Subject: add space handling mappings to riscv prelude and sail_lib.ml --- src/sail_lib.ml | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'src') diff --git a/src/sail_lib.ml b/src/sail_lib.ml index 1f3d0bba..b4c5a8aa 100644 --- a/src/sail_lib.ml +++ b/src/sail_lib.ml @@ -622,3 +622,25 @@ let speculate_conditional_success () = true (* Return nanoseconds since epoch. Truncates to ocaml int but will be OK for next 100 years or so... *) let get_time_ns () = Big_int.of_int (int_of_float (1e9 *. Unix.gettimeofday ())) +let rec n_leading_spaces s = + match String.length s with + | 0 -> 0 + | 1 -> begin match s with + | " " -> 1 + | _ -> 0 + end + | len -> begin match String.get s 0 with + | ' ' -> 1 + (n_leading_spaces (String.sub s 1 (len - 1))) + | _ -> 0 + end + + +let opt_spaces_matches_prefix s = + ZSome ((), n_leading_spaces s |> Big_int.of_int) + +let spaces_matches_prefix s = + let n = n_leading_spaces s in + match n with + | 0 -> ZNone () + | n -> ZSome ((), Big_int.of_int n) + -- cgit v1.2.3