src/Pure/Thy/thy_syn.ML
author wenzelm
Tue, 02 Jul 2002 15:36:51 +0200
changeset 13271 d0859ff6cd65
parent 12120 a08c61932501
child 14981 e73f8140af78
permissions -rw-r--r--
added fact_index.ML;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
411
4860901706db interface for 'user sections';
wenzelm
parents:
diff changeset
     1
(*  Title:      Pure/Thy/thy_syn.ML
4860901706db interface for 'user sections';
wenzelm
parents:
diff changeset
     2
    ID:         $Id$
4860901706db interface for 'user sections';
wenzelm
parents:
diff changeset
     3
    Author:     Markus Wenzel, TU Muenchen
11819
9283b3c11234 tuned comments;
wenzelm
parents: 7024
diff changeset
     4
    License:    GPL (GNU GENERAL PUBLIC LICENSE)
411
4860901706db interface for 'user sections';
wenzelm
parents:
diff changeset
     5
11819
9283b3c11234 tuned comments;
wenzelm
parents: 7024
diff changeset
     6
Provide syntax for *old-style* theory files.
411
4860901706db interface for 'user sections';
wenzelm
parents:
diff changeset
     7
*)
4860901706db interface for 'user sections';
wenzelm
parents:
diff changeset
     8
6206
7d2204fcc1e5 delete_tmpfiles (from thy_read.ML);
wenzelm
parents: 3620
diff changeset
     9
signature BASIC_THY_SYN =
7d2204fcc1e5 delete_tmpfiles (from thy_read.ML);
wenzelm
parents: 3620
diff changeset
    10
sig
7d2204fcc1e5 delete_tmpfiles (from thy_read.ML);
wenzelm
parents: 3620
diff changeset
    11
  val delete_tmpfiles: bool ref
7d2204fcc1e5 delete_tmpfiles (from thy_read.ML);
wenzelm
parents: 3620
diff changeset
    12
end;
7d2204fcc1e5 delete_tmpfiles (from thy_read.ML);
wenzelm
parents: 3620
diff changeset
    13
411
4860901706db interface for 'user sections';
wenzelm
parents:
diff changeset
    14
signature THY_SYN =
3619
0fc67ad6d62a eliminated ThySynData and ThySynFun;
wenzelm
parents: 1512
diff changeset
    15
sig
6206
7d2204fcc1e5 delete_tmpfiles (from thy_read.ML);
wenzelm
parents: 3620
diff changeset
    16
  include BASIC_THY_SYN
3619
0fc67ad6d62a eliminated ThySynData and ThySynFun;
wenzelm
parents: 1512
diff changeset
    17
  val add_syntax: string list ->
0fc67ad6d62a eliminated ThySynData and ThySynFun;
wenzelm
parents: 1512
diff changeset
    18
    (string * (ThyParse.token list -> (string * string) * ThyParse.token list)) list
0fc67ad6d62a eliminated ThySynData and ThySynFun;
wenzelm
parents: 1512
diff changeset
    19
    -> unit
7024
wenzelm
parents: 6641
diff changeset
    20
  val get_lexicon: unit -> Scan.lexicon
6206
7d2204fcc1e5 delete_tmpfiles (from thy_read.ML);
wenzelm
parents: 3620
diff changeset
    21
  val load_thy: string -> string list -> unit
3619
0fc67ad6d62a eliminated ThySynData and ThySynFun;
wenzelm
parents: 1512
diff changeset
    22
end;
411
4860901706db interface for 'user sections';
wenzelm
parents:
diff changeset
    23
3619
0fc67ad6d62a eliminated ThySynData and ThySynFun;
wenzelm
parents: 1512
diff changeset
    24
structure ThySyn: THY_SYN =
411
4860901706db interface for 'user sections';
wenzelm
parents:
diff changeset
    25
struct
4860901706db interface for 'user sections';
wenzelm
parents:
diff changeset
    26
6206
7d2204fcc1e5 delete_tmpfiles (from thy_read.ML);
wenzelm
parents: 3620
diff changeset
    27
3619
0fc67ad6d62a eliminated ThySynData and ThySynFun;
wenzelm
parents: 1512
diff changeset
    28
(* current syntax *)
0fc67ad6d62a eliminated ThySynData and ThySynFun;
wenzelm
parents: 1512
diff changeset
    29
0fc67ad6d62a eliminated ThySynData and ThySynFun;
wenzelm
parents: 1512
diff changeset
    30
val keywords = ref ThyParse.pure_keywords;
0fc67ad6d62a eliminated ThySynData and ThySynFun;
wenzelm
parents: 1512
diff changeset
    31
val sections = ref ThyParse.pure_sections;
0fc67ad6d62a eliminated ThySynData and ThySynFun;
wenzelm
parents: 1512
diff changeset
    32
0fc67ad6d62a eliminated ThySynData and ThySynFun;
wenzelm
parents: 1512
diff changeset
    33
fun make_syntax () =
0fc67ad6d62a eliminated ThySynData and ThySynFun;
wenzelm
parents: 1512
diff changeset
    34
  ThyParse.make_syntax (! keywords) (!sections);
