src/HOL/Import/proof_kernel.ML
author wenzelm
Mon, 16 Mar 2009 18:24:30 +0100
changeset 30549 d2d7874648bd
parent 30447 955190fa639b
child 31723 f5cafe803b55
permissions -rw-r--r--
simplified method setup;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
14620
1be590fd2422 Minor cleanup of headers and some speedup of the HOL4 import.
skalberg
parents: 14518
diff changeset
     1
(*  Title:      HOL/Import/proof_kernel.ML
29265
5b4247055bd7 moved old add_term_vars, add_term_frees etc. to structure OldTerm;
wenzelm
parents: 28965
diff changeset
     2
    Author:     Sebastian Skalberg and Steven Obua, TU Muenchen
14620
1be590fd2422 Minor cleanup of headers and some speedup of the HOL4 import.
skalberg
parents: 14518
diff changeset
     3
*)
1be590fd2422 Minor cleanup of headers and some speedup of the HOL4 import.
skalberg
parents: 14518
diff changeset
     4
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
     5
signature ProofKernel =
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
     6
sig
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
     7
    type hol_type
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
     8
    type tag
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
     9
    type term
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
    10
    type thm
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
    11
    type ('a,'b) subst
24707
dfeb98f84e93 Syntax.parse/check/read;
wenzelm
parents: 24634
diff changeset
    12
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
    13
    type proof_info
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
    14
    datatype proof = Proof of proof_info * proof_content
26626
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
    15
         and proof_content
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
    16
           = PRefl of term
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
    17
           | PInstT of proof * (hol_type,hol_type) subst
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
    18
           | PSubst of proof list * term * proof
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
    19
           | PAbs of proof * term
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
    20
           | PDisch of proof * term
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
    21
           | PMp of proof * proof
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
    22
           | PHyp of term
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
    23
           | PAxm of string * term
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
    24
           | PDef of string * string * term
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
    25
           | PTmSpec of string * string list * proof
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
    26
           | PTyDef of string * string * proof
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
    27
           | PTyIntro of string * string * string * string * term * term * proof
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
    28
           | POracle of tag * term list * term
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
    29
           | PDisk
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
    30
           | PSpec of proof * term
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
    31
           | PInst of proof * (term,term) subst
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
    32
           | PGen of proof * term
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
    33
           | PGenAbs of proof * term option * term list
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
    34
           | PImpAS of proof * proof
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
    35
           | PSym of proof
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
    36
           | PTrans of proof * proof
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
    37
           | PComb of proof * proof
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
    38
           | PEqMp of proof * proof
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
    39
           | PEqImp of proof
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
    40
           | PExists of proof * term * term
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
    41
           | PChoose of term * proof * proof
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
    42
           | PConj of proof * proof
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
    43
           | PConjunct1 of proof
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
    44
           | PConjunct2 of proof
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
    45
           | PDisj1 of proof * term
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
    46
           | PDisj2 of proof * term
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
    47
           | PDisjCases of proof * proof * proof
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
    48
           | PNotI of proof
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
    49
           | PNotE of proof
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
    50
           | PContr of proof * term
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
    51
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
    52
    exception PK of string * string
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
    53
14620
1be590fd2422 Minor cleanup of headers and some speedup of the HOL4 import.
skalberg
parents: 14518
diff changeset
    54
    val get_proof_dir: string -> theory -> string option
17657
2f5f595eb618 moved disambiguate_frees to ProofKernel;
wenzelm
parents: 17652
diff changeset
    55
    val disambiguate_frees : Thm.thm -> Thm.thm
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
    56
    val debug : bool ref
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
    57
    val disk_info_of : proof -> (string * string) option
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
    58
    val set_disk_info_of : proof -> string -> string -> unit
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
    59
    val mk_proof : proof_content -> proof
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
    60
    val content_of : proof -> proof_content
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
    61
    val import_proof : string -> string -> theory -> (theory -> term) option * (theory -> proof)
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
    62
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
    63
    val rewrite_hol4_term: Term.term -> theory -> Thm.thm
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
    64
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
    65
    val type_of : term -> hol_type
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
    66
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
    67
    val get_thm  : string -> string         -> theory -> (theory * thm option)
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
    68
    val get_def  : string -> string -> term -> theory -> (theory * thm option)
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
    69
    val get_axiom: string -> string         -> theory -> (theory * thm option)
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
    70
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
    71
    val store_thm : string -> string -> thm -> theory -> theory * thm
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
    72
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
    73
    val to_isa_thm : thm -> (term * term) list * Thm.thm
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
    74
    val to_isa_term: term -> Term.term
