src/HOL/Tools/Nitpick/nitpick_isar.ML
changeset 43020 abb5d1f907e4
parent 43018 121aa59b4d17
child 43022 7d3ce43d9464
equal deleted inserted replaced
43019:619f16bf2150 43020:abb5d1f907e4
     8 
     8 
     9 signature NITPICK_ISAR =
     9 signature NITPICK_ISAR =
    10 sig
    10 sig
    11   type params = Nitpick.params
    11   type params = Nitpick.params
    12 
    12 
       
    13   val nitpickN : string
       
    14   val nitpick_paramsN : string
    13   val auto : bool Unsynchronized.ref
    15   val auto : bool Unsynchronized.ref
    14   val default_params : theory -> (string * string) list -> params
    16   val default_params : theory -> (string * string) list -> params
    15   val setup : theory -> theory
    17   val setup : theory -> theory
    16 end;
    18 end;
    17 
    19 
    21 open Nitpick_Util
    23 open Nitpick_Util
    22 open Nitpick_HOL
    24 open Nitpick_HOL
    23 open Nitpick_Rep
    25 open Nitpick_Rep
    24 open Nitpick_Nut
    26 open Nitpick_Nut
    25 open Nitpick
    27 open Nitpick
       
    28 
       
    29 val nitpickN = "nitpick"
       
    30 val nitpick_paramsN = "nitpick_params"
    26 
    31 
    27 val auto = Unsynchronized.ref false
    32 val auto = Unsynchronized.ref false
    28 
    33 
    29 (* Maximum number of scopes for Auto Nitpick. Be frugal since it has to share
    34 (* Maximum number of scopes for Auto Nitpick. Be frugal since it has to share
    30    its time slot with several other automatic tools. *)
    35    its time slot with several other automatic tools. *)
   354     val ctxt = Proof.context_of state
   359     val ctxt = Proof.context_of state
   355     val _ = List.app check_raw_param override_params
   360     val _ = List.app check_raw_param override_params
   356     val params as {blocking, debug, ...} =
   361     val params as {blocking, debug, ...} =
   357       extract_params ctxt auto (default_raw_params thy) override_params
   362       extract_params ctxt auto (default_raw_params thy) override_params
   358     fun go () =
   363     fun go () =
   359       (false, state)
   364       (unknownN, state)
   360       |> (if auto then perhaps o try
   365       |> (if auto then perhaps o try
   361           else if debug then fn f => fn x => f x
   366           else if debug then fn f => fn x => f x
   362           else handle_exceptions ctxt)
   367           else handle_exceptions ctxt)
   363          (fn (_, state) => pick_nits_in_subgoal state params auto i step
   368          (fn (_, state) => pick_nits_in_subgoal state params auto i step)
   364                            |>> curry (op =) "genuine")
   369   in if blocking then go () else Future.fork (tap go) |> K (unknownN, state) end
   365   in if blocking then go () else Future.fork (tap go) |> K (false, state) end
   370   |> `(fn (outcome_code, _) => outcome_code = genuineN)
   366 
   371 
   367 fun nitpick_trans (params, i) =
   372 fun nitpick_trans (params, i) =
   368   Toplevel.keep (fn st =>
   373   Toplevel.keep (fn state =>
   369       (pick_nits params false i (Toplevel.proof_position_of st)
   374       pick_nits params false i (Toplevel.proof_position_of state)
   370                  (Toplevel.proof_of st); ()))
   375                 (Toplevel.proof_of state) |> K ())
   371 
   376 
   372 fun string_for_raw_param (name, value) =
   377 fun string_for_raw_param (name, value) =
   373   name ^ " = " ^ stringify_raw_param_value value
   378   name ^ " = " ^ stringify_raw_param_value value
   374 
   379 
   375 fun nitpick_params_trans params =
   380 fun nitpick_params_trans params =
   386 
   391 
   387 val parse_nitpick_command =
   392 val parse_nitpick_command =
   388   (parse_params -- Scan.optional Parse.nat 1) #>> nitpick_trans
   393   (parse_params -- Scan.optional Parse.nat 1) #>> nitpick_trans
   389 val parse_nitpick_params_command = parse_params #>> nitpick_params_trans
   394 val parse_nitpick_params_command = parse_params #>> nitpick_params_trans
   390 
   395 
   391 val _ = Outer_Syntax.improper_command "nitpick"
   396 val _ = Outer_Syntax.improper_command nitpickN
   392             "try to find a counterexample for a given subgoal using Nitpick"
   397             "try to find a counterexample for a given subgoal using Nitpick"
   393             Keyword.diag parse_nitpick_command
   398             Keyword.diag parse_nitpick_command
   394 val _ = Outer_Syntax.command "nitpick_params"
   399 val _ = Outer_Syntax.command nitpick_paramsN
   395             "set and display the default parameters for Nitpick"
   400             "set and display the default parameters for Nitpick"
   396             Keyword.thy_decl parse_nitpick_params_command
   401             Keyword.thy_decl parse_nitpick_params_command
   397 
   402 
   398 val auto_nitpick = pick_nits [] true 1 0
   403 fun try_nitpick auto = pick_nits [] auto 1 0
   399 
   404 
   400 val setup = Try.register_tool (auto, auto_nitpick)
   405 val setup = Try.register_tool (nitpickN, (auto, try_nitpick))
   401 
   406 
   402 end;
   407 end;