ProgTutorial/Helper/Command/Command.thy
author Norbert Schirmer <norbert.schirmer@web.de>
Tue, 14 May 2019 17:10:47 +0200
changeset 565 cecd7a941885
parent 553 c53d74b34123
permissions -rw-r--r--
isabelle update_cartouches -t
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
319
6bce4acf7f2a added file for producing a keyword file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     1
theory Command
6bce4acf7f2a added file for producing a keyword file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     2
imports Main
514
7e25716c3744 updated to outer syntax / parser changes
Christian Urban <urbanc@in.tum.de>
parents: 451
diff changeset
     3
keywords "foobar" "foobar_trace" :: thy_decl and
7e25716c3744 updated to outer syntax / parser changes
Christian Urban <urbanc@in.tum.de>
parents: 451
diff changeset
     4
         "foobar_goal" "foobar_prove" :: thy_goal
319
6bce4acf7f2a added file for producing a keyword file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     5
begin
321
e450fa467e3f polished the commands section
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
     6
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 553
diff changeset
     7
ML \<open>
319
6bce4acf7f2a added file for producing a keyword file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     8
let
449
f952f2679a11 updated to new isabelle
Christian Urban <urbanc@in.tum.de>
parents: 426
diff changeset
     9
   val do_nothing = Scan.succeed (Local_Theory.background_theory I)
319
6bce4acf7f2a added file for producing a keyword file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    10
in
520
615762b8d8cb improved new_command section
Christian Urban <urbanc@in.tum.de>
parents: 514
diff changeset
    11
   Outer_Syntax.local_theory @{command_spec "foobar"} 
615762b8d8cb improved new_command section
Christian Urban <urbanc@in.tum.de>
parents: 514
diff changeset
    12
     "description of foobar" 
615762b8d8cb improved new_command section
Christian Urban <urbanc@in.tum.de>
parents: 514
diff changeset
    13
       do_nothing
319
6bce4acf7f2a added file for producing a keyword file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    14
end
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 553
diff changeset
    15
\<close>
319
6bce4acf7f2a added file for producing a keyword file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    16
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 553
diff changeset
    17
ML \<open>
319
6bce4acf7f2a added file for producing a keyword file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    18
let
321
e450fa467e3f polished the commands section
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
    19
  fun trace_prop str =
449
f952f2679a11 updated to new isabelle
Christian Urban <urbanc@in.tum.de>
parents: 426
diff changeset
    20
     Local_Theory.background_theory (fn lthy => (tracing str; lthy))
426
d94755882e36 updated to new Isabelle
Christian Urban <urbanc@in.tum.de>
parents: 422
diff changeset
    21
  val trace_prop_parser = Parse.prop >> trace_prop
321
e450fa467e3f polished the commands section
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
    22
in
520
615762b8d8cb improved new_command section
Christian Urban <urbanc@in.tum.de>
parents: 514
diff changeset
    23
  Outer_Syntax.local_theory @{command_spec "foobar_trace"} 
615762b8d8cb improved new_command section
Christian Urban <urbanc@in.tum.de>
parents: 514
diff changeset
    24
    "traces a proposition"
615762b8d8cb improved new_command section
Christian Urban <urbanc@in.tum.de>
parents: 514
diff changeset
    25
      trace_prop_parser
321
e450fa467e3f polished the commands section
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
    26
end
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 553
diff changeset
    27
\<close>
321
e450fa467e3f polished the commands section
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
    28
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 553
diff changeset
    29
ML \<open>
321
e450fa467e3f polished the commands section
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
    30
let
e450fa467e3f polished the commands section
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
    31
   fun prove_prop str lthy =
e450fa467e3f polished the commands section
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
    32
     let
e450fa467e3f polished the commands section
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
    33
       val prop = Syntax.read_prop lthy str
e450fa467e3f polished the commands section
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
    34
     in
422
e79563b14b0f updated to new Isabelle
Christian Urban <urbanc@in.tum.de>
parents: 394
diff changeset
    35
       Proof.theorem NONE (K I) [[(prop,[])]] lthy
321
e450fa467e3f polished the commands section
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
    36
     end;
426
d94755882e36 updated to new Isabelle
Christian Urban <urbanc@in.tum.de>
parents: 422
diff changeset
    37
   val prove_prop_parser = Parse.prop >> prove_prop
321
e450fa467e3f polished the commands section
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
    38
in
520
615762b8d8cb improved new_command section
Christian Urban <urbanc@in.tum.de>
parents: 514
diff changeset
    39
   Outer_Syntax.local_theory_to_proof @{command_spec "foobar_goal"} 
615762b8d8cb improved new_command section
Christian Urban <urbanc@in.tum.de>
parents: 514
diff changeset
    40
     "proving a proposition"