19064
bf19cc5a7899 fixed bugs, added caching
obua
parents: 18929
diff changeset
    75
    val to_hol_thm : Thm.thm -> thm
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
    76
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
    77
    val REFL : term -> theory -> theory * thm
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
    78
    val ASSUME : term -> theory -> theory * thm
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
    79
    val INST_TYPE : (hol_type,hol_type) subst -> thm -> theory -> theory * thm
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
    80
    val INST : (term,term)subst -> thm -> theory -> theory * thm
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
    81
    val EQ_MP : thm -> thm -> theory -> theory * thm
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
    82
    val EQ_IMP_RULE : thm -> theory -> theory * thm
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
    83
    val SUBST : thm list -> term -> thm -> theory -> theory * thm
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
    84
    val DISJ_CASES : thm -> thm -> thm -> theory -> theory * thm
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
    85
    val DISJ1: thm -> term -> theory -> theory * thm
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
    86
    val DISJ2: term -> thm -> theory -> theory * thm
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
    87
    val IMP_ANTISYM: thm -> thm -> theory -> theory * thm
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
    88
    val SYM : thm -> theory -> theory * thm
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
    89
    val MP : thm -> thm -> theory -> theory * thm
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
    90
    val GEN : term -> thm -> theory -> theory * thm
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
    91
    val CHOOSE : term -> thm -> thm -> theory -> theory * thm
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
    92
    val EXISTS : term -> term -> thm -> theory -> theory * thm
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
    93
    val ABS : term -> thm -> theory -> theory * thm
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
    94
    val GEN_ABS : term option -> term list -> thm -> theory -> theory * thm
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
    95
    val TRANS : thm -> thm -> theory -> theory * thm
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
    96
    val CCONTR : term -> thm -> theory -> theory * thm
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
    97
    val CONJ : thm -> thm -> theory -> theory * thm
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
    98
    val CONJUNCT1: thm -> theory -> theory * thm
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
    99
    val CONJUNCT2: thm -> theory -> theory * thm
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   100
    val NOT_INTRO: thm -> theory -> theory * thm
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   101
    val NOT_ELIM : thm -> theory -> theory * thm
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   102
    val SPEC : term -> thm -> theory -> theory * thm
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   103
    val COMB : thm -> thm -> theory -> theory * thm
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   104
    val DISCH: term -> thm -> theory -> theory * thm
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   105
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   106
    val type_introduction: string -> string -> string -> string -> string -> term * term -> thm -> theory -> theory * thm
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   107
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   108
    val new_definition : string -> string -> term -> theory -> theory * thm
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   109
    val new_specification : string -> string -> string list -> thm -> theory -> theory * thm
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   110
    val new_type_definition : string -> string -> string -> thm -> theory -> theory * thm
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   111
    val new_axiom : string -> term -> theory -> theory * thm
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   112
24707
dfeb98f84e93 Syntax.parse/check/read;
wenzelm
parents: 24634
diff changeset
   113
    val prin : term -> unit
dfeb98f84e93 Syntax.parse/check/read;
wenzelm
parents: 24634
diff changeset
   114
    val protect_factname : string -> string
19067
c0321d7d6b3d variable counter is now also cached
obua
parents: 19066
diff changeset
   115
    val replay_protect_varname : string -> string -> unit
19068
04b302f2902d cache improvements
obua
parents: 19067
diff changeset
   116
    val replay_add_dump : string -> theory -> theory
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   117
end
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   118
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   119
structure ProofKernel :> ProofKernel =
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   120
struct
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   121
type hol_type = Term.typ
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   122
type term = Term.term
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   123
datatype tag = Tag of string list
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   124
type ('a,'b) subst = ('a * 'b) list
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   125
datatype thm = HOLThm of (Term.term * Term.term) list * Thm.thm
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   126
24707
dfeb98f84e93 Syntax.parse/check/read;
wenzelm
parents: 24634
diff changeset
   127
fun hthm2thm (HOLThm (_, th)) = th
17324
0a5eebd5ff58 introduced internal function hthm2thm
obua
parents: 17322
diff changeset
   128
19064
bf19cc5a7899 fixed bugs, added caching
obua
parents: 18929
diff changeset
   129
fun to_hol_thm th = HOLThm ([], th)
17328
7bbfb79eda96 removed clutter
obua
parents: 17324
diff changeset
   130
19068
04b302f2902d cache improvements
obua
parents: 19067
diff changeset
   131
val replay_add_dump = add_dump
04b302f2902d cache improvements
obua
parents: 19067
diff changeset
   132
fun add_dump s thy = (ImportRecorder.add_dump s; replay_add_dump s thy)
04b302f2902d cache improvements
obua
parents: 19067
diff changeset
   133
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   134
datatype proof_info
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   135
  = Info of {disk_info: (string * string) option ref}
24707
dfeb98f84e93 Syntax.parse/check/read;
wenzelm
parents: 24634
diff changeset
   136
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   137
datatype proof = Proof of proof_info * proof_content
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   138
     and proof_content
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   139
       = PRefl of term
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   140
       | PInstT of proof * (hol_type,hol_type) subst
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   141
       | PSubst of proof list * term * proof
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   142
       | PAbs of proof * term
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   143
       | PDisch of proof * term
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   144
       | PMp of proof * proof
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   145
       | PHyp of term
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   146
       | PAxm of string * term
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   147
       | PDef of string * string * term
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   148
       | PTmSpec of string * string list * proof
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   149
       | PTyDef of string * string * proof
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   150
       | PTyIntro of string * string * string * string * term * term * proof
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   151
       | POracle of tag * term list * term
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   152
       | PDisk
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   153
       | PSpec of proof * term
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   154
       | PInst of proof * (term,term) subst
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   155
       | PGen of proof * term
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   156
       | PGenAbs of proof * term option * term list
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   157
       | PImpAS of proof * proof
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   158
       | PSym of proof
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   159
       | PTrans of proof * proof
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   160
       | PComb of proof * proof
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   161
       | PEqMp of proof * proof
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   162
       | PEqImp of proof
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   163
       | PExists of proof * term * term
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   164
       | PChoose of term * proof * proof
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   165
       | PConj of proof * proof
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   166
       | PConjunct1 of proof
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   167
       | PConjunct2 of proof
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   168
       | PDisj1 of proof * term
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   169
       | PDisj2 of proof * term
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   170
       | PDisjCases of proof * proof * proof
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   171
       | PNotI of proof
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   172
       | PNotE of proof
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   173
       | PContr of proof * term
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   174
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   175
exception PK of string * string
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   176
fun ERR f mesg = PK (f,mesg)
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   177
24707
dfeb98f84e93 Syntax.parse/check/read;
wenzelm
parents: 24634
diff changeset
   178
fun print_exn e =
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   179
    case e of
26626
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   180
        PK (m,s) => (writeln ("PK (" ^ m ^ "): " ^ s); raise e)
17959
8db36a108213 OldGoals;
wenzelm
parents: 17917
diff changeset
   181
      | _ => OldGoals.print_exn e
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   182
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   183
(* Compatibility. *)
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   184
19264
61e775c03ed8 string_of_mixfix;
wenzelm
parents: 19068
diff changeset
   185
val string_of_mixfix = Pretty.string_of o Syntax.pretty_mixfix;
61e775c03ed8 string_of_mixfix;
wenzelm
parents: 19068
diff changeset
   186
