| 411 |      1 | (*  Title:      Pure/Thy/thy_syn.ML
 | 
|  |      2 |     ID:         $Id$
 | 
|  |      3 |     Author:     Markus Wenzel, TU Muenchen
 | 
| 11819 |      4 |     License:    GPL (GNU GENERAL PUBLIC LICENSE)
 | 
| 411 |      5 | 
 | 
| 11819 |      6 | Provide syntax for *old-style* theory files.
 | 
| 411 |      7 | *)
 | 
|  |      8 | 
 | 
| 6206 |      9 | signature BASIC_THY_SYN =
 | 
|  |     10 | sig
 | 
|  |     11 |   val delete_tmpfiles: bool ref
 | 
|  |     12 | end;
 | 
|  |     13 | 
 | 
| 411 |     14 | signature THY_SYN =
 | 
| 3619 |     15 | sig
 | 
| 6206 |     16 |   include BASIC_THY_SYN
 | 
| 3619 |     17 |   val add_syntax: string list ->
 | 
|  |     18 |     (string * (ThyParse.token list -> (string * string) * ThyParse.token list)) list
 | 
|  |     19 |     -> unit
 | 
| 7024 |     20 |   val get_lexicon: unit -> Scan.lexicon
 | 
| 6206 |     21 |   val load_thy: string -> string list -> unit
 | 
| 3619 |     22 | end;
 | 
| 411 |     23 | 
 | 
| 3619 |     24 | structure ThySyn: THY_SYN =
 | 
| 411 |     25 | struct
 | 
|  |     26 | 
 | 
| 6206 |     27 | 
 | 
| 3619 |     28 | (* current syntax *)
 | 
|  |     29 | 
 | 
|  |     30 | val keywords = ref ThyParse.pure_keywords;
 | 
|  |     31 | val sections = ref ThyParse.pure_sections;
 | 
|  |     32 | 
 | 
|  |     33 | fun make_syntax () =
 | 
|  |     34 |   ThyParse.make_syntax (! keywords) (!sections);
 | 
|  |     35 | 
 | 
|  |     36 | val syntax = ref (make_syntax ());
 | 
|  |     37 | 
 | 
| 6206 |     38 | fun get_lexicon () = ThyParse.get_lexicon (! syntax);
 | 
|  |     39 | 
 | 
| 411 |     40 | 
 | 
| 3619 |     41 | (* augment syntax *)
 | 
|  |     42 | 
 | 
|  |     43 | fun add_syntax keys sects =
 | 
| 3620 |     44 |  (keywords := (keys union ! keywords);
 | 
| 3619 |     45 |   sections := sects @ ! sections;
 | 
|  |     46 |   syntax := make_syntax ());
 | 
|  |     47 | 
 | 
|  |     48 | 
 | 
| 6206 |     49 | (* load_thy *)
 | 
|  |     50 | 
 | 
|  |     51 | val delete_tmpfiles = ref true;
 | 
| 3619 |     52 | 
 | 
| 6206 |     53 | fun load_thy name chs =
 | 
|  |     54 |   let
 | 
|  |     55 |     val tmp_path = File.tmp_path (ThyLoad.ml_path (name ^ "_thy"));
 | 
|  |     56 |     val txt_out = ThyParse.parse_thy (! syntax) chs;
 | 
|  |     57 |   in
 | 
|  |     58 |     File.write tmp_path txt_out;
 | 
| 12120 |     59 |     File.use tmp_path;
 | 
| 6206 |     60 |     if ! delete_tmpfiles then File.rm tmp_path else ()
 | 
|  |     61 |   end;
 | 
|  |     62 | 
 | 
| 411 |     63 | 
 | 
|  |     64 | end;
 | 
| 6206 |     65 | 
 | 
|  |     66 | 
 | 
|  |     67 | structure BasicThySyn: BASIC_THY_SYN = ThySyn;
 | 
|  |     68 | open BasicThySyn;
 |