Commit f5de29ab authored by Andrei Paskevich's avatar Andrei Paskevich

a little enhancement in Rc to make config syntax prettier

parent 642c12d4
...@@ -24,6 +24,8 @@ open Util ...@@ -24,6 +24,8 @@ open Util
type error = type error =
| SyntaxError | SyntaxError
| ExtraParameters of string
| MissingParameters of string
| UnknownSection of string | UnknownSection of string
| UnknownField of string | UnknownField of string
| MissingSection of string | MissingSection of string
...@@ -51,6 +53,10 @@ let print_rc_value fmt = function ...@@ -51,6 +53,10 @@ let print_rc_value fmt = function
let report fmt = function let report fmt = function
| SyntaxError -> | SyntaxError ->
fprintf fmt "syntax error" 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 -> | UnknownSection s ->
fprintf fmt "unknown section '%s'" s fprintf fmt "unknown section '%s'" s
| UnknownField s -> | UnknownField s ->
...@@ -79,9 +85,9 @@ let report fmt = function ...@@ -79,9 +85,9 @@ let report fmt = function
(* Configuration file *) (* Configuration file *)
type config_prover = { type config_prover = {
description : string; (* "Alt-Ergo v2.95 (special)" *) name : string; (* "Alt-Ergo v2.95 (special)" *)
command : string; (* "exec why-limit %t %m alt-ergo %f" *) command : string; (* "exec why-limit %t %m alt-ergo %f" *)
driver_file : string; (* "/usr/local/share/why/drivers/ergo-spec.drv" *) driver : string; (* "/usr/local/share/why/drivers/ergo-spec.drv" *)
} }
type config = { type config = {
...@@ -120,27 +126,20 @@ let get_field f = function ...@@ -120,27 +126,20 @@ let get_field f = function
| None -> error (MissingField f) | None -> error (MissingField f)
| Some v -> v | Some v -> v
let load_prover provers al = let load_prover al =
let nam = ref None in let nam = ref None in
let dsc = ref None in
let cmd = ref None in let cmd = ref None in
let drv = ref None in let drv = ref None in
let load (key, value) = match key with let load (key, value) = match key with
| "name" -> set_ident key nam value | "name" -> set_string key nam value
| "description" -> set_string key dsc value
| "command" -> set_string key cmd value | "command" -> set_string key cmd value
| "driver" -> set_string key drv value | "driver" -> set_string key drv value
| _ -> error (UnknownField key) | _ -> error (UnknownField key)
in in
List.iter load al; List.iter load al;
let prover = { { name = get_field "name" !nam;
description = get_field "description" !dsc; command = get_field "command" !cmd;
command = get_field "command" !cmd; driver = get_field "driver" !drv }
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
let load_main main al = let load_main main al =
let lp = ref [] in let lp = ref [] in
...@@ -181,10 +180,17 @@ let read_config ?conf_file () = ...@@ -181,10 +180,17 @@ let read_config ?conf_file () =
let provers = ref Mstr.empty in let provers = ref Mstr.empty in
let have_main = ref false in let have_main = ref false in
let load (key, al) = match key with let load (key, al) = match key with
| "main" when !have_main -> error (DuplicateSection key) | "main" :: rest ->
| "main" -> main := load_main !main al if rest <> [] then error (ExtraParameters "main");
| "prover" -> provers := load_prover !provers al if !have_main then error (DuplicateSection "main");
| _ -> error (UnknownSection key) 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 in
List.iter load rc; List.iter load rc;
{ !main with provers = !provers } { !main with provers = !provers }
...@@ -198,11 +204,10 @@ let save_config config = ...@@ -198,11 +204,10 @@ let save_config config =
Util.option_iter (fprintf fmt "memlimit = %d@\n") config.memlimit; Util.option_iter (fprintf fmt "memlimit = %d@\n") config.memlimit;
fprintf fmt "@."; fprintf fmt "@.";
let print_prover name prover = let print_prover name prover =
fprintf fmt "[prover]@\n"; fprintf fmt "[prover %s]@\n" name;
fprintf fmt "name = %s@\n" name; fprintf fmt "name = \"%s\"@\n" prover.name;
fprintf fmt "description = \"%s\"@\n" prover.description;
fprintf fmt "command = \"%s\"@\n" prover.command; fprintf fmt "command = \"%s\"@\n" prover.command;
fprintf fmt "driver = \"%s\"@\n@." prover.driver_file; fprintf fmt "driver = \"%s\"@\n@." prover.driver;
in in
Mstr.iter print_prover config.provers; Mstr.iter print_prover config.provers;
close_out ch close_out ch
......
...@@ -20,9 +20,9 @@ ...@@ -20,9 +20,9 @@
open Util open Util
type config_prover = { type config_prover = {
description : string; (* "Alt-Ergo v2.95 (special)" *) name : string; (* "Alt-Ergo v2.95 (special)" *)
command : string; (* "exec why-limit %t %m alt-ergo %f" *) command : string; (* "exec why-limit %t %m alt-ergo %f" *)
driver_file : string; (* "/usr/local/share/why/drivers/ergo-spec.drv" *) driver : string; (* "/usr/local/share/why/drivers/ergo-spec.drv" *)
} }
type config = { type config = {
......
...@@ -5,24 +5,24 @@ open Whyconf ...@@ -5,24 +5,24 @@ open Whyconf
let autodetection () = let autodetection () =
let alt_ergo = { let alt_ergo = {
description = "Alt-Ergo"; name = "Alt-Ergo";
command = "alt-ergo %s"; command = "alt-ergo %s";
driver_file = "drivers/alt_ergo.drv" } driver = "drivers/alt_ergo.drv" }
in in
let z3 = { let z3 = {
description = "Z3"; name = "Z3";
command = "z3 -smt -in"; command = "z3 -smt -in";
driver_file = "drivers/z3.drv" } driver = "drivers/z3.drv" }
in in
let cvc3 = { let cvc3 = {
description = "CVC3"; name = "CVC3";
command = "cvc3 -lang smt"; command = "cvc3 -lang smt";
driver_file = "drivers/cvc3.drv" } driver = "drivers/cvc3.drv" }
in in
let coq = { let coq = {
description = "Coq"; name = "Coq";
command = "coqc %s"; command = "coqc %s";
driver_file = "drivers/coq.drv" } driver = "drivers/coq.drv" }
in in
let provers = Util.Mstr.empty in let provers = Util.Mstr.empty in
let provers = Util.Mstr.add "alt-ergo" alt_ergo provers in let provers = Util.Mstr.add "alt-ergo" alt_ergo provers in
......
...@@ -42,7 +42,7 @@ val bool : rc_value -> bool ...@@ -42,7 +42,7 @@ val bool : rc_value -> bool
val string : rc_value -> string val string : rc_value -> string
(** raise Failure "Rc.string" if not a string or an ident value *) (** 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] (** returns the records of the file [f]
@raises Not_found is f does not exists @raises Not_found is f does not exists
@raises Failure "lexing" in case of incorrect syntax *) @raises Failure "lexing" in case of incorrect syntax *)
......
...@@ -57,7 +57,7 @@ let string = function ...@@ -57,7 +57,7 @@ let string = function
let buf = Buffer.create 17 let buf = Buffer.create 17
let current_rec = ref "" let current_rec = ref []
let current_list = ref [] let current_list = ref []
let current = ref [] let current = ref []
...@@ -67,7 +67,7 @@ let push_field key value = ...@@ -67,7 +67,7 @@ let push_field key value =
let push_record () = let push_record () =
if !current_list <> [] then if !current_list <> [] then
current := (!current_rec,List.rev !current_list) :: !current; current := (!current_rec,List.rev !current_list) :: !current;
current_rec := ""; current_rec := [];
current_list := [] current_list := []
} }
...@@ -85,11 +85,8 @@ let escape = ['\\''"''n''t''r'] ...@@ -85,11 +85,8 @@ let escape = ['\\''"''n''t''r']
rule record = parse rule record = parse
| space | space
{ record lexbuf } { record lexbuf }
| '[' (ident as key) ']' | '[' (ident as key) space*
{ push_record(); { header [key] lexbuf }
current_rec := key;
record lexbuf
}
| eof | eof
{ push_record () } { push_record () }
| (ident as key) space* '=' space* | (ident as key) space* '=' space*
...@@ -97,6 +94,18 @@ rule record = parse ...@@ -97,6 +94,18 @@ rule record = parse
| _ as c | _ as c
{ failwith ("Rc: invalid keyval pair starting with " ^ String.make 1 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 and value key = parse
| integer as i | integer as i
{ push_field key (RCint (int_of_string i)); { push_field key (RCint (int_of_string i));
...@@ -116,10 +125,10 @@ and value key = parse ...@@ -116,10 +125,10 @@ and value key = parse
| ident as id | ident as id
{ push_field key (RCident (*kind_of_ident*) id); { push_field key (RCident (*kind_of_ident*) id);
record lexbuf } record lexbuf }
| _ as c
{ failwith ("Rc: invalid value starting with " ^ String.make 1 c) }
| eof | eof
{ failwith "Rc: unterminated keyval pair" } { failwith "Rc: unterminated keyval pair" }
| _ as c
{ failwith ("Rc: invalid value starting with " ^ String.make 1 c) }
and string_val key = parse and string_val key = parse
| '"' | '"'
......
...@@ -2,27 +2,23 @@ ...@@ -2,27 +2,23 @@
loadpath = "theories" loadpath = "theories"
timelimit = 10 timelimit = 10
[prover] [prover alt-ergo]
name = alt-ergo name = "Alt-Ergo"
description = "Alt-Ergo"
command = "alt-ergo %s" command = "alt-ergo %s"
driver = "drivers/alt_ergo.drv" driver = "drivers/alt_ergo.drv"
[prover] [prover coq]
name = coq name = "Coq"
description = "Coq"
command = "coqc %s" command = "coqc %s"
driver = "drivers/coq.drv" driver = "drivers/coq.drv"
[prover] [prover cvc3]
name = cvc3 name = "CVC3"
description = "CVC3"
command = "cvc3 -lang smt" command = "cvc3 -lang smt"
driver = "drivers/cvc3.drv" driver = "drivers/cvc3.drv"
[prover] [prover z3]
name = z3 name = "Z3"
description = "Z3"
command = "z3 -smt -in" command = "z3 -smt -in"
driver = "drivers/z3.drv" driver = "drivers/z3.drv"
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment