ProgTutorial/Base.thy
author Christian Urban <urbanc@in.tum.de>
Sat, 03 Oct 2009 13:01:39 +0200
changeset 328 c0cae24b9d46
parent 317 d69214e47ef9
child 346 0fea8b7a14a1
permissions -rw-r--r--
updated to new Isabelle; more work on the data section
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
23
1322990e4ee7 New theory for installing antiquotations.
berghofe
parents:
diff changeset
     1
theory Base
264
311830b43f8f minor tuning
Christian Urban <urbanc@in.tum.de>
parents: 260
diff changeset
     2
imports Main LaTeXsugar
23
1322990e4ee7 New theory for installing antiquotations.
berghofe
parents:
diff changeset
     3
uses
256
1fb8d62c88a0 added some first index-information
Christian Urban <urbanc@in.tum.de>
parents: 255
diff changeset
     4
  "output_tutorial.ML"
23
1322990e4ee7 New theory for installing antiquotations.
berghofe
parents:
diff changeset
     5
  "antiquote_setup.ML"
1322990e4ee7 New theory for installing antiquotations.
berghofe
parents:
diff changeset
     6
begin
1322990e4ee7 New theory for installing antiquotations.
berghofe
parents:
diff changeset
     7
317
d69214e47ef9 added an experimental antiquotation to replace eventually ML_response_fake
Christian Urban <urbanc@in.tum.de>
parents: 316
diff changeset
     8
(* rebinding of writeln and tracing so that it can *)
d69214e47ef9 added an experimental antiquotation to replace eventually ML_response_fake
Christian Urban <urbanc@in.tum.de>
parents: 316
diff changeset
     9
(* be compared in intiquotations                   *)
d69214e47ef9 added an experimental antiquotation to replace eventually ML_response_fake
Christian Urban <urbanc@in.tum.de>
parents: 316
diff changeset
    10
ML {* 
d69214e47ef9 added an experimental antiquotation to replace eventually ML_response_fake
Christian Urban <urbanc@in.tum.de>
parents: 316
diff changeset
    11
fun writeln s = (Output.writeln s; s)
d69214e47ef9 added an experimental antiquotation to replace eventually ML_response_fake
Christian Urban <urbanc@in.tum.de>
parents: 316
diff changeset
    12
fun tracing s = (Output.tracing s; s)
d69214e47ef9 added an experimental antiquotation to replace eventually ML_response_fake
Christian Urban <urbanc@in.tum.de>
parents: 316
diff changeset
    13
*}
d69214e47ef9 added an experimental antiquotation to replace eventually ML_response_fake
Christian Urban <urbanc@in.tum.de>
parents: 316
diff changeset
    14
302
Christian Urban <urbanc@in.tum.de>
parents: 301
diff changeset
    15
(* re-definition of various ML antiquotations    *)
64
9a6e5e0c4906 deleted old files and added code to give a special tag to the command ML
Christian Urban <urbanc@in.tum.de>
parents: 57
diff changeset
    16
(* to have a special tag for text enclosed in ML *)
301
2728e8daebc0 replaced "writeln" with "tracing"
Christian Urban <urbanc@in.tum.de>
parents: 264
diff changeset
    17
64
9a6e5e0c4906 deleted old files and added code to give a special tag to the command ML
Christian Urban <urbanc@in.tum.de>
parents: 57
diff changeset
    18
ML {*
310
007922777ff1 added some rudimentary inrastructure for producing the ML-code
Christian Urban <urbanc@in.tum.de>
parents: 302
diff changeset
    19
(* FIXME ref *)
328
c0cae24b9d46 updated to new Isabelle; more work on the data section
Christian Urban <urbanc@in.tum.de>
parents: 317
diff changeset
    20
val file_name = Unsynchronized.ref (NONE : string option)
310
007922777ff1 added some rudimentary inrastructure for producing the ML-code
Christian Urban <urbanc@in.tum.de>
parents: 302
diff changeset
    21
007922777ff1 added some rudimentary inrastructure for producing the ML-code
Christian Urban <urbanc@in.tum.de>
parents: 302
diff changeset
    22
fun write_file txt =
007922777ff1 added some rudimentary inrastructure for producing the ML-code
Christian Urban <urbanc@in.tum.de>
parents: 302
diff changeset
    23
  case !file_name of
007922777ff1 added some rudimentary inrastructure for producing the ML-code
Christian Urban <urbanc@in.tum.de>
parents: 302
diff changeset
    24
    NONE => () (* error "No open file" *)
007922777ff1 added some rudimentary inrastructure for producing the ML-code
Christian Urban <urbanc@in.tum.de>
parents: 302
diff changeset
    25
  | SOME name => 
007922777ff1 added some rudimentary inrastructure for producing the ML-code
Christian Urban <urbanc@in.tum.de>
parents: 302
diff changeset
    26
      (let 
007922777ff1 added some rudimentary inrastructure for producing the ML-code
Christian Urban <urbanc@in.tum.de>
parents: 302
diff changeset
    27
         val stream = TextIO.openAppend name
007922777ff1 added some rudimentary inrastructure for producing the ML-code
Christian Urban <urbanc@in.tum.de>
parents: 302
diff changeset
    28
       in
007922777ff1 added some rudimentary inrastructure for producing the ML-code
Christian Urban <urbanc@in.tum.de>
parents: 302
diff changeset
    29
         TextIO.output (stream, txt); 
311
ee864694315b polished
Christian Urban <urbanc@in.tum.de>
parents: 310
diff changeset
    30
         TextIO.flushOut stream;                (* needed ?*)
310
007922777ff1 added some rudimentary inrastructure for producing the ML-code
Christian Urban <urbanc@in.tum.de>
parents: 302
diff changeset
    31
         TextIO.closeOut stream
007922777ff1 added some rudimentary inrastructure for producing the ML-code
Christian Urban <urbanc@in.tum.de>
parents: 302
diff changeset
    32
       end)
007922777ff1 added some rudimentary inrastructure for producing the ML-code
Christian Urban <urbanc@in.tum.de>
parents: 302
diff changeset
    33
*}
007922777ff1 added some rudimentary inrastructure for producing the ML-code
Christian Urban <urbanc@in.tum.de>
parents: 302
diff changeset
    34
