| author | nipkow | 
| Wed, 20 Jun 2007 08:09:56 +0200 | |
| changeset 23432 | cec811764a38 | 
| parent 22826 | 0f4c501a691e | 
| child 23679 | 57dceb84d1a0 | 
| permissions | -rw-r--r-- | 
| 5829 | 1  | 
(* Title: Pure/Isar/outer_syntax.ML  | 
2  | 
ID: $Id$  | 
|
3  | 
Author: Markus Wenzel, TU Muenchen  | 
|
4  | 
||
5  | 
The global Isabelle/Isar outer syntax.  | 
|
6  | 
*)  | 
|
7  | 
||
8  | 
signature BASIC_OUTER_SYNTAX =  | 
|
9  | 
sig  | 
|
| 15830 | 10  | 
structure Isar:  | 
11  | 
sig  | 
|
| 18064 | 12  | 
val state: unit -> Toplevel.state  | 
| 21207 | 13  | 
val exn: unit -> (exn * string) option  | 
| 20023 | 14  | 
val context: unit -> Proof.context  | 
| 21401 | 15  | 
val goal: unit -> thm list * thm  | 
| 15830 | 16  | 
val main: unit -> unit  | 
17  | 
val loop: unit -> unit  | 
|
18  | 
val sync_main: unit -> unit  | 
|
19  | 
val sync_loop: unit -> unit  | 
|
| 18684 | 20  | 
val toplevel: (unit -> 'a) -> 'a  | 
| 15830 | 21  | 
end;  | 
| 5829 | 22  | 
end;  | 
23  | 
||
24  | 
signature OUTER_SYNTAX =  | 
|
25  | 
sig  | 
|
26  | 
include BASIC_OUTER_SYNTAX  | 
|
27  | 
type token  | 
|
28  | 
type parser  | 
|
| 
17071
 
f753d6dd9bd0
moved structure Keyword to OuterKeyword (Isar/outer_keyword.ML);
 
wenzelm 
parents: 
16894 
diff
changeset
 | 
29  | 
val command: string -> string -> OuterKeyword.T ->  | 
| 6373 | 30  | 
(token list -> (Toplevel.transition -> Toplevel.transition) * token list) -> parser  | 
| 22120 | 31  | 
val markup_command: ThyOutput.markup -> string -> string -> OuterKeyword.T ->  | 
| 7789 | 32  | 
(token list -> (Toplevel.transition -> Toplevel.transition) * token list) -> parser  | 
| 
17071
 
f753d6dd9bd0
moved structure Keyword to OuterKeyword (Isar/outer_keyword.ML);
 
wenzelm 
parents: 
16894 
diff
changeset
 | 
33  | 
val improper_command: string -> string -> OuterKeyword.T ->  | 
| 6373 | 34  | 
(token list -> (Toplevel.transition -> Toplevel.transition) * token list) -> parser  | 
| 14687 | 35  | 
val is_keyword: string -> bool  | 
| 7026 | 36  | 
val dest_keywords: unit -> string list  | 
37  | 
val dest_parsers: unit -> (string * string * string * bool) list  | 
|
| 5883 | 38  | 
val print_outer_syntax: unit -> unit  | 
| 9223 | 39  | 
val print_commands: Toplevel.transition -> Toplevel.transition  | 
| 5829 | 40  | 
val add_keywords: string list -> unit  | 
41  | 
val add_parsers: parser list -> unit  | 
|
| 19060 | 42  | 
val check_text: string * Position.T -> Toplevel.node option -> unit  | 
| 7940 | 43  | 
val deps_thy: string -> bool -> Path.T -> string list * Path.T list  | 
| 6199 | 44  | 
val load_thy: string -> bool -> bool -> Path.T -> unit  | 
| 14091 | 45  | 
val isar: bool -> bool -> unit Toplevel.isar  | 
| 16195 | 46  | 
val scan: string -> OuterLex.token list  | 
47  | 
val read: OuterLex.token list -> (string * OuterLex.token list * Toplevel.transition) list  | 
|
| 5829 | 48  | 
end;  | 
49  | 
||
| 
15224
 
1bd35fd87963
Allow scanning to recover and reconstruct bad input
 
aspinall 
parents: 
15156 
diff
changeset
 | 
50  | 
structure OuterSyntax : OUTER_SYNTAX =  | 
| 5829 | 51  | 
struct  | 
52  | 
||
| 7750 | 53  | 
structure T = OuterLex;  | 
| 6860 | 54  | 
structure P = OuterParse;  | 
55  | 
||
| 5829 | 56  | 
|
57  | 
(** outer syntax **)  | 
|
58  | 
||
59  | 
(* parsers *)  | 
|
60  | 
||
| 7750 | 61  | 
type token = T.token;  | 
| 5829 | 62  | 
type parser_fn = token list -> (Toplevel.transition -> Toplevel.transition) * token list;  | 
63  | 
||
64  | 
datatype parser =  | 
|
| 22120 | 65  | 
Parser of string * (string * OuterKeyword.T * ThyOutput.markup option) * bool * parser_fn;  | 
| 5829 | 66  | 
|
| 7750 | 67  | 
fun parser int_only markup name comment kind parse =  | 
68  | 
Parser (name, (comment, kind, markup), int_only, parse);  | 
|
| 5829 | 69  | 
|
70  | 
||
71  | 
(* parse command *)  | 
|
72  | 
||
| 6860 | 73  | 
local  | 
| 6199 | 74  | 
|
| 
14925
 
0f86a8a694f8
added read (provides transition names and sources);
 
wenzelm 
parents: 
14687 
diff
changeset
 | 
75  | 
fun terminate false = Scan.succeed ()  | 
| 
 
0f86a8a694f8
added read (provides transition names and sources);
 
wenzelm 
parents: 
14687 
diff
changeset
 | 
76  | 
| terminate true = P.group "end of input" (Scan.option P.sync -- P.semicolon >> K ());  | 
| 
 
0f86a8a694f8
added read (provides transition names and sources);
 
wenzelm 
parents: 
14687 
diff
changeset
 | 
77  | 
|
| 
 
0f86a8a694f8
added read (provides transition names and sources);
 
wenzelm 
parents: 
14687 
diff
changeset
 | 
78  | 
fun trace false parse = parse  | 
| 
 
0f86a8a694f8
added read (provides transition names and sources);
 
wenzelm 
parents: 
14687 
diff
changeset
 | 
79  | 
| trace true parse = Scan.trace parse >> (fn (f, toks) => f o Toplevel.source toks);  | 
| 
 
0f86a8a694f8
added read (provides transition names and sources);
 
wenzelm 
parents: 
14687 
diff
changeset
 | 
80  | 
|
| 
17071
 
f753d6dd9bd0
moved structure Keyword to OuterKeyword (Isar/outer_keyword.ML);
 
wenzelm 
parents: 
16894 
diff
changeset
 | 
81  | 
fun body cmd do_trace (name, _) =  | 
| 7026 | 82  | 
(case cmd name of  | 
| 15531 | 83  | 
SOME (int_only, parse) =>  | 
| 17118 | 84  | 
P.!!! (Scan.prompt (name ^ "# ") (trace do_trace (P.tags |-- parse) >> pair int_only))  | 
| 15531 | 85  | 
  | NONE => sys_error ("no parser for outer syntax command " ^ quote name));
 | 
| 6860 | 86  | 
|
87  | 
in  | 
|
| 5829 | 88  | 
|
| 
14925
 
0f86a8a694f8
added read (provides transition names and sources);
 
wenzelm 
parents: 
14687 
diff
changeset
 | 
89  | 
fun command do_terminate do_trace cmd =  | 
| 15531 | 90  | 
P.semicolon >> K NONE ||  | 
91  | 
P.sync >> K NONE ||  | 
|
| 17118 | 92  | 
(P.position P.command :-- body cmd do_trace) --| terminate do_terminate  | 
| 6860 | 93  | 
>> (fn ((name, pos), (int_only, f)) =>  | 
| 15531 | 94  | 
SOME (Toplevel.empty |> Toplevel.name name |> Toplevel.position pos |>  | 
| 6860 | 95  | 
Toplevel.interactive int_only |> f));  | 
| 5829 | 96  | 
|
| 6199 | 97  | 
end;  | 
98  | 
||
| 5829 | 99  | 
|
100  | 
||
| 9132 | 101  | 
(** global outer syntax **)  | 
| 5829 | 102  | 
|
| 7026 | 103  | 
local  | 
104  | 
||
105  | 
val global_lexicons = ref (Scan.empty_lexicon, Scan.empty_lexicon);  | 
|
| 7750 | 106  | 
val global_parsers =  | 
| 22120 | 107  | 
ref (Symtab.empty: (((string * OuterKeyword.T) * (bool * parser_fn)) * ThyOutput.markup option)  | 
| 9132 | 108  | 
Symtab.table);  | 
| 22120 | 109  | 
val global_markups = ref ([]: (string * ThyOutput.markup) list);  | 
| 5952 | 110  | 
|
| 7026 | 111  | 
fun change_lexicons f =  | 
112  | 
let val lexs = f (! global_lexicons) in  | 
|
113  | 
(case (op inter_string) (pairself Scan.dest_lexicon lexs) of  | 
|
114  | 
[] => global_lexicons := lexs  | 
|
115  | 
    | bads => error ("Clash of outer syntax commands and keywords: " ^ commas_quote bads))
 | 
|
116  | 
end;  | 
|
| 5829 | 117  | 
|
| 
17071
 
f753d6dd9bd0
moved structure Keyword to OuterKeyword (Isar/outer_keyword.ML);
 
wenzelm 
parents: 
16894 
diff
changeset
 | 
118  | 
fun make_markups () = global_markups :=  | 
| 
 
f753d6dd9bd0
moved structure Keyword to OuterKeyword (Isar/outer_keyword.ML);
 
wenzelm 
parents: 
16894 
diff
changeset
 | 
119  | 
Symtab.fold (fn (name, (_, SOME m)) => cons (name, m) | _ => I) (! global_parsers) [];  | 
| 7750 | 120  | 
|
| 9132 | 121  | 
fun change_parsers f = (Library.change global_parsers f; make_markups ());  | 
| 6722 | 122  | 
|
| 7026 | 123  | 
in  | 
124  | 
||
| 7750 | 125  | 
|
| 9132 | 126  | 
(* access current syntax *)  | 
| 7026 | 127  | 
|
128  | 
(*Note: the syntax for files is statically determined at the very  | 
|
129  | 
beginning; for interactive processing it may change dynamically.*)  | 
|
130  | 
||
131  | 
fun get_lexicons () = ! global_lexicons;  | 
|
132  | 
fun get_parsers () = ! global_parsers;  | 
|
| 17412 | 133  | 
fun get_parser () = Option.map (#2 o #1) o Symtab.lookup (get_parsers ());  | 
| 7789 | 134  | 
|
| 
17071
 
f753d6dd9bd0
moved structure Keyword to OuterKeyword (Isar/outer_keyword.ML);
 
wenzelm 
parents: 
16894 
diff
changeset
 | 
135  | 
fun command_tags name =  | 
| 17412 | 136  | 
(case Symtab.lookup (get_parsers ()) name of  | 
| 
17071
 
f753d6dd9bd0
moved structure Keyword to OuterKeyword (Isar/outer_keyword.ML);
 
wenzelm 
parents: 
16894 
diff
changeset
 | 
137  | 
SOME (((_, k), _), _) => OuterKeyword.tags_of k  | 
| 
 
f753d6dd9bd0
moved structure Keyword to OuterKeyword (Isar/outer_keyword.ML);
 
wenzelm 
parents: 
16894 
diff
changeset
 | 
138  | 
| NONE => []);  | 
| 
 
f753d6dd9bd0
moved structure Keyword to OuterKeyword (Isar/outer_keyword.ML);
 
wenzelm 
parents: 
16894 
diff
changeset
 | 
139  | 
|
| 17184 | 140  | 
fun is_markup kind name = (AList.lookup (op =) (! global_markups) name = SOME kind);  | 
| 5829 | 141  | 
|
142  | 
||
143  | 
(* augment syntax *)  | 
|
144  | 
||
| 22120 | 145  | 
fun add_keywords keywords =  | 
146  | 
change_lexicons (apfst (Scan.extend_lexicon (map Symbol.explode keywords)));  | 
|
| 5829 | 147  | 
|
| 
17071
 
f753d6dd9bd0
moved structure Keyword to OuterKeyword (Isar/outer_keyword.ML);
 
wenzelm 
parents: 
16894 
diff
changeset
 | 
148  | 
fun add_parser (Parser (name, (comment, kind, markup), int_only, parse)) tab =  | 
| 16894 | 149  | 
(if not (Symtab.defined tab name) then ()  | 
| 5829 | 150  | 
  else warning ("Redefined outer syntax command " ^ quote name);
 | 
| 17412 | 151  | 
Symtab.update (name, (((comment, kind), (int_only, parse)), markup)) tab);  | 
| 5829 | 152  | 
|
153  | 
fun add_parsers parsers =  | 
|
| 
17071
 
f753d6dd9bd0
moved structure Keyword to OuterKeyword (Isar/outer_keyword.ML);
 
wenzelm 
parents: 
16894 
diff
changeset
 | 
154  | 
(change_parsers (fold add_parser parsers);  | 
| 22120 | 155  | 
change_lexicons (apsnd (Scan.extend_lexicon  | 
| 7026 | 156  | 
(map (fn Parser (name, _, _, _) => Symbol.explode name) parsers))));  | 
157  | 
||
158  | 
end;  | 
|
| 5829 | 159  | 
|
160  | 
||
| 7026 | 161  | 
(* print syntax *)  | 
162  | 
||
| 14687 | 163  | 
fun is_keyword s = Scan.is_literal (#1 (get_lexicons ())) (Symbol.explode s);  | 
| 7026 | 164  | 
fun dest_keywords () = Scan.dest_lexicon (#1 (get_lexicons ()));  | 
165  | 
||
166  | 
fun dest_parsers () =  | 
|
| 16727 | 167  | 
get_parsers () |> Symtab.dest |> sort_wrt #1  | 
| 
17071
 
f753d6dd9bd0
moved structure Keyword to OuterKeyword (Isar/outer_keyword.ML);
 
wenzelm 
parents: 
16894 
diff
changeset
 | 
168  | 
|> map (fn (name, (((cmt, kind), (int_only, _)), _)) =>  | 
| 
 
f753d6dd9bd0
moved structure Keyword to OuterKeyword (Isar/outer_keyword.ML);
 
wenzelm 
parents: 
16894 
diff
changeset
 | 
169  | 
(name, cmt, OuterKeyword.kind_of kind, int_only));  | 
| 5829 | 170  | 
|
| 9223 | 171  | 
fun print_outer_syntax () =  | 
| 7026 | 172  | 
let  | 
173  | 
fun pretty_cmd (name, comment, _, _) =  | 
|
174  | 
Pretty.block [Pretty.str (name ^ ":"), Pretty.brk 2, Pretty.str comment];  | 
|
| 15570 | 175  | 
val (int_cmds, cmds) = List.partition #4 (dest_parsers ());  | 
| 7026 | 176  | 
in  | 
| 8720 | 177  | 
    [Pretty.strs ("syntax keywords:" :: map quote (dest_keywords ())),
 | 
| 18326 | 178  | 
Pretty.big_list "commands:" (map pretty_cmd cmds),  | 
179  | 
Pretty.big_list "interactive-only commands:" (map pretty_cmd int_cmds)]  | 
|
| 9223 | 180  | 
|> Pretty.chunks |> Pretty.writeln  | 
| 7026 | 181  | 
end;  | 
| 5829 | 182  | 
|
| 9223 | 183  | 
val print_commands = Toplevel.imperative print_outer_syntax;  | 
| 7367 | 184  | 
|
| 5829 | 185  | 
|
186  | 
||
| 9132 | 187  | 
(** toplevel parsing **)  | 
| 5829 | 188  | 
|
| 9132 | 189  | 
(* basic sources *)  | 
| 6860 | 190  | 
|
| 
17071
 
f753d6dd9bd0
moved structure Keyword to OuterKeyword (Isar/outer_keyword.ML);
 
wenzelm 
parents: 
16894 
diff
changeset
 | 
191  | 
fun toplevel_source term do_trace do_recover cmd src =  | 
| 9132 | 192  | 
let  | 
193  | 
val no_terminator =  | 
|
194  | 
Scan.unless P.semicolon (Scan.one (T.not_sync andf T.not_eof));  | 
|
| 15531 | 195  | 
fun recover x = (Scan.prompt "recover# " (Scan.repeat no_terminator) >> K [NONE]) x;  | 
| 9132 | 196  | 
in  | 
197  | 
src  | 
|
| 
12876
 
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
 
wenzelm 
parents: 
10749 
diff
changeset
 | 
198  | 
|> T.source_proper  | 
| 9132 | 199  | 
|> Source.source T.stopper  | 
| 15531 | 200  | 
(Scan.bulk (P.$$$ "--" -- P.!!! P.text >> K NONE || P.not_eof >> SOME))  | 
201  | 
(if do_recover then SOME recover else NONE)  | 
|
| 
19482
 
9f11af8f7ef9
tuned basic list operators (flat, maps, map_filter);
 
wenzelm 
parents: 
19060 
diff
changeset
 | 
202  | 
|> Source.map_filter I  | 
| 
17071
 
f753d6dd9bd0
moved structure Keyword to OuterKeyword (Isar/outer_keyword.ML);
 
wenzelm 
parents: 
16894 
diff
changeset
 | 
203  | 
|> Source.source T.stopper (Scan.bulk (fn xs => P.!!! (command term do_trace (cmd ())) xs))  | 
| 15531 | 204  | 
(if do_recover then SOME recover else NONE)  | 
| 
19482
 
9f11af8f7ef9
tuned basic list operators (flat, maps, map_filter);
 
wenzelm 
parents: 
19060 
diff
changeset
 | 
205  | 
|> Source.map_filter I  | 
| 9132 | 206  | 
end;  | 
| 5829 | 207  | 
|
| 7746 | 208  | 
|
| 9132 | 209  | 
(* interactive source of toplevel transformers *)  | 
| 5829 | 210  | 
|
| 9132 | 211  | 
fun isar term no_pos =  | 
212  | 
Source.tty  | 
|
213  | 
|> Symbol.source true  | 
|
214  | 
|> T.source true get_lexicons  | 
|
215  | 
(if no_pos then Position.none else Position.line_name 1 "stdin")  | 
|
| 
14925
 
0f86a8a694f8
added read (provides transition names and sources);
 
wenzelm 
parents: 
14687 
diff
changeset
 | 
216  | 
|> toplevel_source term false true get_parser;  | 
| 6199 | 217  | 
|
218  | 
||
| 16195 | 219  | 
(* scan text *)  | 
| 
14925
 
0f86a8a694f8
added read (provides transition names and sources);
 
wenzelm 
parents: 
14687 
diff
changeset
 | 
220  | 
|
| 
15144
 
85929e1b307d
Remove isar_readstring.  Split read into scanner and parser.
 
aspinall 
parents: 
14981 
diff
changeset
 | 
221  | 
fun scan str =  | 
| 16195 | 222  | 
Source.of_string str  | 
223  | 
|> Symbol.source false  | 
|
224  | 
|> T.source true get_lexicons Position.none  | 
|
225  | 
|> Source.exhaust;  | 
|
226  | 
||
227  | 
||
228  | 
(* read tokens with trace *)  | 
|
| 
14925
 
0f86a8a694f8
added read (provides transition names and sources);
 
wenzelm 
parents: 
14687 
diff
changeset
 | 
229  | 
|
| 
15144
 
85929e1b307d
Remove isar_readstring.  Split read into scanner and parser.
 
aspinall 
parents: 
14981 
diff
changeset
 | 
230  | 
fun read toks =  | 
| 
 
85929e1b307d
Remove isar_readstring.  Split read into scanner and parser.
 
aspinall 
parents: 
14981 
diff
changeset
 | 
231  | 
Source.of_list toks  | 
| 
14925
 
0f86a8a694f8
added read (provides transition names and sources);
 
wenzelm 
parents: 
14687 
diff
changeset
 | 
232  | 
|> toplevel_source false true true get_parser  | 
| 
 
0f86a8a694f8
added read (provides transition names and sources);
 
wenzelm 
parents: 
14687 
diff
changeset
 | 
233  | 
|> Source.exhaust  | 
| 15973 | 234  | 
|> map (fn tr => (Toplevel.name_of tr, the (Toplevel.source_of tr), tr));  | 
| 14091 | 235  | 
|
236  | 
||
| 16195 | 237  | 
|
| 9132 | 238  | 
(** read theory **)  | 
| 6247 | 239  | 
|
| 12943 | 240  | 
(* check_text *)  | 
241  | 
||
| 22120 | 242  | 
fun check_text s state = (ThyOutput.eval_antiquote (#1 (get_lexicons ())) state s; ());  | 
| 12943 | 243  | 
|
244  | 
||
| 9132 | 245  | 
(* deps_thy *)  | 
| 6199 | 246  | 
|
| 7940 | 247  | 
fun deps_thy name ml path =  | 
| 6199 | 248  | 
let  | 
| 7735 | 249  | 
val src = Source.of_string (File.read path);  | 
250  | 
val pos = Path.position path;  | 
|
| 17932 | 251  | 
val (name', parents, files) = ThyHeader.read (src, pos);  | 
| 6199 | 252  | 
val ml_path = ThyLoad.ml_path name;  | 
| 15973 | 253  | 
val ml_file = if ml andalso is_some (ThyLoad.check_file NONE ml_path) then [ml_path] else [];  | 
| 6199 | 254  | 
in  | 
255  | 
if name <> name' then  | 
|
| 
21858
 
05f57309170c
avoid conflict with Alice keywords: renamed pack -> implode, unpack -> explode, any -> many, avoided assert;
 
wenzelm 
parents: 
21506 
diff
changeset
 | 
256  | 
      error ("Filename " ^ quote (Path.implode path) ^
 | 
| 8078 | 257  | 
" does not agree with theory name " ^ quote name')  | 
| 
21858
 
05f57309170c
avoid conflict with Alice keywords: renamed pack -> implode, unpack -> explode, any -> many, avoided assert;
 
wenzelm 
parents: 
21506 
diff
changeset
 | 
258  | 
else (parents, map (Path.explode o #1) files @ ml_file)  | 
| 6199 | 259  | 
end;  | 
260  | 
||
| 7746 | 261  | 
|
| 9132 | 262  | 
(* load_thy *)  | 
| 6199 | 263  | 
|
| 7746 | 264  | 
local  | 
265  | 
||
| 7940 | 266  | 
fun try_ml_file name time =  | 
| 20323 | 267  | 
let val path = ThyLoad.ml_path name in  | 
| 15531 | 268  | 
if is_none (ThyLoad.check_file NONE path) then ()  | 
| 20323 | 269  | 
else  | 
270  | 
let  | 
|
| 22826 | 271  | 
        val _ = legacy_feature ("loading attached ML script " ^ quote (Path.implode path));
 | 
| 20323 | 272  | 
val tr = Toplevel.imperative (fn () => ThyInfo.load_file time path);  | 
273  | 
val tr_name = if time then "time_use" else "use";  | 
|
274  | 
in Toplevel.excursion [Toplevel.empty |> Toplevel.name tr_name |> tr] end  | 
|
| 6199 | 275  | 
end;  | 
276  | 
||
| 18717 | 277  | 
fun run_thy name path =  | 
| 7683 | 278  | 
let  | 
| 17932 | 279  | 
val text = Source.of_list (Library.untabify (explode (File.read path)));  | 
280  | 
val _ = Present.init_theory name;  | 
|
281  | 
val _ = Present.verbatim_source name (fn () => Source.exhaust (Symbol.source false text));  | 
|
282  | 
val toks = text  | 
|
283  | 
|> Symbol.source false  | 
|
284  | 
|> T.source false (K (get_lexicons ())) (Path.position path)  | 
|
285  | 
|> Source.exhausted;  | 
|
286  | 
val trs = toks  | 
|
287  | 
|> toplevel_source false false false (K (get_parser ()))  | 
|
288  | 
|> Source.exhaust;  | 
|
| 7683 | 289  | 
in  | 
| 22120 | 290  | 
ThyOutput.present_thy (#1 (get_lexicons ())) command_tags is_markup trs toks  | 
| 17932 | 291  | 
|> Buffer.content  | 
292  | 
|> Present.theory_output name  | 
|
| 18717 | 293  | 
end;  | 
| 6199 | 294  | 
|
| 7746 | 295  | 
in  | 
296  | 
||
| 6199 | 297  | 
fun load_thy name ml time path =  | 
| 6247 | 298  | 
(if time then  | 
299  | 
timeit (fn () =>  | 
|
300  | 
     (writeln ("\n**** Starting theory " ^ quote name ^ " ****");
 | 
|
| 9036 | 301  | 
run_thy name path;  | 
| 6247 | 302  | 
      writeln ("**** Finished theory " ^ quote name ^ " ****\n")))
 | 
303  | 
else run_thy name path;  | 
|
| 22120 | 304  | 
ML_Context.set_context (SOME (Context.Theory (ThyInfo.get_theory name)));  | 
| 7940 | 305  | 
if ml then try_ml_file name time else ());  | 
| 5829 | 306  | 
|
| 7746 | 307  | 
end;  | 
308  | 
||
| 5829 | 309  | 
|
310  | 
||
311  | 
(** the read-eval-print loop **)  | 
|
312  | 
||
| 5923 | 313  | 
(* main loop *)  | 
314  | 
||
| 7333 | 315  | 
fun gen_loop term no_pos =  | 
| 22120 | 316  | 
(ML_Context.set_context NONE;  | 
| 21967 | 317  | 
Toplevel.loop (isar term no_pos));  | 
| 5829 | 318  | 
|
| 7333 | 319  | 
fun gen_main term no_pos =  | 
| 21957 | 320  | 
(Toplevel.init_state ();  | 
| 6199 | 321  | 
writeln (Session.welcome ());  | 
| 7333 | 322  | 
gen_loop term no_pos);  | 
| 6860 | 323  | 
|
| 15830 | 324  | 
structure Isar =  | 
325  | 
struct  | 
|
| 18064 | 326  | 
val state = Toplevel.get_state;  | 
327  | 
val exn = Toplevel.exn;  | 
|
| 21401 | 328  | 
|
| 21207 | 329  | 
fun context () =  | 
| 21506 | 330  | 
Toplevel.context_of (state ())  | 
| 21207 | 331  | 
handle Toplevel.UNDEF => error "Unknown context";  | 
| 21401 | 332  | 
|
333  | 
fun goal () =  | 
|
334  | 
#2 (Proof.get_goal (Toplevel.proof_of (state ())))  | 
|
335  | 
handle Toplevel.UNDEF => error "No goal present";  | 
|
336  | 
||
| 15830 | 337  | 
fun main () = gen_main false false;  | 
338  | 
fun loop () = gen_loop false false;  | 
|
339  | 
fun sync_main () = gen_main true true;  | 
|
340  | 
fun sync_loop () = gen_loop true true;  | 
|
| 18684 | 341  | 
val toplevel = Toplevel.program;  | 
| 15830 | 342  | 
end;  | 
| 5829 | 343  | 
|
344  | 
||
| 6373 | 345  | 
(*final declarations of this structure!*)  | 
| 15531 | 346  | 
val command = parser false NONE;  | 
347  | 
val markup_command = parser false o SOME;  | 
|
348  | 
val improper_command = parser true NONE;  | 
|
| 6685 | 349  | 
|
| 5829 | 350  | 
end;  | 
351  | 
||
| 6199 | 352  | 
(*setup theory syntax dependent operations*)  | 
353  | 
ThyLoad.deps_thy_fn := OuterSyntax.deps_thy;  | 
|
354  | 
ThyLoad.load_thy_fn := OuterSyntax.load_thy;  | 
|
355  | 
structure ThyLoad: THY_LOAD = ThyLoad;  | 
|
356  | 
||
| 5829 | 357  | 
structure BasicOuterSyntax: BASIC_OUTER_SYNTAX = OuterSyntax;  | 
358  | 
open BasicOuterSyntax;  |