615762b8d8cb improved new_command section
Christian Urban <urbanc@in.tum.de>
parents: 514
diff changeset
    41
       prove_prop_parser
321
e450fa467e3f polished the commands section
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
    42
end
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 553
diff changeset
    43
\<close>
321
e450fa467e3f polished the commands section
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
    44
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 553
diff changeset
    45
ML \<open>
451
fc074e669f9f disabled foobar_prove; updated to new Isabelle
Christian Urban <urbanc@in.tum.de>
parents: 449
diff changeset
    46
structure Result = Proof_Data(
fc074e669f9f disabled foobar_prove; updated to new Isabelle
Christian Urban <urbanc@in.tum.de>
parents: 449
diff changeset
    47
  type T = unit -> term
fc074e669f9f disabled foobar_prove; updated to new Isabelle
Christian Urban <urbanc@in.tum.de>
parents: 449
diff changeset
    48
  fun init thy () = error "Result")
fc074e669f9f disabled foobar_prove; updated to new Isabelle
Christian Urban <urbanc@in.tum.de>
parents: 449
diff changeset
    49
fc074e669f9f disabled foobar_prove; updated to new Isabelle
Christian Urban <urbanc@in.tum.de>
parents: 449
diff changeset
    50
val result_cookie = (Result.get, Result.put, "Result.put")
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 553
diff changeset
    51
\<close>
451
fc074e669f9f disabled foobar_prove; updated to new Isabelle
Christian Urban <urbanc@in.tum.de>
parents: 449
diff changeset
    52
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 553
diff changeset
    53
ML\<open>
321
e450fa467e3f polished the commands section
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
    54
let
324
4172c0743cf2 updated foobar_proof example
Christian Urban <urbanc@in.tum.de>
parents: 321
diff changeset
    55
   fun after_qed thm_name thms lthy =
394
0019ebf76e10 updated to new Isabelle
Christian Urban <urbanc@in.tum.de>
parents: 328
diff changeset
    56
        Local_Theory.note (thm_name, (flat thms)) lthy |> snd
324
4172c0743cf2 updated foobar_proof example
Christian Urban <urbanc@in.tum.de>
parents: 321
diff changeset
    57
553
c53d74b34123 updated to changes in Isabelle
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 520
diff changeset
    58
   fun setup_proof (thm_name, {text, ...}) lthy =
321
e450fa467e3f polished the commands section
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
    59
   let
553
c53d74b34123 updated to changes in Isabelle
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 520
diff changeset
    60
     val trm = Code_Runtime.value lthy result_cookie ("", text)
321
e450fa467e3f polished the commands section
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
    61
   in
422
e79563b14b0f updated to new Isabelle
Christian Urban <urbanc@in.tum.de>
parents: 394
diff changeset
    62
     Proof.theorem NONE (after_qed thm_name) [[(trm,[])]] lthy
324
4172c0743cf2 updated foobar_proof example
Christian Urban <urbanc@in.tum.de>
parents: 321
diff changeset
    63
   end
321
e450fa467e3f polished the commands section
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
    64
426
d94755882e36 updated to new Isabelle
Christian Urban <urbanc@in.tum.de>
parents: 422
diff changeset
    65
   val parser = Parse_Spec.opt_thm_name ":" -- Parse.ML_source
324
4172c0743cf2 updated foobar_proof example
Christian Urban <urbanc@in.tum.de>
parents: 321
diff changeset
    66
 
321
e450fa467e3f polished the commands section
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
    67
in
520
615762b8d8cb improved new_command section
Christian Urban <urbanc@in.tum.de>
parents: 514
diff changeset
    68
   Outer_Syntax.local_theory_to_proof @{command_spec "foobar_prove"} 
615762b8d8cb improved new_command section
Christian Urban <urbanc@in.tum.de>
parents: 514
diff changeset
    69
     "proving a proposition" 
615762b8d8cb improved new_command section
Christian Urban <urbanc@in.tum.de>
parents: 514
diff changeset
    70
        (parser >> setup_proof)
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 553
diff changeset
    71
end\<close>
324
4172c0743cf2 updated foobar_proof example
Christian Urban <urbanc@in.tum.de>
parents: 321
diff changeset
    72
321
e450fa467e3f polished the commands section
Christian Urban <urbanc@in.tum.de>
parents: 319
diff changeset
    73
319
6bce4acf7f2a added file for producing a keyword file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    74
451
fc074e669f9f disabled foobar_prove; updated to new Isabelle
Christian Urban <urbanc@in.tum.de>
parents: 449
diff changeset
    75
319
6bce4acf7f2a added file for producing a keyword file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    76
end