diff --git a/src/driver/whyconf.ml b/src/driver/whyconf.ml index edb385abb9cbc6755cffacbc43a14813816390b2..36eebebfc750eabed0375152e6fce696ea8596ba 100644 --- a/src/driver/whyconf.ml +++ b/src/driver/whyconf.ml @@ -24,6 +24,8 @@ open Util type error = | SyntaxError + | ExtraParameters of string + | MissingParameters of string | UnknownSection of string | UnknownField of string | MissingSection of string @@ -51,6 +53,10 @@ let print_rc_value fmt = function let report fmt = function | SyntaxError -> fprintf fmt "syntax error" + | ExtraParameters s -> + fprintf fmt "section '%s': header too long" s + | MissingParameters s -> + fprintf fmt "section '%s': header too short" s | UnknownSection s -> fprintf fmt "unknown section '%s'" s | UnknownField s -> @@ -79,9 +85,9 @@ let report fmt = function (* Configuration file *) type config_prover = { - description : string; (* "Alt-Ergo v2.95 (special)" *) - command : string; (* "exec why-limit %t %m alt-ergo %f" *) - driver_file : string; (* "/usr/local/share/why/drivers/ergo-spec.drv" *) + name : string; (* "Alt-Ergo v2.95 (special)" *) + command : string; (* "exec why-limit %t %m alt-ergo %f" *) + driver : string; (* "/usr/local/share/why/drivers/ergo-spec.drv" *) } type config = { @@ -120,27 +126,20 @@ let get_field f = function | None -> error (MissingField f) | Some v -> v -let load_prover provers al = +let load_prover al = let nam = ref None in - let dsc = ref None in let cmd = ref None in let drv = ref None in let load (key, value) = match key with - | "name" -> set_ident key nam value - | "description" -> set_string key dsc value + | "name" -> set_string key nam value | "command" -> set_string key cmd value | "driver" -> set_string key drv value | _ -> error (UnknownField key) in List.iter load al; - let prover = { - description = get_field "description" !dsc; - command = get_field "command" !cmd; - driver_file = get_field "driver" !drv } - in - let n = get_field "name" !nam in - if Mstr.mem n provers then error (DuplicateProver n); - Mstr.add n prover provers + { name = get_field "name" !nam; + command = get_field "command" !cmd; + driver = get_field "driver" !drv } let load_main main al = let lp = ref [] in @@ -181,10 +180,17 @@ let read_config ?conf_file () = let provers = ref Mstr.empty in let have_main = ref false in let load (key, al) = match key with - | "main" when !have_main -> error (DuplicateSection key) - | "main" -> main := load_main !main al - | "prover" -> provers := load_prover !provers al - | _ -> error (UnknownSection key) + | "main" :: rest -> + if rest <> [] then error (ExtraParameters "main"); + if !have_main then error (DuplicateSection "main"); + main := load_main !main al + | "prover" :: name :: rest -> + if rest <> [] then error (ExtraParameters ("prover " ^ name)); + if Mstr.mem name !provers then error (DuplicateProver name); + provers := Mstr.add name (load_prover al) !provers + | "prover" :: [] -> error (MissingParameters "prover") + | s :: _ -> error (UnknownSection s) + | [] -> assert false in List.iter load rc; { !main with provers = !provers } @@ -198,11 +204,10 @@ let save_config config = Util.option_iter (fprintf fmt "memlimit = %d@\n") config.memlimit; fprintf fmt "@."; let print_prover name prover = - fprintf fmt "[prover]@\n"; - fprintf fmt "name = %s@\n" name; - fprintf fmt "description = \"%s\"@\n" prover.description; + fprintf fmt "[prover %s]@\n" name; + fprintf fmt "name = \"%s\"@\n" prover.name; fprintf fmt "command = \"%s\"@\n" prover.command; - fprintf fmt "driver = \"%s\"@\n@." prover.driver_file; + fprintf fmt "driver = \"%s\"@\n@." prover.driver; in Mstr.iter print_prover config.provers; close_out ch diff --git a/src/driver/whyconf.mli b/src/driver/whyconf.mli index d2c9084f503a0f8493c6f46b768d9feb950c589a..88f65c3aa9033dd4f3402d00887d8b15bb06ba38 100644 --- a/src/driver/whyconf.mli +++ b/src/driver/whyconf.mli @@ -20,9 +20,9 @@ open Util type config_prover = { - description : string; (* "Alt-Ergo v2.95 (special)" *) - command : string; (* "exec why-limit %t %m alt-ergo %f" *) - driver_file : string; (* "/usr/local/share/why/drivers/ergo-spec.drv" *) + name : string; (* "Alt-Ergo v2.95 (special)" *) + command : string; (* "exec why-limit %t %m alt-ergo %f" *) + driver : string; (* "/usr/local/share/why/drivers/ergo-spec.drv" *) } type config = { diff --git a/src/manager/test.ml b/src/manager/test.ml index f52943d8fe684d1053df660bd18c75571898d463..830e017c07899fc2d917dfeed9efa5ea94750b30 100644 --- a/src/manager/test.ml +++ b/src/manager/test.ml @@ -5,24 +5,24 @@ open Whyconf let autodetection () = let alt_ergo = { - description = "Alt-Ergo"; - command = "alt-ergo %s"; - driver_file = "drivers/alt_ergo.drv" } + name = "Alt-Ergo"; + command = "alt-ergo %s"; + driver = "drivers/alt_ergo.drv" } in let z3 = { - description = "Z3"; - command = "z3 -smt -in"; - driver_file = "drivers/z3.drv" } + name = "Z3"; + command = "z3 -smt -in"; + driver = "drivers/z3.drv" } in let cvc3 = { - description = "CVC3"; - command = "cvc3 -lang smt"; - driver_file = "drivers/cvc3.drv" } + name = "CVC3"; + command = "cvc3 -lang smt"; + driver = "drivers/cvc3.drv" } in let coq = { - description = "Coq"; - command = "coqc %s"; - driver_file = "drivers/coq.drv" } + name = "Coq"; + command = "coqc %s"; + driver = "drivers/coq.drv" } in let provers = Util.Mstr.empty in let provers = Util.Mstr.add "alt-ergo" alt_ergo provers in diff --git a/src/util/rc.mli b/src/util/rc.mli index b681f13ae68527f4ba9c4591622059b16bbb594f..6924f501f8e084f3b28e54a8c96088766741d241 100644 --- a/src/util/rc.mli +++ b/src/util/rc.mli @@ -42,7 +42,7 @@ val bool : rc_value -> bool val string : rc_value -> string (** raise Failure "Rc.string" if not a string or an ident value *) -val from_file : string -> (string * (string * rc_value) list) list +val from_file : string -> (string list * (string * rc_value) list) list (** returns the records of the file [f] @raises Not_found is f does not exists @raises Failure "lexing" in case of incorrect syntax *) diff --git a/src/util/rc.mll b/src/util/rc.mll index 48fbbd44baaf8229d5b928b735a7ae61c95a5b8b..5bfeb54673af51b4b83c3fbd01ddbf1ec762f772 100644 --- a/src/util/rc.mll +++ b/src/util/rc.mll @@ -57,7 +57,7 @@ let string = function let buf = Buffer.create 17 -let current_rec = ref "" +let current_rec = ref [] let current_list = ref [] let current = ref [] @@ -67,7 +67,7 @@ let push_field key value = let push_record () = if !current_list <> [] then current := (!current_rec,List.rev !current_list) :: !current; - current_rec := ""; + current_rec := []; current_list := [] } @@ -85,11 +85,8 @@ let escape = ['\\''"''n''t''r'] rule record = parse | space { record lexbuf } - | '[' (ident as key) ']' - { push_record(); - current_rec := key; - record lexbuf - } + | '[' (ident as key) space* + { header [key] lexbuf } | eof { push_record () } | (ident as key) space* '=' space* @@ -97,6 +94,18 @@ rule record = parse | _ as c { failwith ("Rc: invalid keyval pair starting with " ^ String.make 1 c) } +and header keylist = parse + | (ident as key) space* + { header (key::keylist) lexbuf } + | ']' + { push_record (); + current_rec := List.rev keylist; + record lexbuf } + | eof + { failwith "Rc: unterminated header" } + | _ as c + { failwith ("Rc: invalid header starting with " ^ String.make 1 c) } + and value key = parse | integer as i { push_field key (RCint (int_of_string i)); @@ -116,10 +125,10 @@ and value key = parse | ident as id { push_field key (RCident (*kind_of_ident*) id); record lexbuf } - | _ as c - { failwith ("Rc: invalid value starting with " ^ String.make 1 c) } | eof { failwith "Rc: unterminated keyval pair" } + | _ as c + { failwith ("Rc: invalid value starting with " ^ String.make 1 c) } and string_val key = parse | '"' diff --git a/why.conf b/why.conf index 6979474d028d5c35af565c3bacb93786a955e31c..db9db103df69923827688886fe8f78b95480b20e 100644 --- a/why.conf +++ b/why.conf @@ -2,27 +2,23 @@ loadpath = "theories" timelimit = 10 -[prover] -name = alt-ergo -description = "Alt-Ergo" +[prover alt-ergo] +name = "Alt-Ergo" command = "alt-ergo %s" driver = "drivers/alt_ergo.drv" -[prover] -name = coq -description = "Coq" +[prover coq] +name = "Coq" command = "coqc %s" driver = "drivers/coq.drv" -[prover] -name = cvc3 -description = "CVC3" +[prover cvc3] +name = "CVC3" command = "cvc3 -lang smt" driver = "drivers/cvc3.drv" -[prover] -name = z3 -description = "Z3" +[prover z3] +name = "Z3" command = "z3 -smt -in" driver = "drivers/z3.drv"