open Nitpick_Util open Nitpick_HOL open Nitpick_Rep open Nitpick_Nut open Nitpick
val nitpickN = "nitpick" val nitpick_paramsN = "nitpick_params"
(* Maximum number of scopes for Auto Nitpick. Be frugal since it has to share
its time slot with several other automatic tools. *) val auto_try_max_scopes = 6
fun is_known_raw_param s =
AList.defined (op =) default_default_params s orelse
AList.defined (op =) negated_params s orelse
member (op =) ["max", "show_all", "whack", "eval", "need", "atoms", "expect"] s orelse exists (fn p => String.isPrefix (p ^ " ") s)
["card", "max", "iter", "box", "dont_box", "finitize", "dont_finitize", "mono", "non_mono", "wf", "non_wf", "format", "atoms"]
fun check_raw_param (s, _) = if is_known_raw_param s then () else error ("Unknown parameter: " ^ quote s)
fun unnegate_param_name name = case AList.lookup (op =) negated_params name of
NONE => ifString.isPrefix "dont_" name then SOME (unprefix "dont_" name) elseifString.isPrefix "non_" name then SOME (unprefix "non_" name) else NONE
| some_name => some_name
fun normalize_raw_param (name, value) = case unnegate_param_name name of
SOME name' => [(name', case value of
["false"] => ["true"]
| ["true"] => ["false"]
| [] => ["false"]
| _ => value)]
| NONE => if name = "show_all"then
[("show_types", value), ("show_skolems", value),
("show_consts", value)] else
[(name, value)]
structure Data = Theory_Data
( type T = raw_param list val empty = default_default_params |> map (apsnd single) fun merge data = AList.merge (op =) (K true) data
)
val set_default_raw_param =
Data.map o fold (AList.update (op =)) o normalize_raw_param val default_raw_params = Data.get
fun handle_exceptions ctxt f x =
f x handle ARG (loc, details) =>
error ("Bad argument(s) to " ^ quote loc ^ ": " ^ details)
| BAD (loc, details) =>
error ("Internal error (" ^ quote loc ^ "): " ^ details)
| NOT_SUPPORTED details =>
(warning ("Unsupported case: " ^ details); x)
| NUT (loc, us) =>
error ("Invalid intermediate term" ^ plural_s_for_list us ^ " (" ^ quote loc ^ "): " ^
commas (map (string_for_nut ctxt) us))
| REP (loc, Rs) =>
error ("Invalid representation" ^ plural_s_for_list Rs ^ " (" ^ quote loc ^ "): " ^ commas (map string_for_rep Rs))
| TERM (loc, ts) =>
error ("Invalid term" ^ plural_s_for_list ts ^ " (" ^ quote loc ^ "): " ^
commas (map (Syntax.string_of_term ctxt) ts))
| TYPE (loc, Ts, ts) =>
error ("Invalid type" ^ plural_s_for_list Ts ^
(if null ts then "" else " for term" ^ plural_s_for_list ts ^ " " ^
commas (map (quote o Syntax.string_of_term ctxt) ts)) ^ " (" ^ quote loc ^ "): " ^
commas (map (Syntax.string_of_typ ctxt) Ts))
fun pick_nits override_params mode i step state = let val thy = Proof.theory_of state val ctxt = Proof.context_of state val _ = List.app check_raw_param override_params val params as {debug, ...} =
extract_params ctxt mode (default_raw_params thy) override_params fun go () =
(unknownN, [])
|> (if mode = Auto_Try then perhaps o try elseif debug then fn f => fn x => f x else handle_exceptions ctxt)
(fn _ => pick_nits_in_subgoal state params mode i step) in go () end
|> `(fn (outcome_code, _) => outcome_code = genuineN)
fun string_for_raw_param (name, value) =
name ^ " = " ^ stringify_raw_param_value value
val _ =
Outer_Syntax.command \<^command_keyword>\<open>nitpick\<close> "try to find a counterexample for a given subgoal using Nitpick"
(parse_params -- Scan.optional Parse.nat 1 >> (fn (params, i) =>
Toplevel.keep_proof (fn state =>
ignore (pick_nits params Normal i (Toplevel.proof_position_of state)
(Toplevel.proof_of state)))))
val _ =
Outer_Syntax.command \<^command_keyword>\<open>nitpick_params\<close> "set and display the default parameters for Nitpick"
(parse_params #>> nitpick_params_trans)
val _ = Try.tool_setup
{name = nitpickN, weight = 50, auto_option = \<^system_option>\<open>auto_nitpick\<close>,
body = fn auto => pick_nits [] (if auto then Auto_Try elseTry) 1 0}
end;
¤ Dauer der Verarbeitung: 0.16 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.