src/HOL/Tools/Sledgehammer/sledgehammer_util.ML
changeset 35963 943e2582dc87
child 36062 194cb6e3c13f
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/HOL/Tools/Sledgehammer/sledgehammer_util.ML	Tue Mar 23 11:39:21 2010 +0100
     1.3 @@ -0,0 +1,53 @@
     1.4 +(*  Title:      HOL/Sledgehammer/sledgehammer_util.ML
     1.5 +    Author:     Jasmin Blanchette, TU Muenchen
     1.6 +
     1.7 +General-purpose functions used by the Sledgehammer modules.
     1.8 +*)
     1.9 +
    1.10 +signature SLEDGEHAMMER_UTIL =
    1.11 +sig
    1.12 +  val serial_commas : string -> string list -> string list
    1.13 +  val parse_bool_option : bool -> string -> string -> bool option
    1.14 +  val parse_time_option : string -> string -> Time.time option
    1.15 +end;
    1.16 +
    1.17 +structure Sledgehammer_Util : SLEDGEHAMMER_UTIL =
    1.18 +struct
    1.19 +
    1.20 +fun serial_commas _ [] = ["??"]
    1.21 +  | serial_commas _ [s] = [s]
    1.22 +  | serial_commas conj [s1, s2] = [s1, conj, s2]
    1.23 +  | serial_commas conj [s1, s2, s3] = [s1 ^ ",", s2 ^ ",", conj, s3]
    1.24 +  | serial_commas conj (s :: ss) = s ^ "," :: serial_commas conj ss
    1.25 +
    1.26 +fun parse_bool_option option name s =
    1.27 +  (case s of
    1.28 +     "smart" => if option then NONE else raise Option
    1.29 +   | "false" => SOME false
    1.30 +   | "true" => SOME true
    1.31 +   | "" => SOME true
    1.32 +   | _ => raise Option)
    1.33 +  handle Option.Option =>
    1.34 +         let val ss = map quote ((option ? cons "smart") ["true", "false"]) in
    1.35 +           error ("Parameter " ^ quote name ^ " must be assigned " ^
    1.36 +                  space_implode " " (serial_commas "or" ss) ^ ".")
    1.37 +         end
    1.38 +
    1.39 +fun parse_time_option _ "none" = NONE
    1.40 +  | parse_time_option name s =
    1.41 +    let
    1.42 +      val msecs =
    1.43 +        case space_explode " " s of
    1.44 +          [s1, "min"] => 60000 * the (Int.fromString s1)
    1.45 +        | [s1, "s"] => 1000 * the (Int.fromString s1)
    1.46 +        | [s1, "ms"] => the (Int.fromString s1)
    1.47 +        | _ => 0
    1.48 +    in
    1.49 +      if msecs <= 0 then
    1.50 +        error ("Parameter " ^ quote name ^ " must be assigned a positive time \
    1.51 +               \value (e.g., \"60 s\", \"200 ms\") or \"none\".")
    1.52 +      else
    1.53 +        SOME (Time.fromMilliseconds msecs)
    1.54 +    end
    1.55 +
    1.56 +end;