author | wenzelm |
Tue, 26 Apr 2011 15:56:15 +0200 | |
changeset 42473 | aca720fb3936 |
parent 42129 | c17508a61f49 |
child 43621 | e8858190cccd |
permissions | -rw-r--r-- |
5829 | 1 |
(* Title: Pure/Isar/outer_syntax.ML |
2 |
Author: Markus Wenzel, TU Muenchen |
|
3 |
||
27353
71c4dd53d4cb
moved global keywords from OuterSyntax to OuterKeyword, tuned interfaces;
wenzelm
parents:
26990
diff
changeset
|
4 |
The global Isabelle/Isar outer syntax. |
71c4dd53d4cb
moved global keywords from OuterSyntax to OuterKeyword, tuned interfaces;
wenzelm
parents:
26990
diff
changeset
|
5 |
|
71c4dd53d4cb
moved global keywords from OuterSyntax to OuterKeyword, tuned interfaces;
wenzelm
parents:
26990
diff
changeset
|
6 |
Note: the syntax for files is statically determined at the very |
71c4dd53d4cb
moved global keywords from OuterSyntax to OuterKeyword, tuned interfaces;
wenzelm
parents:
26990
diff
changeset
|
7 |
beginning; for interactive processing it may change dynamically. |
5829 | 8 |
*) |
9 |
||
10 |
signature OUTER_SYNTAX = |
|
11 |
sig |
|
36950 | 12 |
val command: string -> string -> Keyword.T -> |
29311 | 13 |
(Toplevel.transition -> Toplevel.transition) parser -> unit |
37216
3165bc303f66
modernized some structure names, keeping a few legacy aliases;
wenzelm
parents:
36959
diff
changeset
|
14 |
val markup_command: Thy_Output.markup -> string -> string -> Keyword.T -> |
29311 | 15 |
(Toplevel.transition -> Toplevel.transition) parser -> unit |
36950 | 16 |
val improper_command: string -> string -> Keyword.T -> |
29311 | 17 |
(Toplevel.transition -> Toplevel.transition) parser -> unit |
18 |
val internal_command: string -> (Toplevel.transition -> Toplevel.transition) parser -> unit |
|
36950 | 19 |
val local_theory': string -> string -> Keyword.T -> |
29380 | 20 |
(bool -> local_theory -> local_theory) parser -> unit |
36950 | 21 |
val local_theory: string -> string -> Keyword.T -> |
29311 | 22 |
(local_theory -> local_theory) parser -> unit |
36950 | 23 |
val local_theory_to_proof': string -> string -> Keyword.T -> |
29311 | 24 |
(bool -> local_theory -> Proof.state) parser -> unit |
36950 | 25 |
val local_theory_to_proof: string -> string -> Keyword.T -> |
29311 | 26 |
(local_theory -> Proof.state) parser -> unit |
5883 | 27 |
val print_outer_syntax: unit -> unit |
36959
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents:
36955
diff
changeset
|
28 |
val scan: Position.T -> string -> Token.T list |
25580 | 29 |
val parse: Position.T -> string -> Toplevel.transition list |
26431 | 30 |
val process_file: Path.T -> theory -> theory |
26600 | 31 |
type isar |
38253
3d4e521014f7
Isabelle_Process: separate input fifo for commands (still using the old tty protocol);
wenzelm
parents:
38236
diff
changeset
|
32 |
val isar: TextIO.instream -> bool -> isar |
27839
0be8644c45eb
Symbol.source/OuterLex.source: more explicit do_recover argument;
wenzelm
parents:
27831
diff
changeset
|
33 |
val prepare_command: Position.T -> string -> Toplevel.transition |
42129
c17508a61f49
present theory content as future, depending on intermediate proof state futures -- potential to reduce memory requirements and improve parallelization;
wenzelm
parents:
42012
diff
changeset
|
34 |
val load_thy: string -> (Path.T option -> theory) -> Position.T -> string -> theory * unit future |
5829 | 35 |
end; |
36 |
||
36953
2af1ad9aa1a3
renamed structure OuterSyntax to Outer_Syntax, keeping the old name as alias for some time;
wenzelm
parents:
36950
diff
changeset
|
37 |
structure Outer_Syntax: OUTER_SYNTAX = |
5829 | 38 |
struct |
39 |
||
40 |
(** outer syntax **) |
|
41 |
||
29311 | 42 |
(* command parsers *) |
5829 | 43 |
|
29311 | 44 |
datatype command = Command of |
24868 | 45 |
{comment: string, |
37216
3165bc303f66
modernized some structure names, keeping a few legacy aliases;
wenzelm
parents:
36959
diff
changeset
|
46 |
markup: Thy_Output.markup option, |
24868 | 47 |
int_only: bool, |
29311 | 48 |
parse: (Toplevel.transition -> Toplevel.transition) parser}; |
5829 | 49 |
|
29311 | 50 |
fun make_command comment markup int_only parse = |
51 |
Command {comment = comment, markup = markup, int_only = int_only, parse = parse}; |
|
5829 | 52 |
|
53 |
||
54 |
(* parse command *) |
|
55 |
||
6860 | 56 |
local |
6199 | 57 |
|
14925
0f86a8a694f8
added read (provides transition names and sources);
wenzelm
parents:
14687
diff
changeset
|
58 |
fun terminate false = Scan.succeed () |
36950 | 59 |
| terminate true = Parse.group "end of input" (Scan.option Parse.sync -- Parse.semicolon >> K ()); |
14925
0f86a8a694f8
added read (provides transition names and sources);
wenzelm
parents:
14687
diff
changeset
|
60 |
|
26620 | 61 |
fun body cmd (name, _) = |
7026 | 62 |
(case cmd name of |
29311 | 63 |
SOME (Command {int_only, parse, ...}) => |
36950 | 64 |
Parse.!!! (Scan.prompt (name ^ "# ") (Parse.tags |-- parse >> pair int_only)) |
37852
a902f158b4fc
eliminated old-style sys_error/SYS_ERROR in favour of exception Fail -- after careful checking that there is no overlap with existing handling of that;
wenzelm
parents:
37713
diff
changeset
|
65 |
| NONE => raise Fail ("No parser for outer syntax command " ^ quote name)); |
6860 | 66 |
|
67 |
in |
|
5829 | 68 |
|
26620 | 69 |
fun parse_command do_terminate cmd = |
36950 | 70 |
Parse.semicolon >> K NONE || |
71 |
Parse.sync >> K NONE || |
|
72 |
(Parse.position Parse.command :-- body cmd) --| terminate do_terminate |
|
6860 | 73 |
>> (fn ((name, pos), (int_only, f)) => |
15531 | 74 |
SOME (Toplevel.empty |> Toplevel.name name |> Toplevel.position pos |> |
6860 | 75 |
Toplevel.interactive int_only |> f)); |
5829 | 76 |
|
6199 | 77 |
end; |
78 |
||
5829 | 79 |
|
80 |
||
9132 | 81 |
(** global outer syntax **) |
5829 | 82 |
|
7026 | 83 |
local |
84 |
||
32738 | 85 |
val global_commands = Unsynchronized.ref (Symtab.empty: command Symtab.table); |
37216
3165bc303f66
modernized some structure names, keeping a few legacy aliases;
wenzelm
parents:
36959
diff
changeset
|
86 |
val global_markups = Unsynchronized.ref ([]: (string * Thy_Output.markup) list); |
5952 | 87 |
|
29311 | 88 |
fun change_commands f = CRITICAL (fn () => |
32738 | 89 |
(Unsynchronized.change global_commands f; |
23939 | 90 |
global_markups := |
29311 | 91 |
Symtab.fold (fn (name, Command {markup = SOME m, ...}) => cons (name, m) | _ => I) |
92 |
(! global_commands) [])); |
|
6722 | 93 |
|
7026 | 94 |
in |
95 |
||
9132 | 96 |
(* access current syntax *) |
7026 | 97 |
|
33223 | 98 |
fun get_commands () = ! global_commands; |
99 |
fun get_markups () = ! global_markups; |
|
7026 | 100 |
|
29311 | 101 |
fun get_command () = Symtab.lookup (get_commands ()); |
36950 | 102 |
fun get_syntax () = CRITICAL (fn () => (Keyword.get_lexicons (), get_command ())); |
7789 | 103 |
|
24868 | 104 |
fun is_markup kind name = AList.lookup (op =) (get_markups ()) name = SOME kind; |
5829 | 105 |
|
106 |
||
107 |
(* augment syntax *) |
|
108 |
||
29311 | 109 |
fun add_command name kind cmd = CRITICAL (fn () => |
36950 | 110 |
(Keyword.command name kind; |
29311 | 111 |
if not (Symtab.defined (get_commands ()) name) then () |
24868 | 112 |
else warning ("Redefining outer syntax command " ^ quote name); |
29311 | 113 |
change_commands (Symtab.update (name, cmd)))); |
5829 | 114 |
|
24868 | 115 |
fun command name comment kind parse = |
29311 | 116 |
add_command name kind (make_command comment NONE false parse); |
5829 | 117 |
|
24868 | 118 |
fun markup_command markup name comment kind parse = |
29311 | 119 |
add_command name kind (make_command comment (SOME markup) false parse); |
24868 | 120 |
|
121 |
fun improper_command name comment kind parse = |
|
29311 | 122 |
add_command name kind (make_command comment NONE true parse); |
7026 | 123 |
|
124 |
end; |
|
5829 | 125 |
|
29311 | 126 |
fun internal_command name parse = |
36950 | 127 |
command name "(internal)" Keyword.control (parse >> (fn tr => Toplevel.no_timing o tr)); |
29311 | 128 |
|
5829 | 129 |
|
26990 | 130 |
(* local_theory commands *) |
131 |
||
132 |
fun local_theory_command do_print trans name comment kind parse = |
|
36950 | 133 |
command name comment kind (Parse.opt_target -- parse |
26990 | 134 |
>> (fn (loc, f) => (if do_print then Toplevel.print else I) o trans loc f)); |
135 |
||
29380 | 136 |
val local_theory' = local_theory_command false Toplevel.local_theory'; |
29311 | 137 |
val local_theory = local_theory_command false Toplevel.local_theory; |
26990 | 138 |
val local_theory_to_proof' = local_theory_command true Toplevel.local_theory_to_proof'; |
29311 | 139 |
val local_theory_to_proof = local_theory_command true Toplevel.local_theory_to_proof; |
26990 | 140 |
|
141 |
||
24872 | 142 |
(* inspect syntax *) |
7026 | 143 |
|
29311 | 144 |
fun dest_commands () = |
145 |
get_commands () |> Symtab.dest |> sort_wrt #1 |
|
146 |
|> map (fn (name, Command {comment, int_only, ...}) => (name, comment, int_only)); |
|
5829 | 147 |
|
9223 | 148 |
fun print_outer_syntax () = |
7026 | 149 |
let |
27353
71c4dd53d4cb
moved global keywords from OuterSyntax to OuterKeyword, tuned interfaces;
wenzelm
parents:
26990
diff
changeset
|
150 |
fun pretty_cmd (name, comment, _) = |
7026 | 151 |
Pretty.block [Pretty.str (name ^ ":"), Pretty.brk 2, Pretty.str comment]; |
29311 | 152 |
val (int_cmds, cmds) = List.partition #3 (dest_commands ()); |
7026 | 153 |
in |
36950 | 154 |
[Pretty.strs ("syntax keywords:" :: map quote (Keyword.dest_keywords ())), |
18326 | 155 |
Pretty.big_list "commands:" (map pretty_cmd cmds), |
156 |
Pretty.big_list "interactive-only commands:" (map pretty_cmd int_cmds)] |
|
9223 | 157 |
|> Pretty.chunks |> Pretty.writeln |
7026 | 158 |
end; |
5829 | 159 |
|
160 |
||
161 |
||
9132 | 162 |
(** toplevel parsing **) |
5829 | 163 |
|
9132 | 164 |
(* basic sources *) |
6860 | 165 |
|
26620 | 166 |
fun toplevel_source term do_recover cmd src = |
9132 | 167 |
let |
168 |
val no_terminator = |
|
36959
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents:
36955
diff
changeset
|
169 |
Scan.unless Parse.semicolon (Scan.one (Token.not_sync andf Token.not_eof)); |
23682
cf4773532006
nested source: explicit interactive flag for recover avoids duplicate errors;
wenzelm
parents:
23679
diff
changeset
|
170 |
fun recover int = |
cf4773532006
nested source: explicit interactive flag for recover avoids duplicate errors;
wenzelm
parents:
23679
diff
changeset
|
171 |
(int, fn _ => Scan.prompt "recover# " (Scan.repeat no_terminator) >> K [NONE]); |
9132 | 172 |
in |
173 |
src |
|
36959
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents:
36955
diff
changeset
|
174 |
|> Token.source_proper |
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents:
36955
diff
changeset
|
175 |
|> Source.source Token.stopper |
36950 | 176 |
(Scan.bulk (Parse.$$$ "--" -- Parse.!!! Parse.doc_source >> K NONE || Parse.not_eof >> SOME)) |
23682
cf4773532006
nested source: explicit interactive flag for recover avoids duplicate errors;
wenzelm
parents:
23679
diff
changeset
|
177 |
(Option.map recover do_recover) |
19482
9f11af8f7ef9
tuned basic list operators (flat, maps, map_filter);
wenzelm
parents:
19060
diff
changeset
|
178 |
|> Source.map_filter I |
36959
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents:
36955
diff
changeset
|
179 |
|> Source.source Token.stopper |
36950 | 180 |
(Scan.bulk (fn xs => Parse.!!! (parse_command term (cmd ())) xs)) |
23682
cf4773532006
nested source: explicit interactive flag for recover avoids duplicate errors;
wenzelm
parents:
23679
diff
changeset
|
181 |
(Option.map recover do_recover) |
19482
9f11af8f7ef9
tuned basic list operators (flat, maps, map_filter);
wenzelm
parents:
19060
diff
changeset
|
182 |
|> Source.map_filter I |
9132 | 183 |
end; |
5829 | 184 |
|
7746 | 185 |
|
25580 | 186 |
(* off-line scanning/parsing *) |
14925
0f86a8a694f8
added read (provides transition names and sources);
wenzelm
parents:
14687
diff
changeset
|
187 |
|
27839
0be8644c45eb
Symbol.source/OuterLex.source: more explicit do_recover argument;
wenzelm
parents:
27831
diff
changeset
|
188 |
fun scan pos str = |
16195 | 189 |
Source.of_string str |
40523
1050315f6ee2
simplified/robustified treatment of malformed symbols, which are now fully internalized (total Symbol.explode etc.);
wenzelm
parents:
38422
diff
changeset
|
190 |
|> Symbol.source |
36959
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents:
36955
diff
changeset
|
191 |
|> Token.source {do_recover = SOME false} Keyword.get_lexicons pos |
16195 | 192 |
|> Source.exhaust; |
193 |
||
25580 | 194 |
fun parse pos str = |
195 |
Source.of_string str |
|
40523
1050315f6ee2
simplified/robustified treatment of malformed symbols, which are now fully internalized (total Symbol.explode etc.);
wenzelm
parents:
38422
diff
changeset
|
196 |
|> Symbol.source |
36959
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents:
36955
diff
changeset
|
197 |
|> Token.source {do_recover = SOME false} Keyword.get_lexicons pos |
29311 | 198 |
|> toplevel_source false NONE get_command |
25580 | 199 |
|> Source.exhaust; |
200 |
||
14091 | 201 |
|
26431 | 202 |
(* process file *) |
203 |
||
204 |
fun process_file path thy = |
|
205 |
let |
|
26881 | 206 |
val trs = parse (Path.position path) (File.read path); |
41536
47fef6afe756
Toplevel.init_theory: maintain optional master directory, to allow bypassing global Thy_Load.master_path;
wenzelm
parents:
41484
diff
changeset
|
207 |
val init = Toplevel.init_theory NONE "" (K thy) Toplevel.empty; |
28424
fc6ce1c4d5b7
simplified process_file, eliminated Toplevel.excursion;
wenzelm
parents:
27872
diff
changeset
|
208 |
val result = fold Toplevel.command (init :: trs) Toplevel.toplevel; |
fc6ce1c4d5b7
simplified process_file, eliminated Toplevel.excursion;
wenzelm
parents:
27872
diff
changeset
|
209 |
in |
fc6ce1c4d5b7
simplified process_file, eliminated Toplevel.excursion;
wenzelm
parents:
27872
diff
changeset
|
210 |
(case (Toplevel.is_theory result, Toplevel.generic_theory_of result) of |
fc6ce1c4d5b7
simplified process_file, eliminated Toplevel.excursion;
wenzelm
parents:
27872
diff
changeset
|
211 |
(true, Context.Theory thy') => thy' |
fc6ce1c4d5b7
simplified process_file, eliminated Toplevel.excursion;
wenzelm
parents:
27872
diff
changeset
|
212 |
| _ => error "Bad result state: global theory expected") |
fc6ce1c4d5b7
simplified process_file, eliminated Toplevel.excursion;
wenzelm
parents:
27872
diff
changeset
|
213 |
end; |
26431 | 214 |
|
215 |
||
24868 | 216 |
(* interactive source of toplevel transformers *) |
217 |
||
26600 | 218 |
type isar = |
219 |
(Toplevel.transition, (Toplevel.transition option, |
|
36959
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents:
36955
diff
changeset
|
220 |
(Token.T, (Token.T option, (Token.T, (Token.T, |
30573 | 221 |
(Symbol_Pos.T, Position.T * (Symbol.symbol, (string, unit) Source.source) |
27770 | 222 |
Source.source) Source.source) Source.source) Source.source) |
223 |
Source.source) Source.source) Source.source) Source.source; |
|
26600 | 224 |
|
38253
3d4e521014f7
Isabelle_Process: separate input fifo for commands (still using the old tty protocol);
wenzelm
parents:
38236
diff
changeset
|
225 |
fun isar in_stream term : isar = |
3d4e521014f7
Isabelle_Process: separate input fifo for commands (still using the old tty protocol);
wenzelm
parents:
38236
diff
changeset
|
226 |
Source.tty in_stream |
40523
1050315f6ee2
simplified/robustified treatment of malformed symbols, which are now fully internalized (total Symbol.explode etc.);
wenzelm
parents:
38422
diff
changeset
|
227 |
|> Symbol.source |
36959
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents:
36955
diff
changeset
|
228 |
|> Token.source {do_recover = SOME true} Keyword.get_lexicons Position.none |
29311 | 229 |
|> toplevel_source term (SOME true) get_command; |
24868 | 230 |
|
231 |
||
27839
0be8644c45eb
Symbol.source/OuterLex.source: more explicit do_recover argument;
wenzelm
parents:
27831
diff
changeset
|
232 |
(* prepare toplevel commands -- fail-safe *) |
0be8644c45eb
Symbol.source/OuterLex.source: more explicit do_recover argument;
wenzelm
parents:
27831
diff
changeset
|
233 |
|
0be8644c45eb
Symbol.source/OuterLex.source: more explicit do_recover argument;
wenzelm
parents:
27831
diff
changeset
|
234 |
val not_singleton = "Exactly one command expected"; |
0be8644c45eb
Symbol.source/OuterLex.source: more explicit do_recover argument;
wenzelm
parents:
27831
diff
changeset
|
235 |
|
29311 | 236 |
fun prepare_span commands span = |
27839
0be8644c45eb
Symbol.source/OuterLex.source: more explicit do_recover argument;
wenzelm
parents:
27831
diff
changeset
|
237 |
let |
41484 | 238 |
val range_pos = Position.set_range (Thy_Syntax.span_range span); |
37216
3165bc303f66
modernized some structure names, keeping a few legacy aliases;
wenzelm
parents:
36959
diff
changeset
|
239 |
val toks = Thy_Syntax.span_content span; |
3165bc303f66
modernized some structure names, keeping a few legacy aliases;
wenzelm
parents:
36959
diff
changeset
|
240 |
val _ = List.app Thy_Syntax.report_token toks; |
27839
0be8644c45eb
Symbol.source/OuterLex.source: more explicit do_recover argument;
wenzelm
parents:
27831
diff
changeset
|
241 |
in |
29311 | 242 |
(case Source.exhaust (toplevel_source false NONE (K commands) (Source.of_list toks)) of |
37713
c82cf6e11669
Outer_Syntax.prepare_command: disallow control commands here, and consequently in Isar documents;
wenzelm
parents:
37216
diff
changeset
|
243 |
[tr] => |
c82cf6e11669
Outer_Syntax.prepare_command: disallow control commands here, and consequently in Isar documents;
wenzelm
parents:
37216
diff
changeset
|
244 |
if Keyword.is_control (Toplevel.name_of tr) then |
c82cf6e11669
Outer_Syntax.prepare_command: disallow control commands here, and consequently in Isar documents;
wenzelm
parents:
37216
diff
changeset
|
245 |
(Toplevel.malformed range_pos "Illegal control command", true) |
c82cf6e11669
Outer_Syntax.prepare_command: disallow control commands here, and consequently in Isar documents;
wenzelm
parents:
37216
diff
changeset
|
246 |
else (tr, true) |
27839
0be8644c45eb
Symbol.source/OuterLex.source: more explicit do_recover argument;
wenzelm
parents:
27831
diff
changeset
|
247 |
| [] => (Toplevel.ignored range_pos, false) |
0be8644c45eb
Symbol.source/OuterLex.source: more explicit do_recover argument;
wenzelm
parents:
27831
diff
changeset
|
248 |
| _ => (Toplevel.malformed range_pos not_singleton, true)) |
0be8644c45eb
Symbol.source/OuterLex.source: more explicit do_recover argument;
wenzelm
parents:
27831
diff
changeset
|
249 |
handle ERROR msg => (Toplevel.malformed range_pos msg, true) |
0be8644c45eb
Symbol.source/OuterLex.source: more explicit do_recover argument;
wenzelm
parents:
27831
diff
changeset
|
250 |
end; |
0be8644c45eb
Symbol.source/OuterLex.source: more explicit do_recover argument;
wenzelm
parents:
27831
diff
changeset
|
251 |
|
38422
f96394dba335
rename "unit" to "atom", to avoid confusion with the unit type;
wenzelm
parents:
38253
diff
changeset
|
252 |
fun prepare_atom commands init (cmd, proof, proper_proof) = |
28436
4faf705a177d
load_thy: more precise treatment of improper cmd or proof (notably 'oops');
wenzelm
parents:
28432
diff
changeset
|
253 |
let |
37977
3ceccd415145
simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents:
37953
diff
changeset
|
254 |
val (tr, proper_cmd) = prepare_span commands cmd |>> Toplevel.modify_init init; |
29311 | 255 |
val proof_trs = map (prepare_span commands) proof |> filter #2 |> map #1; |
28436
4faf705a177d
load_thy: more precise treatment of improper cmd or proof (notably 'oops');
wenzelm
parents:
28432
diff
changeset
|
256 |
in |
4faf705a177d
load_thy: more precise treatment of improper cmd or proof (notably 'oops');
wenzelm
parents:
28432
diff
changeset
|
257 |
if proper_cmd andalso proper_proof then [(tr, proof_trs)] |
4faf705a177d
load_thy: more precise treatment of improper cmd or proof (notably 'oops');
wenzelm
parents:
28432
diff
changeset
|
258 |
else map (rpair []) (if proper_cmd then tr :: proof_trs else proof_trs) |
4faf705a177d
load_thy: more precise treatment of improper cmd or proof (notably 'oops');
wenzelm
parents:
28432
diff
changeset
|
259 |
end; |
28432
944cb67f809a
load_thy: Toplevel.excursion based on units of command/proof pairs;
wenzelm
parents:
28424
diff
changeset
|
260 |
|
27839
0be8644c45eb
Symbol.source/OuterLex.source: more explicit do_recover argument;
wenzelm
parents:
27831
diff
changeset
|
261 |
fun prepare_command pos str = |
29311 | 262 |
let val (lexs, commands) = get_syntax () in |
37216
3165bc303f66
modernized some structure names, keeping a few legacy aliases;
wenzelm
parents:
36959
diff
changeset
|
263 |
(case Thy_Syntax.parse_spans lexs pos str of |
29311 | 264 |
[span] => #1 (prepare_span commands span) |
27839
0be8644c45eb
Symbol.source/OuterLex.source: more explicit do_recover argument;
wenzelm
parents:
27831
diff
changeset
|
265 |
| _ => Toplevel.malformed pos not_singleton) |
0be8644c45eb
Symbol.source/OuterLex.source: more explicit do_recover argument;
wenzelm
parents:
27831
diff
changeset
|
266 |
end; |
0be8644c45eb
Symbol.source/OuterLex.source: more explicit do_recover argument;
wenzelm
parents:
27831
diff
changeset
|
267 |
|
0be8644c45eb
Symbol.source/OuterLex.source: more explicit do_recover argument;
wenzelm
parents:
27831
diff
changeset
|
268 |
|
26611 | 269 |
(* load_thy *) |
7746 | 270 |
|
37977
3ceccd415145
simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents:
37953
diff
changeset
|
271 |
fun load_thy name init pos text = |
7683 | 272 |
let |
29311 | 273 |
val (lexs, commands) = get_syntax (); |
42012
2c3fe3cbebae
structure Timing: covers former start_timing/end_timing and Output.timeit etc;
wenzelm
parents:
41711
diff
changeset
|
274 |
val time = ! Toplevel.timing; |
23866
5295671034f8
moved deps_thy to ThyLoad (independent of outer syntax);
wenzelm
parents:
23796
diff
changeset
|
275 |
|
17932 | 276 |
val _ = Present.init_theory name; |
27855
b1bf607e06c2
load_thy: no untabify (preserve position information!), present spans instead of verbatim source;
wenzelm
parents:
27839
diff
changeset
|
277 |
|
37902
4e7864f3643d
deps_thy/load_thy: store compact text to reduce space by factor 12;
wenzelm
parents:
37873
diff
changeset
|
278 |
val toks = Source.exhausted (Thy_Syntax.token_source lexs pos (Source.of_string text)); |
37216
3165bc303f66
modernized some structure names, keeping a few legacy aliases;
wenzelm
parents:
36959
diff
changeset
|
279 |
val spans = Source.exhaust (Thy_Syntax.span_source toks); |
38236
d8c7be27e01d
explicitly distinguish Output.status (essential feedback) vs. Output.report (useful markup);
wenzelm
parents:
37977
diff
changeset
|
280 |
val _ = List.app Thy_Syntax.report_span spans; (* FIXME ?? *) |
38422
f96394dba335
rename "unit" to "atom", to avoid confusion with the unit type;
wenzelm
parents:
38253
diff
changeset
|
281 |
val atoms = Source.exhaust (Thy_Syntax.atom_source (Source.of_list spans)) |
41711 | 282 |
|> Par_List.map_name "Outer_Syntax.prepare_atom" (prepare_atom commands init) |> flat; |
23866
5295671034f8
moved deps_thy to ThyLoad (independent of outer syntax);
wenzelm
parents:
23796
diff
changeset
|
283 |
|
27855
b1bf607e06c2
load_thy: no untabify (preserve position information!), present spans instead of verbatim source;
wenzelm
parents:
27839
diff
changeset
|
284 |
val _ = Present.theory_source name |
37216
3165bc303f66
modernized some structure names, keeping a few legacy aliases;
wenzelm
parents:
36959
diff
changeset
|
285 |
(fn () => HTML.html_mode (implode o map Thy_Syntax.present_span) spans); |
27855
b1bf607e06c2
load_thy: no untabify (preserve position information!), present spans instead of verbatim source;
wenzelm
parents:
27839
diff
changeset
|
286 |
|
23866
5295671034f8
moved deps_thy to ThyLoad (independent of outer syntax);
wenzelm
parents:
23796
diff
changeset
|
287 |
val _ = if time then writeln ("\n**** Starting theory " ^ quote name ^ " ****") else (); |
38422
f96394dba335
rename "unit" to "atom", to avoid confusion with the unit type;
wenzelm
parents:
38253
diff
changeset
|
288 |
val (results, thy) = cond_timeit time "" (fn () => Toplevel.excursion atoms); |
23866
5295671034f8
moved deps_thy to ThyLoad (independent of outer syntax);
wenzelm
parents:
23796
diff
changeset
|
289 |
val _ = if time then writeln ("**** Finished theory " ^ quote name ^ " ****\n") else (); |
29428
3ab54b42ded8
load_thy: explicit after_load phase for presentation;
wenzelm
parents:
29380
diff
changeset
|
290 |
|
42129
c17508a61f49
present theory content as future, depending on intermediate proof state futures -- potential to reduce memory requirements and improve parallelization;
wenzelm
parents:
42012
diff
changeset
|
291 |
val present = |
c17508a61f49
present theory content as future, depending on intermediate proof state futures -- potential to reduce memory requirements and improve parallelization;
wenzelm
parents:
42012
diff
changeset
|
292 |
singleton (Future.cond_forks {name = "Outer_Syntax.present:" ^ name, group = NONE, |
c17508a61f49
present theory content as future, depending on intermediate proof state futures -- potential to reduce memory requirements and improve parallelization;
wenzelm
parents:
42012
diff
changeset
|
293 |
deps = map Future.task_of results, pri = 0}) |
c17508a61f49
present theory content as future, depending on intermediate proof state futures -- potential to reduce memory requirements and improve parallelization;
wenzelm
parents:
42012
diff
changeset
|
294 |
(fn () => |
c17508a61f49
present theory content as future, depending on intermediate proof state futures -- potential to reduce memory requirements and improve parallelization;
wenzelm
parents:
42012
diff
changeset
|
295 |
Thy_Output.present_thy (#1 lexs) Keyword.command_tags is_markup |
c17508a61f49
present theory content as future, depending on intermediate proof state futures -- potential to reduce memory requirements and improve parallelization;
wenzelm
parents:
42012
diff
changeset
|
296 |
(maps Future.join results) toks |
c17508a61f49
present theory content as future, depending on intermediate proof state futures -- potential to reduce memory requirements and improve parallelization;
wenzelm
parents:
42012
diff
changeset
|
297 |
|> Buffer.content |
c17508a61f49
present theory content as future, depending on intermediate proof state futures -- potential to reduce memory requirements and improve parallelization;
wenzelm
parents:
42012
diff
changeset
|
298 |
|> Present.theory_output name); |
c17508a61f49
present theory content as future, depending on intermediate proof state futures -- potential to reduce memory requirements and improve parallelization;
wenzelm
parents:
42012
diff
changeset
|
299 |
|
c17508a61f49
present theory content as future, depending on intermediate proof state futures -- potential to reduce memory requirements and improve parallelization;
wenzelm
parents:
42012
diff
changeset
|
300 |
in (thy, present) end; |
23866
5295671034f8
moved deps_thy to ThyLoad (independent of outer syntax);
wenzelm
parents:
23796
diff
changeset
|
301 |
|
5829 | 302 |
end; |
36953
2af1ad9aa1a3
renamed structure OuterSyntax to Outer_Syntax, keeping the old name as alias for some time;
wenzelm
parents:
36950
diff
changeset
|
303 |