0fc67ad6d62a eliminated ThySynData and ThySynFun;
wenzelm
parents: 1512
diff changeset
    35
0fc67ad6d62a eliminated ThySynData and ThySynFun;
wenzelm
parents: 1512
diff changeset
    36
val syntax = ref (make_syntax ());
0fc67ad6d62a eliminated ThySynData and ThySynFun;
wenzelm
parents: 1512
diff changeset
    37
6206
7d2204fcc1e5 delete_tmpfiles (from thy_read.ML);
wenzelm
parents: 3620
diff changeset
    38
fun get_lexicon () = ThyParse.get_lexicon (! syntax);
7d2204fcc1e5 delete_tmpfiles (from thy_read.ML);
wenzelm
parents: 3620
diff changeset
    39
411
4860901706db interface for 'user sections';
wenzelm
parents:
diff changeset
    40
3619
0fc67ad6d62a eliminated ThySynData and ThySynFun;
wenzelm
parents: 1512
diff changeset
    41
(* augment syntax *)
0fc67ad6d62a eliminated ThySynData and ThySynFun;
wenzelm
parents: 1512
diff changeset
    42
0fc67ad6d62a eliminated ThySynData and ThySynFun;
wenzelm
parents: 1512
diff changeset
    43
fun add_syntax keys sects =
3620
wenzelm
parents: 3619
diff changeset
    44
 (keywords := (keys union ! keywords);
3619
0fc67ad6d62a eliminated ThySynData and ThySynFun;
wenzelm
parents: 1512
diff changeset
    45
  sections := sects @ ! sections;
0fc67ad6d62a eliminated ThySynData and ThySynFun;
wenzelm
parents: 1512
diff changeset
    46
  syntax := make_syntax ());
0fc67ad6d62a eliminated ThySynData and ThySynFun;
wenzelm
parents: 1512
diff changeset
    47
0fc67ad6d62a eliminated ThySynData and ThySynFun;
wenzelm
parents: 1512
diff changeset
    48
6206
7d2204fcc1e5 delete_tmpfiles (from thy_read.ML);
wenzelm
parents: 3620
diff changeset
    49
(* load_thy *)
7d2204fcc1e5 delete_tmpfiles (from thy_read.ML);
wenzelm
parents: 3620
diff changeset
    50
7d2204fcc1e5 delete_tmpfiles (from thy_read.ML);
wenzelm
parents: 3620
diff changeset
    51
val delete_tmpfiles = ref true;
3619
0fc67ad6d62a eliminated ThySynData and ThySynFun;
wenzelm
parents: 1512
diff changeset
    52
6206
7d2204fcc1e5 delete_tmpfiles (from thy_read.ML);
wenzelm
parents: 3620
diff changeset
    53
fun load_thy name chs =
7d2204fcc1e5 delete_tmpfiles (from thy_read.ML);
wenzelm
parents: 3620
diff changeset
    54
  let
7d2204fcc1e5 delete_tmpfiles (from thy_read.ML);
wenzelm
parents: 3620
diff changeset
    55
    val tmp_path = File.tmp_path (ThyLoad.ml_path (name ^ "_thy"));
7d2204fcc1e5 delete_tmpfiles (from thy_read.ML);
wenzelm
parents: 3620
diff changeset
    56
    val txt_out = ThyParse.parse_thy (! syntax) chs;
7d2204fcc1e5 delete_tmpfiles (from thy_read.ML);
wenzelm
parents: 3620
diff changeset
    57
  in
7d2204fcc1e5 delete_tmpfiles (from thy_read.ML);
wenzelm
parents: 3620
diff changeset
    58
    File.write tmp_path txt_out;
12120
a08c61932501 File.use;
wenzelm
parents: 11819
diff changeset
    59
    File.use tmp_path;
6206
7d2204fcc1e5 delete_tmpfiles (from thy_read.ML);
wenzelm
parents: 3620
diff changeset
    60
    if ! delete_tmpfiles then File.rm tmp_path else ()
7d2204fcc1e5 delete_tmpfiles (from thy_read.ML);
wenzelm
parents: 3620
diff changeset
    61
  end;
7d2204fcc1e5 delete_tmpfiles (from thy_read.ML);
wenzelm
parents: 3620
diff changeset
    62
411
4860901706db interface for 'user sections';
wenzelm
parents:
diff changeset
    63
4860901706db interface for 'user sections';
wenzelm
parents:
diff changeset
    64
end;
6206
7d2204fcc1e5 delete_tmpfiles (from thy_read.ML);
wenzelm
parents: 3620
diff changeset
    65
7d2204fcc1e5 delete_tmpfiles (from thy_read.ML);
wenzelm
parents: 3620
diff changeset
    66
7d2204fcc1e5 delete_tmpfiles (from thy_read.ML);
wenzelm
parents: 3620
diff changeset
    67
structure BasicThySyn: BASIC_THY_SYN = ThySyn;
7d2204fcc1e5 delete_tmpfiles (from thy_read.ML);
wenzelm
parents: 3620
diff changeset
    68
open BasicThySyn;