14685
92f34880efe3 more robust output of definitions;
wenzelm
parents: 14673
diff changeset
   187
fun mk_syn thy c =
16427
9975aab75d72 refer to HOL4_PROOFS setting;
wenzelm
parents: 16363
diff changeset
   188
  if Syntax.is_identifier c andalso not (Syntax.is_keyword (Sign.syn_of thy) c) then NoSyn
14685
92f34880efe3 more robust output of definitions;
wenzelm
parents: 14673
diff changeset
   189
  else Syntax.literal c
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   190
14673
3d760a971fde use Syntax.is_identifier;
wenzelm
parents: 14620
diff changeset
   191
fun quotename c =
27353
71c4dd53d4cb moved global keywords from OuterSyntax to OuterKeyword, tuned interfaces;
wenzelm
parents: 27187
diff changeset
   192
  if Syntax.is_identifier c andalso not (OuterKeyword.is_keyword c) then c else quote c
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   193
17652
b1ef33ebfa17 Release HOL4 and HOLLight Importer.
obua
parents: 17644
diff changeset
   194
fun simple_smart_string_of_cterm ct =
b1ef33ebfa17 Release HOL4 and HOLLight Importer.
obua
parents: 17644
diff changeset
   195
    let
26626
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   196
        val thy = Thm.theory_of_cterm ct;
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   197
        val {t,T,...} = rep_cterm ct
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   198
        (* Hack to avoid parse errors with Trueprop *)
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   199
        val ct  = (cterm_of thy (HOLogic.dest_Trueprop t)
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   200
                           handle TERM _ => ct)
17652
b1ef33ebfa17 Release HOL4 and HOLLight Importer.
obua
parents: 17644
diff changeset
   201
    in
26626
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   202
        quote(
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   203
        PrintMode.setmp [] (
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   204
        Library.setmp show_brackets false (
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   205
        Library.setmp show_all_types true (
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   206
        Library.setmp Syntax.ambiguity_is_error false (
26928
ca87aff1ad2d structure Display: less pervasive operations;
wenzelm
parents: 26626
diff changeset
   207
        Library.setmp show_sorts true Display.string_of_cterm))))
26626
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   208
        ct)
17652
b1ef33ebfa17 Release HOL4 and HOLLight Importer.
obua
parents: 17644
diff changeset
   209
    end
b1ef33ebfa17 Release HOL4 and HOLLight Importer.
obua
parents: 17644
diff changeset
   210
19064
bf19cc5a7899 fixed bugs, added caching
obua
parents: 18929
diff changeset
   211
exception SMART_STRING
bf19cc5a7899 fixed bugs, added caching
obua
parents: 18929
diff changeset
   212
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   213
fun smart_string_of_cterm ct =
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   214
    let
26626
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   215
        val thy = Thm.theory_of_cterm ct
24707
dfeb98f84e93 Syntax.parse/check/read;
wenzelm
parents: 24634
diff changeset
   216
        val ctxt = ProofContext.init thy
26626
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   217
        val {t,T,...} = rep_cterm ct
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   218
        (* Hack to avoid parse errors with Trueprop *)
26626
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   219
        val ct  = (cterm_of thy (HOLogic.dest_Trueprop t)
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   220
                   handle TERM _ => ct)
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   221
        fun match u = t aconv u
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   222
        fun G 0 = Library.setmp show_types true (Library.setmp show_sorts true)
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   223
          | G 1 = Library.setmp show_brackets true (G 0)
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   224
          | G 2 = Library.setmp show_all_types true (G 0)
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   225
          | G 3 = Library.setmp show_brackets true (G 2)
24707
dfeb98f84e93 Syntax.parse/check/read;
wenzelm
parents: 24634
diff changeset
   226
          | G _ = raise SMART_STRING
26626
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   227
        fun F n =
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   228
            let
26928
ca87aff1ad2d structure Display: less pervasive operations;
wenzelm
parents: 26626
diff changeset
   229
                val str = Library.setmp show_brackets false (G n Display.string_of_cterm) ct
26626
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   230
                val u = Syntax.parse_term ctxt str
24707
dfeb98f84e93 Syntax.parse/check/read;
wenzelm
parents: 24634
diff changeset
   231
                  |> TypeInfer.constrain T |> Syntax.check_term ctxt
26626
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   232
            in
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   233
                if match u
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   234
                then quote str
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   235
                else F (n+1)
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   236
            end
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   237
            handle ERROR mesg => F (n+1)
27187
17b63e145986 use regular error function;
wenzelm
parents: 26939
diff changeset
   238
                 | SMART_STRING => error ("smart_string failed for: "^(G 0 Display.string_of_cterm ct))
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   239
    in
24634
38db11874724 simplified PrintMode interfaces;
wenzelm
parents: 24630
diff changeset
   240
      PrintMode.setmp [] (Library.setmp Syntax.ambiguity_is_error true F) 0
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   241
    end
18678
dd0c569fa43d sane ERROR handling;
wenzelm
parents: 18489
diff changeset
   242
    handle ERROR mesg => simple_smart_string_of_cterm ct
24707
dfeb98f84e93 Syntax.parse/check/read;
wenzelm
parents: 24634
diff changeset
   243
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   244
val smart_string_of_thm = smart_string_of_cterm o cprop_of
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   245
26928
ca87aff1ad2d structure Display: less pervasive operations;
wenzelm
parents: 26626
diff changeset
   246
fun prth th = writeln (PrintMode.setmp [] Display.string_of_thm th)
ca87aff1ad2d structure Display: less pervasive operations;
wenzelm
parents: 26626
diff changeset
   247
fun prc ct = writeln (PrintMode.setmp [] Display.string_of_cterm ct)
26939
1035c89b4c02 moved global pretty/string_of functions from Sign to Syntax;
wenzelm
parents: 26928
diff changeset
   248