007922777ff1 added some rudimentary inrastructure for producing the ML-code
Christian Urban <urbanc@in.tum.de>
parents: 302
diff changeset
    35
ML {*
007922777ff1 added some rudimentary inrastructure for producing the ML-code
Christian Urban <urbanc@in.tum.de>
parents: 302
diff changeset
    36
fun write_file_blk txt =
007922777ff1 added some rudimentary inrastructure for producing the ML-code
Christian Urban <urbanc@in.tum.de>
parents: 302
diff changeset
    37
let
007922777ff1 added some rudimentary inrastructure for producing the ML-code
Christian Urban <urbanc@in.tum.de>
parents: 302
diff changeset
    38
  val pre  = implode ["\n", "ML ", "{", "*", "\n"]
007922777ff1 added some rudimentary inrastructure for producing the ML-code
Christian Urban <urbanc@in.tum.de>
parents: 302
diff changeset
    39
  val post = implode ["\n", "*", "}", "\n"]
007922777ff1 added some rudimentary inrastructure for producing the ML-code
Christian Urban <urbanc@in.tum.de>
parents: 302
diff changeset
    40
in
007922777ff1 added some rudimentary inrastructure for producing the ML-code
Christian Urban <urbanc@in.tum.de>
parents: 302
diff changeset
    41
  write_file (enclose pre post txt)
007922777ff1 added some rudimentary inrastructure for producing the ML-code
Christian Urban <urbanc@in.tum.de>
parents: 302
diff changeset
    42
end
007922777ff1 added some rudimentary inrastructure for producing the ML-code
Christian Urban <urbanc@in.tum.de>
parents: 302
diff changeset
    43
*}
007922777ff1 added some rudimentary inrastructure for producing the ML-code
Christian Urban <urbanc@in.tum.de>
parents: 302
diff changeset
    44
007922777ff1 added some rudimentary inrastructure for producing the ML-code
Christian Urban <urbanc@in.tum.de>
parents: 302
diff changeset
    45
ML {*
007922777ff1 added some rudimentary inrastructure for producing the ML-code
Christian Urban <urbanc@in.tum.de>
parents: 302
diff changeset
    46
fun open_file name =
007922777ff1 added some rudimentary inrastructure for producing the ML-code
Christian Urban <urbanc@in.tum.de>
parents: 302
diff changeset
    47
  (tracing ("Opened File: " ^ name);
315
de49d5780f57 simplified a bit the index generation
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
    48
   file_name := SOME name;
de49d5780f57 simplified a bit the index generation
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
    49
   TextIO.openOut name; ())
310
007922777ff1 added some rudimentary inrastructure for producing the ML-code
Christian Urban <urbanc@in.tum.de>
parents: 302
diff changeset
    50
007922777ff1 added some rudimentary inrastructure for producing the ML-code
Christian Urban <urbanc@in.tum.de>
parents: 302
diff changeset
    51
fun open_file_prelude name txt =
007922777ff1 added some rudimentary inrastructure for producing the ML-code
Christian Urban <urbanc@in.tum.de>
parents: 302
diff changeset
    52
  (open_file name; write_file (txt ^ "\n"))
007922777ff1 added some rudimentary inrastructure for producing the ML-code
Christian Urban <urbanc@in.tum.de>
parents: 302
diff changeset
    53
*}
007922777ff1 added some rudimentary inrastructure for producing the ML-code
Christian Urban <urbanc@in.tum.de>
parents: 302
diff changeset
    54
007922777ff1 added some rudimentary inrastructure for producing the ML-code
Christian Urban <urbanc@in.tum.de>
parents: 302
diff changeset
    55
ML {*
64
9a6e5e0c4906 deleted old files and added code to give a special tag to the command ML
Christian Urban <urbanc@in.tum.de>
parents: 57
diff changeset
    56
260
5accec94b6df updated to lates Isabelle changes
Christian Urban <urbanc@in.tum.de>
parents: 256
diff changeset
    57
fun propagate_env (context as Context.Proof lthy) =
5accec94b6df updated to lates Isabelle changes
Christian Urban <urbanc@in.tum.de>
parents: 256
diff changeset
    58
      Context.Proof (LocalTheory.map_contexts (ML_Env.inherit context) lthy)
264
311830b43f8f minor tuning
Christian Urban <urbanc@in.tum.de>
parents: 260
diff changeset
    59
  | propagate_env context = context
210
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 189
diff changeset
    60
260
5accec94b6df updated to lates Isabelle changes
Christian Urban <urbanc@in.tum.de>
parents: 256
diff changeset
    61
fun propagate_env_prf prf = Proof.map_contexts
264
311830b43f8f minor tuning
Christian Urban <urbanc@in.tum.de>
parents: 260
diff changeset
    62
  (Context.proof_map (ML_Env.inherit (Context.Proof (Proof.context_of prf)))) prf
210
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 189
diff changeset
    63
64
9a6e5e0c4906 deleted old files and added code to give a special tag to the command ML
Christian Urban <urbanc@in.tum.de>
parents: 57
diff changeset
    64
val _ =
9a6e5e0c4906 deleted old files and added code to give a special tag to the command ML
Christian Urban <urbanc@in.tum.de>
parents: 57
diff changeset
    65
  OuterSyntax.command "ML" "eval ML text within theory"
106
bdd82350cf22 renamed in the pdf all instances of cookbook to tutorial (in order to sound more serious)
Christian Urban <urbanc@in.tum.de>
parents: 80
diff changeset
    66
    (OuterKeyword.tag "TutorialML" OuterKeyword.thy_decl)
310
007922777ff1 added some rudimentary inrastructure for producing the ML-code
Christian Urban <urbanc@in.tum.de>
parents: 302
diff changeset
    67
    (OuterParse.position OuterParse.text >> (fn (txt, pos) =>
210
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 189
diff changeset
    68
      Toplevel.generic_theory
310
007922777ff1 added some rudimentary inrastructure for producing the ML-code
Christian Urban <urbanc@in.tum.de>
parents: 302
diff changeset
    69
        (ML_Context.exec (fn () => (write_file_blk txt; ML_Context.eval true pos txt)) #> propagate_env)))
210
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 189
diff changeset
    70
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 189
diff changeset
    71
val _ =
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 189
diff changeset
    72
  OuterSyntax.command "ML_prf" "ML text within proof" 
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 189
diff changeset
    73
    (OuterKeyword.tag "TutorialML" OuterKeyword.prf_decl)
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 189
diff changeset
    74
    (OuterParse.ML_source >> (fn (txt, pos) =>
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 189
diff changeset
    75
      Toplevel.proof (Proof.map_context (Context.proof_map
260
5accec94b6df updated to lates Isabelle changes
Christian Urban <urbanc@in.tum.de>
parents: 256
diff changeset
    76
        (ML_Context.exec (fn () => ML_Context.eval true pos txt))) #> propagate_env_prf)))
210
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 189
diff changeset
    77
224
647cab4a72c2 finished the heavy duty stuff for the inductive package
Christian Urban <urbanc@in.tum.de>
parents: 210
diff changeset
    78
val _ =
647cab4a72c2 finished the heavy duty stuff for the inductive package
Christian Urban <urbanc@in.tum.de>
parents: 210
diff changeset
    79
  OuterSyntax.command "ML_val" "diagnostic ML text" 
647cab4a72c2 finished the heavy duty stuff for the inductive package
Christian Urban <urbanc@in.tum.de>
parents: 210
diff changeset
    80
  (OuterKeyword.tag "TutorialML" OuterKeyword.diag)
264
311830b43f8f minor tuning
Christian Urban <urbanc@in.tum.de>
parents: 260
diff changeset
    81
    (OuterParse.ML_source >> IsarCmd.ml_diag true)
224
647cab4a72c2 finished the heavy duty stuff for the inductive package
Christian Urban <urbanc@in.tum.de>
parents: 210
diff changeset
    82
64
9a6e5e0c4906 deleted old files and added code to give a special tag to the command ML
Christian Urban <urbanc@in.tum.de>
parents: 57
diff changeset
    83
*}
239
b63c72776f03 replaced "warning" with "writeln"
Christian Urban <urbanc@in.tum.de>
parents: 224
diff changeset
    84
b63c72776f03 replaced "warning" with "writeln"
Christian Urban <urbanc@in.tum.de>
parents: 224
diff changeset
    85
end