src/HOL/Tools/Sledgehammer/sledgehammer_util.ML
author blanchet
Tue Mar 23 11:39:21 2010 +0100 (2010-03-23)
changeset 35963 943e2582dc87
child 36062 194cb6e3c13f
permissions -rw-r--r--
added options to Sledgehammer;
syntax: sledgehammer [options] goal_no, where "[options]" and "goal_no" are optional
blanchet@35963
     1
(*  Title:      HOL/Sledgehammer/sledgehammer_util.ML
blanchet@35963
     2
    Author:     Jasmin Blanchette, TU Muenchen
blanchet@35963
     3
blanchet@35963
     4
General-purpose functions used by the Sledgehammer modules.
blanchet@35963
     5
*)
blanchet@35963
     6
blanchet@35963
     7
signature SLEDGEHAMMER_UTIL =
blanchet@35963
     8
sig
blanchet@35963
     9
  val serial_commas : string -> string list -> string list
blanchet@35963
    10
  val parse_bool_option : bool -> string -> string -> bool option
blanchet@35963
    11
  val parse_time_option : string -> string -> Time.time option
blanchet@35963
    12
end;
blanchet@35963
    13
blanchet@35963
    14
structure Sledgehammer_Util : SLEDGEHAMMER_UTIL =
blanchet@35963
    15
struct
blanchet@35963
    16
blanchet@35963
    17
fun serial_commas _ [] = ["??"]
blanchet@35963
    18
  | serial_commas _ [s] = [s]
blanchet@35963
    19
  | serial_commas conj [s1, s2] = [s1, conj, s2]
blanchet@35963
    20
  | serial_commas conj [s1, s2, s3] = [s1 ^ ",", s2 ^ ",", conj, s3]
blanchet@35963
    21
  | serial_commas conj (s :: ss) = s ^ "," :: serial_commas conj ss
blanchet@35963
    22
blanchet@35963
    23
fun parse_bool_option option name s =
blanchet@35963
    24
  (case s of
blanchet@35963
    25
     "smart" => if option then NONE else raise Option
blanchet@35963
    26
   | "false" => SOME false
blanchet@35963
    27
   | "true" => SOME true
blanchet@35963
    28
   | "" => SOME true
blanchet@35963
    29
   | _ => raise Option)
blanchet@35963
    30
  handle Option.Option =>
blanchet@35963
    31
         let val ss = map quote ((option ? cons "smart") ["true", "false"]) in
blanchet@35963
    32
           error ("Parameter " ^ quote name ^ " must be assigned " ^
blanchet@35963
    33
                  space_implode " " (serial_commas "or" ss) ^ ".")
blanchet@35963
    34
         end
blanchet@35963
    35
blanchet@35963
    36
fun parse_time_option _ "none" = NONE
blanchet@35963
    37
  | parse_time_option name s =
blanchet@35963
    38
    let
blanchet@35963
    39
      val msecs =
blanchet@35963
    40
        case space_explode " " s of
blanchet@35963
    41
          [s1, "min"] => 60000 * the (Int.fromString s1)
blanchet@35963
    42
        | [s1, "s"] => 1000 * the (Int.fromString s1)
blanchet@35963
    43
        | [s1, "ms"] => the (Int.fromString s1)
blanchet@35963
    44
        | _ => 0
blanchet@35963
    45
    in
blanchet@35963
    46
      if msecs <= 0 then
blanchet@35963
    47
        error ("Parameter " ^ quote name ^ " must be assigned a positive time \
blanchet@35963
    48
               \value (e.g., \"60 s\", \"200 ms\") or \"none\".")
blanchet@35963
    49
      else
blanchet@35963
    50
        SOME (Time.fromMilliseconds msecs)
blanchet@35963
    51
    end
blanchet@35963
    52
blanchet@35963
    53
end;