fun prin t = writeln (PrintMode.setmp [] (fn () => Syntax.string_of_term_global (the_context ()) t) ());
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   249
fun pth (HOLThm(ren,thm)) =
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   250
    let
26626
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   251
        (*val _ = writeln "Renaming:"
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   252
        val _ = app (fn(v,w) => (prin v; writeln " -->"; prin w)) ren*)
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   253
        val _ = prth thm
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   254
    in
26626
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   255
        ()
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   256
    end
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   257
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   258
fun disk_info_of (Proof(Info{disk_info,...},_)) = !disk_info
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15463
diff changeset
   259
fun mk_proof p = Proof(Info{disk_info = ref NONE},p)
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   260
fun content_of (Proof(_,p)) = p
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   261
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   262
fun set_disk_info_of (Proof(Info{disk_info,...},_)) thyname thmname =
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15463
diff changeset
   263
    disk_info := SOME(thyname,thmname)
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   264
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   265
structure Lib =
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   266
struct
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   267
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   268
fun assoc x =
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   269
    let
26626
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   270
        fun F [] = raise PK("Lib.assoc","Not found")
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   271
          | F ((x',y)::rest) = if x = x'
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   272
                               then y
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   273
                               else F rest
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   274
    in
26626
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   275
        F
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   276
    end
24707
dfeb98f84e93 Syntax.parse/check/read;
wenzelm
parents: 24634
diff changeset
   277
fun i mem L =
dfeb98f84e93 Syntax.parse/check/read;
wenzelm
parents: 24634
diff changeset
   278
    let fun itr [] = false
26626
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   279
          | itr (a::rst) = i=a orelse itr rst
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   280
    in itr L end;
24707
dfeb98f84e93 Syntax.parse/check/read;
wenzelm
parents: 24634
diff changeset
   281
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   282
fun [] union S = S
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   283
  | S union [] = S
29289
f45c9c3b40a3 eliminated OldTerm.(add_)term_consts;
wenzelm
parents: 29281
diff changeset
   284
  | (a::rst) union S2 = rst union (insert (op =) a S2)
24707
dfeb98f84e93 Syntax.parse/check/read;
wenzelm
parents: 24634
diff changeset
   285
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   286
fun implode_subst [] = []
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   287
  | implode_subst (x::r::rest) = ((x,r)::(implode_subst rest))
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   288
  | implode_subst _ = raise ERR "implode_subst" "malformed substitution list"
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   289
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   290
end
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   291
open Lib
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   292
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   293
structure Tag =
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   294
struct
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   295
val empty_tag = Tag []
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   296
fun read name = Tag [name]
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   297
fun merge (Tag tag1) (Tag tag2) = Tag (Lib.union(tag1,tag2))
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   298
end
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   299
24707
dfeb98f84e93 Syntax.parse/check/read;
wenzelm
parents: 24634
diff changeset
   300
(* Actual code. *)
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   301
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   302
fun get_segment thyname l = (Lib.assoc "s" l
26626
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   303
                             handle PK _ => thyname)
14518
c3019a66180f Added a number of explicit type casts and delayed evaluations (all seemingly
skalberg
parents: 14516
diff changeset
   304
val get_name : (string * string) list -> string = Lib.assoc "n"
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   305
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   306
local
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   307
    open LazyScan
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   308
    infix 7 |-- --|
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   309
    infix 5 :-- -- ^^
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   310
    infix 3 >>
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   311
    infix 0 ||
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   312
in
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   313
exception XML of string
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   314
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   315
datatype xml = Elem of string * (string * string) list * xml list
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   316
datatype XMLtype = XMLty of xml | FullType of hol_type
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   317
datatype XMLterm = XMLtm of xml | FullTerm of term
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   318
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   319
fun pair x y = (x,y)
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   320
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   321
fun scan_id toks =
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   322
    let
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   323
        val (x,toks2) = one Char.isAlpha toks
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   324
        val (xs,toks3) = any Char.isAlphaNum toks2
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   325
    in
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   326
        (String.implode (x::xs),toks3)
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   327
    end
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   328
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   329
fun scan_string str c =
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   330
    let
26626
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   331
        fun F [] toks = (c,toks)
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   332
          | F (c::cs) toks =
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   333
            case LazySeq.getItem toks of
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   334
                SOME(c',toks') =>
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   335
                if c = c'
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   336
                then F cs toks'
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   337
                else raise SyntaxError
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   338
              | NONE => raise SyntaxError
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   339
    in
26626
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   340
        F (String.explode str)
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   341
    end
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   342
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   343
local
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   344
    val scan_entity =
26626
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   345
        (scan_string "amp;" #"&")
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   346
            || scan_string "quot;" #"\""
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   347
            || scan_string "gt;" #">"
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   348
            || scan_string "lt;" #"<"
14620
1be590fd2422 Minor cleanup of headers and some speedup of the HOL4 import.
skalberg
parents: 14518
diff changeset
   349
            || scan_string "apos;" #"'"
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   350
in
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   351
fun scan_nonquote toks =
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   352
    case LazySeq.getItem toks of
26626
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   353
        SOME (c,toks') =>
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   354
        (case c of
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   355
             #"\"" => raise SyntaxError
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   356
           | #"&" => scan_entity toks'
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   357
           | c => (c,toks'))
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15463
diff changeset
   358
      | NONE => raise SyntaxError
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   359
end
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   360
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   361
val scan_string = $$ #"\"" |-- repeat scan_nonquote --| $$ #"\"" >>
26626
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   362
                     String.implode
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   363
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   364
val scan_attribute = scan_id -- $$ #"=" |-- scan_string
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   365
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   366
val scan_start_of_tag = $$ #"<" |-- scan_id --
26626
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   367
                           repeat ($$ #" " |-- scan_attribute)
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   368
14518
c3019a66180f Added a number of explicit type casts and delayed evaluations (all seemingly
skalberg
parents: 14516
diff changeset
   369
(* The evaluation delay introduced through the 'toks' argument is needed
c3019a66180f Added a number of explicit type casts and delayed evaluations (all seemingly
skalberg
parents: 14516
diff changeset
   370
for the sake of the SML/NJ (110.9.1) compiler.  Either that or an explicit
c3019a66180f Added a number of explicit type casts and delayed evaluations (all seemingly
skalberg
parents: 14516
diff changeset
   371
type :-( *)
c3019a66180f Added a number of explicit type casts and delayed evaluations (all seemingly
skalberg
parents: 14516
diff changeset
   372
fun scan_end_of_tag toks = ($$ #"/" |-- $$ #">" |-- succeed []) toks
c3019a66180f Added a number of explicit type casts and delayed evaluations (all seemingly
skalberg
parents: 14516
diff changeset
   373
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   374
val scan_end_tag = $$ #"<" |-- $$ #"/" |-- scan_id --| $$ #">"
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   375
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   376
fun scan_children id = $$ #">" |-- repeat scan_tag -- scan_end_tag >>
26626
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   377
                       (fn (chldr,id') => if id = id'
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   378
                                          then chldr
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   379
                                          else raise XML "Tag mismatch")
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   380
and scan_tag toks =
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   381
    let
26626
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   382
        val ((id,atts),toks2) = scan_start_of_tag toks
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   383
        val (chldr,toks3) = (scan_children id || scan_end_of_tag) toks2
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   384
    in
26626
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   385
        (Elem (id,atts,chldr),toks3)
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   386
    end
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   387
end
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   388
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   389
val type_of = Term.type_of
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   390
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   391
val boolT = Type("bool",[])
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   392
val propT = Type("prop",[])
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   393
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   394
fun mk_defeq name rhs thy =
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   395
    let
26626
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   396
        val ty = type_of rhs
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   397
    in
26626
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   398
        Logic.mk_equals (Const(Sign.intern_const thy name,ty),rhs)
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   399
    end
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   400
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   401
fun mk_teq name rhs thy =
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   402
    let
26626
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   403
        val ty = type_of rhs
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   404
    in
26626
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   405
        HOLogic.mk_eq (Const(Sign.intern_const thy name,ty),rhs)
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   406
    end
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   407
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   408
fun intern_const_name thyname const thy =
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   409
    case get_hol4_const_mapping thyname const thy of
26626
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   410
        SOME (_,cname,_) => cname
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15463
diff changeset
   411
      | NONE => (case get_hol4_const_renaming thyname const thy of
26626
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   412
                     SOME cname => Sign.intern_const thy (thyname ^ "." ^ cname)
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   413
                   | NONE => Sign.intern_const thy (thyname ^ "." ^ const))
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   414
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   415
fun intern_type_name thyname const thy =
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   416
    case get_hol4_type_mapping thyname const thy of
26626
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   417
        SOME (_,cname) => cname
17894
f2fdd22accaa Simplifier.theory_context;
wenzelm
parents: 17657
diff changeset
   418
      | NONE => Sign.intern_const thy (thyname ^ "." ^ const)
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   419
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   420
fun mk_vartype name = TFree(name,["HOL.type"])
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   421
fun mk_thy_type thy Thy Tyop Args = Type(intern_type_name Thy Tyop thy,Args)
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   422
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   423
val mk_var = Free
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   424
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   425
fun dom_rng (Type("fun",[dom,rng])) = (dom,rng)
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   426
  | dom_rng _ = raise ERR "dom_rng" "Not a functional type"
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   427
16486
1a12cdb6ee6b get_thm(s): Name;
wenzelm
parents: 16427
diff changeset
   428
fun mk_thy_const thy Thy Nam Ty = Const(intern_const_name Thy Nam thy,Ty)
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   429
24707
dfeb98f84e93 Syntax.parse/check/read;
wenzelm
parents: 24634
diff changeset
   430
local
dfeb98f84e93 Syntax.parse/check/read;
wenzelm
parents: 24634
diff changeset
   431
  fun get_const sg thyname name =
17894
f2fdd22accaa Simplifier.theory_context;
wenzelm
parents: 17657
diff changeset
   432
    (case Sign.const_type sg name of
f2fdd22accaa Simplifier.theory_context;
wenzelm
parents: 17657
diff changeset
   433
      SOME ty => Const (name, ty)
f2fdd22accaa Simplifier.theory_context;
wenzelm
parents: 17657
diff changeset
   434
    | NONE => raise ERR "get_type" (name ^ ": No such constant"))
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   435
in
16486
1a12cdb6ee6b get_thm(s): Name;
wenzelm
parents: 16427
diff changeset
   436
fun prim_mk_const thy Thy Nam =
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   437
    let
17894
f2fdd22accaa Simplifier.theory_context;
wenzelm
parents: 17657
diff changeset
   438
      val name = intern_const_name Thy Nam thy
f2fdd22accaa Simplifier.theory_context;
wenzelm
parents: 17657
diff changeset
   439
      val cmaps = HOL4ConstMaps.get thy
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   440
    in
17894
f2fdd22accaa Simplifier.theory_context;
wenzelm
parents: 17657
diff changeset
   441
      case StringPair.lookup cmaps (Thy,Nam) of
f2fdd22accaa Simplifier.theory_context;
wenzelm
parents: 17657
diff changeset
   442
        SOME(_,_,SOME ty) => Const(name,ty)
f2fdd22accaa Simplifier.theory_context;
wenzelm
parents: 17657
diff changeset
   443
      | _ => get_const thy Thy name
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   444
    end
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   445
end
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   446
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   447
fun mk_comb(f,a) = f $ a
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   448
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   449
(* Needed for HOL Light *)
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   450
fun protect_tyvarname s =
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   451
    let
26626
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   452
        fun no_quest s =
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   453
            if Char.contains s #"?"
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   454
            then String.translate (fn #"?" => "q_" | c => Char.toString c) s
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   455
            else s
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   456
        fun beg_prime s =
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   457
            if String.isPrefix "'" s
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   458
            then s
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   459
            else "'" ^ s
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   460
    in
26626
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   461
        s |> no_quest |> beg_prime
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   462
    end
17440
df77edc4f5d0 fixed HOL-light/Isabelle syntax incompatability via more protect_xxx functions
obua
parents: 17412
diff changeset
   463
17444
a389e5892691 1) mapped .. and == constants
obua
parents: 17440
diff changeset
   464
val protected_varnames = ref (Symtab.empty:string Symtab.table)
24630
351a308ab58d simplified type int (eliminated IntInf.int, integer);
wenzelm
parents: 22709
diff changeset
   465
val invented_isavar = ref 0
17444
a389e5892691 1) mapped .. and == constants
obua
parents: 17440
diff changeset
   466
17490
ec62f340e811 maybe the last bug fix (sigh)?
obua
parents: 17444
diff changeset
   467
fun innocent_varname s = Syntax.is_identifier s andalso not (String.isPrefix "u_" s)
ec62f340e811 maybe the last bug fix (sigh)?
obua
parents: 17444
diff changeset
   468
18678
dd0c569fa43d sane ERROR handling;
wenzelm
parents: 18489
diff changeset
   469
val check_name_thy = theory "Main"
17592
ece268908438 add debug messages
obua
parents: 17490
diff changeset
   470
18678
dd0c569fa43d sane ERROR handling;
wenzelm
parents: 18489
diff changeset
   471
fun valid_boundvarname s =
24707
dfeb98f84e93 Syntax.parse/check/read;
wenzelm
parents: 24634
diff changeset
   472
  can (fn () => Syntax.read_term_global check_name_thy ("SOME "^s^". True")) ();
18678
dd0c569fa43d sane ERROR handling;
wenzelm
parents: 18489
diff changeset
   473
dd0c569fa43d sane ERROR handling;
wenzelm
parents: 18489
diff changeset
   474
fun valid_varname s =
24707
dfeb98f84e93 Syntax.parse/check/read;
wenzelm
parents: 24634
diff changeset
   475
  can (fn () => Syntax.read_term_global check_name_thy s) ();
17490
ec62f340e811 maybe the last bug fix (sigh)?
obua
parents: 17444
diff changeset
   476
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   477
fun protect_varname s =
17490
ec62f340e811 maybe the last bug fix (sigh)?
obua
parents: 17444
diff changeset
   478
    if innocent_varname s andalso valid_varname s then s else
17444
a389e5892691 1) mapped .. and == constants
obua
parents: 17440
diff changeset
   479
    case Symtab.lookup (!protected_varnames) s of
a389e5892691 1) mapped .. and == constants
obua
parents: 17440
diff changeset
   480
      SOME t => t
24707
dfeb98f84e93 Syntax.parse/check/read;
wenzelm
parents: 24634
diff changeset
   481
    | NONE =>
17444
a389e5892691 1) mapped .. and == constants
obua
parents: 17440
diff changeset
   482
      let
26626
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   483
          val _ = inc invented_isavar
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   484
          val t = "u_" ^ string_of_int (!invented_isavar)
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   485
          val _ = ImportRecorder.protect_varname s t
17444
a389e5892691 1) mapped .. and == constants
obua
parents: 17440
diff changeset
   486
          val _ = protected_varnames := Symtab.update (s, t) (!protected_varnames)
a389e5892691 1) mapped .. and == constants
obua
parents: 17440
diff changeset
   487
      in
26626
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   488
          t
17444
a389e5892691 1) mapped .. and == constants
obua
parents: 17440
diff changeset
   489
      end
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   490
19067
c0321d7d6b3d variable counter is now also cached
obua
parents: 19066
diff changeset
   491
exception REPLAY_PROTECT_VARNAME of string*string*string
c0321d7d6b3d variable counter is now also cached
obua
parents: 19066
diff changeset
   492
24707
dfeb98f84e93 Syntax.parse/check/read;
wenzelm
parents: 24634
diff changeset
   493
fun replay_protect_varname s t =
26626
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   494
        case Symtab.lookup (!protected_varnames) s of
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   495
          SOME t' => raise REPLAY_PROTECT_VARNAME (s, t, t')
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   496
        | NONE =>
19067
c0321d7d6b3d variable counter is now also cached
obua
parents: 19066
diff changeset
   497
          let
26626
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   498
              val _ = inc invented_isavar
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   499
              val t = "u_" ^ string_of_int (!invented_isavar)
19067
c0321d7d6b3d variable counter is now also cached
obua
parents: 19066
diff changeset
   500
              val _ = protected_varnames := Symtab.update (s, t) (!protected_varnames)
c0321d7d6b3d variable counter is now also cached
obua
parents: 19066
diff changeset
   501
          in
26626
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   502
              ()
24707
dfeb98f84e93 Syntax.parse/check/read;
wenzelm
parents: 24634
diff changeset
   503
          end
dfeb98f84e93 Syntax.parse/check/read;
wenzelm
parents: 24634
diff changeset
   504
17490
ec62f340e811 maybe the last bug fix (sigh)?
obua
parents: 17444
diff changeset
   505
fun protect_boundvarname s = if innocent_varname s andalso valid_boundvarname s then s else "u"
17440
df77edc4f5d0 fixed HOL-light/Isabelle syntax incompatability via more protect_xxx functions
obua
parents: 17412
diff changeset
   506
df77edc4f5d0 fixed HOL-light/Isabelle syntax incompatability via more protect_xxx functions
obua
parents: 17412
diff changeset
   507
fun mk_lambda (v as Free (x, T)) t = Abs (protect_boundvarname x, T, abstract_over (v, t))
df77edc4f5d0 fixed HOL-light/Isabelle syntax incompatability via more protect_xxx functions
obua
parents: 17412
diff changeset
   508
  | mk_lambda (v as Var ((x, _), T)) t = Abs (protect_boundvarname x, T, abstract_over (v, t))
df77edc4f5d0 fixed HOL-light/Isabelle syntax incompatability via more protect_xxx functions
obua
parents: 17412
diff changeset
   509
  | mk_lambda v t = raise TERM ("lambda", [v, t]);
24707
dfeb98f84e93 Syntax.parse/check/read;
wenzelm
parents: 24634
diff changeset
   510
dfeb98f84e93 Syntax.parse/check/read;
wenzelm
parents: 24634
diff changeset
   511
fun replacestr x y s =
17440
df77edc4f5d0 fixed HOL-light/Isabelle syntax incompatability via more protect_xxx functions
obua
parents: 17412
diff changeset
   512
let
df77edc4f5d0 fixed HOL-light/Isabelle syntax incompatability via more protect_xxx functions
obua
parents: 17412
diff changeset
   513
  val xl = explode x
df77edc4f5d0 fixed HOL-light/Isabelle syntax incompatability via more protect_xxx functions
obua
parents: 17412
diff changeset
   514
  val yl = explode y
df77edc4f5d0 fixed HOL-light/Isabelle syntax incompatability via more protect_xxx functions
obua
parents: 17412
diff changeset
   515
  fun isprefix [] ys = true
df77edc4f5d0 fixed HOL-light/Isabelle syntax incompatability via more protect_xxx functions
obua
parents: 17412
diff changeset
   516
    | isprefix (x::xs) (y::ys) = if x = y then isprefix xs ys else false
24707
dfeb98f84e93 Syntax.parse/check/read;
wenzelm
parents: 24634
diff changeset
   517
    | isprefix _ _ = false
17440
df77edc4f5d0 fixed HOL-light/Isabelle syntax incompatability via more protect_xxx functions
obua
parents: 17412
diff changeset
   518
  fun isp s = isprefix xl s
df77edc4f5d0 fixed HOL-light/Isabelle syntax incompatability via more protect_xxx functions
obua
parents: 17412
diff changeset
   519
  fun chg s = yl@(List.drop (s, List.length xl))
df77edc4f5d0 fixed HOL-light/Isabelle syntax incompatability via more protect_xxx functions
obua
parents: 17412
diff changeset
   520
  fun r [] = []
24707
dfeb98f84e93 Syntax.parse/check/read;
wenzelm
parents: 24634
diff changeset
   521
    | r (S as (s::ss)) = if isp S then r (chg S) else s::(r ss)
17440
df77edc4f5d0 fixed HOL-light/Isabelle syntax incompatability via more protect_xxx functions
obua
parents: 17412
diff changeset
   522
in
df77edc4f5d0 fixed HOL-light/Isabelle syntax incompatability via more protect_xxx functions
obua
parents: 17412
diff changeset
   523
  implode(r (explode s))
24707
dfeb98f84e93 Syntax.parse/check/read;
wenzelm
parents: 24634
diff changeset
   524
end
17440
df77edc4f5d0 fixed HOL-light/Isabelle syntax incompatability via more protect_xxx functions
obua
parents: 17412
diff changeset
   525
df77edc4f5d0 fixed HOL-light/Isabelle syntax incompatability via more protect_xxx functions
obua
parents: 17412
diff changeset
   526
fun protect_factname s = replacestr "." "_dot_" s
24707
dfeb98f84e93 Syntax.parse/check/read;
wenzelm
parents: 24634
diff changeset
   527
fun unprotect_factname s = replacestr "_dot_" "." s
17440
df77edc4f5d0 fixed HOL-light/Isabelle syntax incompatability via more protect_xxx functions
obua
parents: 17412
diff changeset
   528
17322
781abf7011e6 Added HOLLight support to importer.
obua
parents: 16486
diff changeset
   529
val ty_num_prefix = "N_"
781abf7011e6 Added HOLLight support to importer.
obua
parents: 16486
diff changeset
   530
781abf7011e6 Added HOLLight support to importer.
obua
parents: 16486
diff changeset
   531
fun startsWithDigit s = Char.isDigit (hd (String.explode s))
781abf7011e6 Added HOLLight support to importer.
obua
parents: 16486
diff changeset
   532
24707
dfeb98f84e93 Syntax.parse/check/read;
wenzelm
parents: 24634
diff changeset
   533
fun protect_tyname tyn =
17322
781abf7011e6 Added HOLLight support to importer.
obua
parents: 16486
diff changeset
   534
  let
24707
dfeb98f84e93 Syntax.parse/check/read;
wenzelm
parents: 24634
diff changeset
   535
    val tyn' =
dfeb98f84e93 Syntax.parse/check/read;
wenzelm
parents: 24634
diff changeset
   536
      if String.isPrefix ty_num_prefix tyn then raise (ERR "protect_ty_name" ("type name '"^tyn^"' is reserved")) else
17322
781abf7011e6 Added HOLLight support to importer.
obua
parents: 16486
diff changeset
   537
      (if startsWithDigit tyn then ty_num_prefix^tyn else tyn)
781abf7011e6 Added HOLLight support to importer.
obua
parents: 16486
diff changeset
   538
  in
781abf7011e6 Added HOLLight support to importer.
obua
parents: 16486
diff changeset
   539
    tyn'
781abf7011e6 Added HOLLight support to importer.
obua
parents: 16486
diff changeset
   540
  end
781abf7011e6 Added HOLLight support to importer.
obua
parents: 16486
diff changeset
   541
24707
dfeb98f84e93 Syntax.parse/check/read;
wenzelm
parents: 24634
diff changeset
   542
fun protect_constname tcn = tcn
17444
a389e5892691 1) mapped .. and == constants
obua
parents: 17440
diff changeset
   543
 (* if tcn = ".." then "dotdot"
a389e5892691 1) mapped .. and == constants
obua
parents: 17440
diff changeset
   544
  else if tcn = "==" then "eqeq"
a389e5892691 1) mapped .. and == constants
obua
parents: 17440
diff changeset
   545
  else tcn*)
17322
781abf7011e6 Added HOLLight support to importer.
obua
parents: 16486
diff changeset
   546
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   547
structure TypeNet =
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   548
struct
17322
781abf7011e6 Added HOLLight support to importer.
obua
parents: 16486
diff changeset
   549
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   550
fun get_type_from_index thy thyname types is =
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   551
    case Int.fromString is of
26626
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   552
        SOME i => (case Array.sub(types,i) of
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   553
                       FullType ty => ty
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   554
                     | XMLty xty =>
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   555
                       let
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   556
                           val ty = get_type_from_xml thy thyname types xty
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   557
                           val _  = Array.update(types,i,FullType ty)
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   558
                       in
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   559
                           ty
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   560
                       end)
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   561
      | NONE => raise ERR "get_type_from_index" "Bad index"
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   562
and get_type_from_xml thy thyname types =
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   563
    let
26626
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   564
        fun gtfx (Elem("tyi",[("i",iS)],[])) =
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   565
                 get_type_from_index thy thyname types iS
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   566
          | gtfx (Elem("tyc",atts,[])) =
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   567
            mk_thy_type thy
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   568
                        (get_segment thyname atts)
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   569
                        (protect_tyname (get_name atts))
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   570
                        []
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   571
          | gtfx (Elem("tyv",[("n",s)],[])) = mk_vartype (protect_tyvarname s)
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   572
          | gtfx (Elem("tya",[],(Elem("tyc",atts,[]))::tys)) =
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   573
            mk_thy_type thy
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   574
                        (get_segment thyname atts)
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   575
                        (protect_tyname (get_name atts))
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   576
                        (map gtfx tys)
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   577
          | gtfx _ = raise ERR "get_type" "Bad type"
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   578
    in
26626
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   579
        gtfx
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   580
    end
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   581
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   582
fun input_types thyname (Elem("tylist",[("i",i)],xtys)) =
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   583
    let
26626
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   584
        val types = Array.array(valOf (Int.fromString i),XMLty (Elem("",[],[])))
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   585
        fun IT _ [] = ()
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   586
          | IT n (xty::xtys) =
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   587
            (Array.update(types,n,XMLty xty);
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   588
             IT (n+1) xtys)
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   589
        val _ = IT 0 xtys
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   590
    in
26626
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   591
        types
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   592
    end
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   593
  | input_types _ _ = raise ERR "input_types" "Bad type list"
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   594
end
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   595
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   596
structure TermNet =
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   597
struct
17322
781abf7011e6 Added HOLLight support to importer.
obua
parents: 16486
diff changeset
   598
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   599
fun get_term_from_index thy thyname types terms is =
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   600
    case Int.fromString is of
26626
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   601
        SOME i => (case Array.sub(terms,i) of
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   602
                       FullTerm tm => tm
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   603
                     | XMLtm xtm =>
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   604
                       let
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   605
                           val tm = get_term_from_xml thy thyname types terms xtm
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   606
                           val _  = Array.update(terms,i,FullTerm tm)
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   607
                       in
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   608
                           tm
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   609
                       end)
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   610
      | NONE => raise ERR "get_term_from_index" "Bad index"
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   611
and get_term_from_xml thy thyname types terms =
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   612
    let
26626
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   613
        fun get_type [] = NONE
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   614
          | get_type [ty] = SOME (TypeNet.get_type_from_xml thy thyname types ty)
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   615
          | get_type _ = raise ERR "get_term" "Bad type"
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   616
26626
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   617
        fun gtfx (Elem("tmv",[("n",name),("t",tyi)],[])) =
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   618
            mk_var(protect_varname name,TypeNet.get_type_from_index thy thyname types tyi)
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   619
          | gtfx (Elem("tmc",atts,[])) =
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   620
            let
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   621
                val segment = get_segment thyname atts
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   622
                val name = protect_constname(get_name atts)
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   623
            in
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   624
                mk_thy_const thy segment name (TypeNet.get_type_from_index thy thyname types (Lib.assoc "t" atts))
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   625
                handle PK _ => prim_mk_const thy segment name
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   626
            end
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   627
          | gtfx (Elem("tma",[("f",tmf),("a",tma)],[])) =
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   628
            let
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   629
                val f = get_term_from_index thy thyname types terms tmf
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   630
                val a = get_term_from_index thy thyname types terms tma
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   631
            in
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   632
                mk_comb(f,a)
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   633
            end
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   634
          | gtfx (Elem("tml",[("x",tmx),("a",tma)],[])) =
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   635
            let
24707
dfeb98f84e93 Syntax.parse/check/read;
wenzelm
parents: 24634
diff changeset
   636
                val x = get_term_from_index thy thyname types terms tmx
17490
ec62f340e811 maybe the last bug fix (sigh)?
obua
parents: 17444
diff changeset
   637
                val a = get_term_from_index thy thyname types terms tma
26626
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   638
            in
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   639
                mk_lambda x a
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   640
            end
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   641
          | gtfx (Elem("tmi",[("i",iS)],[])) =
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   642
            get_term_from_index thy thyname types terms iS
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   643
          | gtfx (Elem(tag,_,_)) =
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   644
            raise ERR "get_term" ("Not a term: "^tag)
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   645
    in
26626
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   646
        gtfx
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   647
    end
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   648
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   649
fun input_terms thyname types (Elem("tmlist",[("i",i)],xtms)) =
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   650
    let
26626
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   651
        val terms = Array.array(valOf(Int.fromString i),XMLtm (Elem("",[],[])))
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   652
26626
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   653
        fun IT _ [] = ()
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   654
          | IT n (xtm::xtms) =
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   655
            (Array.update(terms,n,XMLtm xtm);
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   656
             IT (n+1) xtms)
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   657
        val _ = IT 0 xtms
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   658
    in
26626
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents: 26343
diff changeset
   659
        terms
14516
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   660
    end
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   661
  | input_terms _ _ _ = raise ERR "input_terms" "Bad term list"
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   662
end
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   663
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   664
fun get_proof_dir (thyname:string) thy =
a183dec876ab Added HOL proof importer.
skalberg
parents:
diff changeset
   665
    let
26626
c6231d64d264 rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm