author | boehmes |
Wed, 12 May 2010 23:53:59 +0200 | |
changeset 36895 | a96f9793d9c5 |
parent 33223 | d27956b4d3b4 |
child 36950 | 75b8f26f2f07 |
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 |
|
29311 | 12 |
val command: string -> string -> OuterKeyword.T -> |
13 |
(Toplevel.transition -> Toplevel.transition) parser -> unit |
|
14 |
val markup_command: ThyOutput.markup -> string -> string -> OuterKeyword.T -> |
|
15 |
(Toplevel.transition -> Toplevel.transition) parser -> unit |
|
16 |
val improper_command: string -> string -> OuterKeyword.T -> |
|
17 |
(Toplevel.transition -> Toplevel.transition) parser -> unit |
|
18 |
val internal_command: string -> (Toplevel.transition -> Toplevel.transition) parser -> unit |
|
29380 | 19 |
val local_theory': string -> string -> OuterKeyword.T -> |
20 |
(bool -> local_theory -> local_theory) parser -> unit |
|
26990 | 21 |
val local_theory: string -> string -> OuterKeyword.T -> |
29311 | 22 |
(local_theory -> local_theory) parser -> unit |
26990 | 23 |
val local_theory_to_proof': string -> string -> OuterKeyword.T -> |
29311 | 24 |
(bool -> local_theory -> Proof.state) parser -> unit |
26990 | 25 |
val local_theory_to_proof: string -> string -> OuterKeyword.T -> |
29311 | 26 |
(local_theory -> Proof.state) parser -> unit |
5883 | 27 |
val print_outer_syntax: unit -> unit |
27839
0be8644c45eb
Symbol.source/OuterLex.source: more explicit do_recover argument;
wenzelm
parents:
27831
diff
changeset
|
28 |
val scan: Position.T -> string -> OuterLex.token list |
25580 | 29 |
val parse: Position.T -> string -> Toplevel.transition list |
26431 | 30 |
val process_file: Path.T -> theory -> theory |
26600 | 31 |
type isar |
32 |
val isar: 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 |
29428
3ab54b42ded8
load_thy: explicit after_load phase for presentation;
wenzelm
parents:
29380
diff
changeset
|
34 |
val load_thy: string -> Position.T -> string list -> bool -> unit -> unit |
5829 | 35 |
end; |
36 |
||
26600 | 37 |
structure OuterSyntax: OUTER_SYNTAX = |
5829 | 38 |
struct |
39 |
||
7750 | 40 |
structure T = OuterLex; |
6860 | 41 |
structure P = OuterParse; |
29311 | 42 |
type 'a parser = 'a P.parser; |
43 |
||
6860 | 44 |
|
5829 | 45 |
|
46 |
(** outer syntax **) |
|
47 |
||
29311 | 48 |
(* command parsers *) |
5829 | 49 |
|
29311 | 50 |
datatype command = Command of |
24868 | 51 |
{comment: string, |
52 |
markup: ThyOutput.markup option, |
|
53 |
int_only: bool, |
|
29311 | 54 |
parse: (Toplevel.transition -> Toplevel.transition) parser}; |
5829 | 55 |
|
29311 | 56 |
fun make_command comment markup int_only parse = |
57 |
Command {comment = comment, markup = markup, int_only = int_only, parse = parse}; |
|
5829 | 58 |
|
59 |
||
60 |
(* parse command *) |
|
61 |
||
6860 | 62 |
local |
6199 | 63 |
|
14925
0f86a8a694f8
added read (provides transition names and sources);
wenzelm
parents:
14687
diff
changeset
|
64 |
fun terminate false = Scan.succeed () |
0f86a8a694f8
added read (provides transition names and sources);
wenzelm
parents:
14687
diff
changeset
|
65 |
| 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
|
66 |
|
26620 | 67 |
fun body cmd (name, _) = |
7026 | 68 |
(case cmd name of |
29311 | 69 |
SOME (Command {int_only, parse, ...}) => |
26620 | 70 |
P.!!! (Scan.prompt (name ^ "# ") (P.tags |-- parse >> pair int_only)) |
15531 | 71 |
| NONE => sys_error ("no parser for outer syntax command " ^ quote name)); |
6860 | 72 |
|
73 |
in |
|
5829 | 74 |
|
26620 | 75 |
fun parse_command do_terminate cmd = |
15531 | 76 |
P.semicolon >> K NONE || |
77 |
P.sync >> K NONE || |
|
26620 | 78 |
(P.position P.command :-- body cmd) --| terminate do_terminate |
6860 | 79 |
>> (fn ((name, pos), (int_only, f)) => |
15531 | 80 |
SOME (Toplevel.empty |> Toplevel.name name |> Toplevel.position pos |> |
6860 | 81 |
Toplevel.interactive int_only |> f)); |
5829 | 82 |
|
6199 | 83 |
end; |
84 |
||
5829 | 85 |
|
86 |
||
9132 | 87 |
(** global outer syntax **) |
5829 | 88 |
|
7026 | 89 |
local |
90 |
||
32738 | 91 |
val global_commands = Unsynchronized.ref (Symtab.empty: command Symtab.table); |
92 |
val global_markups = Unsynchronized.ref ([]: (string * ThyOutput.markup) list); |
|
5952 | 93 |
|
29311 | 94 |
fun change_commands f = CRITICAL (fn () => |
32738 | 95 |
(Unsynchronized.change global_commands f; |
23939 | 96 |
global_markups := |
29311 | 97 |
Symtab.fold (fn (name, Command {markup = SOME m, ...}) => cons (name, m) | _ => I) |
98 |
(! global_commands) [])); |
|
6722 | 99 |
|
7026 | 100 |
in |
101 |
||
9132 | 102 |
(* access current syntax *) |
7026 | 103 |
|
33223 | 104 |
fun get_commands () = ! global_commands; |
105 |
fun get_markups () = ! global_markups; |
|
7026 | 106 |
|
29311 | 107 |
fun get_command () = Symtab.lookup (get_commands ()); |
108 |
fun get_syntax () = CRITICAL (fn () => (OuterKeyword.get_lexicons (), get_command ())); |
|
7789 | 109 |
|
24868 | 110 |
fun is_markup kind name = AList.lookup (op =) (get_markups ()) name = SOME kind; |
5829 | 111 |
|
112 |
||
113 |
(* augment syntax *) |
|
114 |
||
29311 | 115 |
fun add_command name kind cmd = CRITICAL (fn () => |
27353
71c4dd53d4cb
moved global keywords from OuterSyntax to OuterKeyword, tuned interfaces;
wenzelm
parents:
26990
diff
changeset
|
116 |
(OuterKeyword.command name kind; |
29311 | 117 |
if not (Symtab.defined (get_commands ()) name) then () |
24868 | 118 |
else warning ("Redefining outer syntax command " ^ quote name); |
29311 | 119 |
change_commands (Symtab.update (name, cmd)))); |
5829 | 120 |
|
24868 | 121 |
fun command name comment kind parse = |
29311 | 122 |
add_command name kind (make_command comment NONE false parse); |
5829 | 123 |
|
24868 | 124 |
fun markup_command markup name comment kind parse = |
29311 | 125 |
add_command name kind (make_command comment (SOME markup) false parse); |
24868 | 126 |
|
127 |
fun improper_command name comment kind parse = |
|
29311 | 128 |
add_command name kind (make_command comment NONE true parse); |
7026 | 129 |
|
130 |
end; |
|
5829 | 131 |
|
29311 | 132 |
fun internal_command name parse = |
133 |
command name "(internal)" OuterKeyword.control (parse >> (fn tr => Toplevel.no_timing o tr)); |
|
134 |
||
5829 | 135 |
|
26990 | 136 |
(* local_theory commands *) |
137 |
||
138 |
fun local_theory_command do_print trans name comment kind parse = |
|
139 |
command name comment kind (P.opt_target -- parse |
|
140 |
>> (fn (loc, f) => (if do_print then Toplevel.print else I) o trans loc f)); |
|
141 |
||
29380 | 142 |
val local_theory' = local_theory_command false Toplevel.local_theory'; |
29311 | 143 |
val local_theory = local_theory_command false Toplevel.local_theory; |
26990 | 144 |
val local_theory_to_proof' = local_theory_command true Toplevel.local_theory_to_proof'; |
29311 | 145 |
val local_theory_to_proof = local_theory_command true Toplevel.local_theory_to_proof; |
26990 | 146 |
|
147 |
||
24872 | 148 |
(* inspect syntax *) |
7026 | 149 |
|
29311 | 150 |
fun dest_commands () = |
151 |
get_commands () |> Symtab.dest |> sort_wrt #1 |
|
152 |
|> map (fn (name, Command {comment, int_only, ...}) => (name, comment, int_only)); |
|
5829 | 153 |
|
9223 | 154 |
fun print_outer_syntax () = |
7026 | 155 |
let |
27353
71c4dd53d4cb
moved global keywords from OuterSyntax to OuterKeyword, tuned interfaces;
wenzelm
parents:
26990
diff
changeset
|
156 |
fun pretty_cmd (name, comment, _) = |
7026 | 157 |
Pretty.block [Pretty.str (name ^ ":"), Pretty.brk 2, Pretty.str comment]; |
29311 | 158 |
val (int_cmds, cmds) = List.partition #3 (dest_commands ()); |
7026 | 159 |
in |
27353
71c4dd53d4cb
moved global keywords from OuterSyntax to OuterKeyword, tuned interfaces;
wenzelm
parents:
26990
diff
changeset
|
160 |
[Pretty.strs ("syntax keywords:" :: map quote (OuterKeyword.dest_keywords ())), |
18326 | 161 |
Pretty.big_list "commands:" (map pretty_cmd cmds), |
162 |
Pretty.big_list "interactive-only commands:" (map pretty_cmd int_cmds)] |
|
9223 | 163 |
|> Pretty.chunks |> Pretty.writeln |
7026 | 164 |
end; |
5829 | 165 |
|
166 |
||
167 |
||
9132 | 168 |
(** toplevel parsing **) |
5829 | 169 |
|
9132 | 170 |
(* basic sources *) |
6860 | 171 |
|
26620 | 172 |
fun toplevel_source term do_recover cmd src = |
9132 | 173 |
let |
174 |
val no_terminator = |
|
175 |
Scan.unless P.semicolon (Scan.one (T.not_sync andf T.not_eof)); |
|
23682
cf4773532006
nested source: explicit interactive flag for recover avoids duplicate errors;
wenzelm
parents:
23679
diff
changeset
|
176 |
fun recover int = |
cf4773532006
nested source: explicit interactive flag for recover avoids duplicate errors;
wenzelm
parents:
23679
diff
changeset
|
177 |
(int, fn _ => Scan.prompt "recover# " (Scan.repeat no_terminator) >> K [NONE]); |
9132 | 178 |
in |
179 |
src |
|
12876
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
10749
diff
changeset
|
180 |
|> T.source_proper |
9132 | 181 |
|> Source.source T.stopper |
27872
631371a02b8c
P.doc_source and P.ml_sorce for proper SymbolPos.text;
wenzelm
parents:
27855
diff
changeset
|
182 |
(Scan.bulk (P.$$$ "--" -- P.!!! P.doc_source >> K NONE || P.not_eof >> SOME)) |
23682
cf4773532006
nested source: explicit interactive flag for recover avoids duplicate errors;
wenzelm
parents:
23679
diff
changeset
|
183 |
(Option.map recover do_recover) |
19482
9f11af8f7ef9
tuned basic list operators (flat, maps, map_filter);
wenzelm
parents:
19060
diff
changeset
|
184 |
|> Source.map_filter I |
24868 | 185 |
|> Source.source T.stopper |
26620 | 186 |
(Scan.bulk (fn xs => P.!!! (parse_command term (cmd ())) xs)) |
23682
cf4773532006
nested source: explicit interactive flag for recover avoids duplicate errors;
wenzelm
parents:
23679
diff
changeset
|
187 |
(Option.map recover do_recover) |
19482
9f11af8f7ef9
tuned basic list operators (flat, maps, map_filter);
wenzelm
parents:
19060
diff
changeset
|
188 |
|> Source.map_filter I |
9132 | 189 |
end; |
5829 | 190 |
|
7746 | 191 |
|
25580 | 192 |
(* off-line scanning/parsing *) |
14925
0f86a8a694f8
added read (provides transition names and sources);
wenzelm
parents:
14687
diff
changeset
|
193 |
|
27839
0be8644c45eb
Symbol.source/OuterLex.source: more explicit do_recover argument;
wenzelm
parents:
27831
diff
changeset
|
194 |
fun scan pos str = |
16195 | 195 |
Source.of_string str |
27839
0be8644c45eb
Symbol.source/OuterLex.source: more explicit do_recover argument;
wenzelm
parents:
27831
diff
changeset
|
196 |
|> Symbol.source {do_recover = false} |
0be8644c45eb
Symbol.source/OuterLex.source: more explicit do_recover argument;
wenzelm
parents:
27831
diff
changeset
|
197 |
|> T.source {do_recover = SOME false} OuterKeyword.get_lexicons pos |
16195 | 198 |
|> Source.exhaust; |
199 |
||
25580 | 200 |
fun parse pos str = |
201 |
Source.of_string str |
|
27839
0be8644c45eb
Symbol.source/OuterLex.source: more explicit do_recover argument;
wenzelm
parents:
27831
diff
changeset
|
202 |
|> Symbol.source {do_recover = false} |
0be8644c45eb
Symbol.source/OuterLex.source: more explicit do_recover argument;
wenzelm
parents:
27831
diff
changeset
|
203 |
|> T.source {do_recover = SOME false} OuterKeyword.get_lexicons pos |
29311 | 204 |
|> toplevel_source false NONE get_command |
25580 | 205 |
|> Source.exhaust; |
206 |
||
14091 | 207 |
|
26431 | 208 |
(* process file *) |
209 |
||
210 |
fun process_file path thy = |
|
211 |
let |
|
26881 | 212 |
val trs = parse (Path.position path) (File.read path); |
28424
fc6ce1c4d5b7
simplified process_file, eliminated Toplevel.excursion;
wenzelm
parents:
27872
diff
changeset
|
213 |
val init = Toplevel.init_theory "" (K thy) (K ()) Toplevel.empty; |
fc6ce1c4d5b7
simplified process_file, eliminated Toplevel.excursion;
wenzelm
parents:
27872
diff
changeset
|
214 |
val result = fold Toplevel.command (init :: trs) Toplevel.toplevel; |
fc6ce1c4d5b7
simplified process_file, eliminated Toplevel.excursion;
wenzelm
parents:
27872
diff
changeset
|
215 |
in |
fc6ce1c4d5b7
simplified process_file, eliminated Toplevel.excursion;
wenzelm
parents:
27872
diff
changeset
|
216 |
(case (Toplevel.is_theory result, Toplevel.generic_theory_of result) of |
fc6ce1c4d5b7
simplified process_file, eliminated Toplevel.excursion;
wenzelm
parents:
27872
diff
changeset
|
217 |
(true, Context.Theory thy') => thy' |
fc6ce1c4d5b7
simplified process_file, eliminated Toplevel.excursion;
wenzelm
parents:
27872
diff
changeset
|
218 |
| _ => error "Bad result state: global theory expected") |
fc6ce1c4d5b7
simplified process_file, eliminated Toplevel.excursion;
wenzelm
parents:
27872
diff
changeset
|
219 |
end; |
26431 | 220 |
|
221 |
||
24868 | 222 |
(* interactive source of toplevel transformers *) |
223 |
||
26600 | 224 |
type isar = |
225 |
(Toplevel.transition, (Toplevel.transition option, |
|
226 |
(OuterLex.token, (OuterLex.token option, (OuterLex.token, (OuterLex.token, |
|
30573 | 227 |
(Symbol_Pos.T, Position.T * (Symbol.symbol, (string, unit) Source.source) |
27770 | 228 |
Source.source) Source.source) Source.source) Source.source) |
229 |
Source.source) Source.source) Source.source) Source.source; |
|
26600 | 230 |
|
231 |
fun isar term : isar = |
|
24868 | 232 |
Source.tty |
27839
0be8644c45eb
Symbol.source/OuterLex.source: more explicit do_recover argument;
wenzelm
parents:
27831
diff
changeset
|
233 |
|> Symbol.source {do_recover = true} |
0be8644c45eb
Symbol.source/OuterLex.source: more explicit do_recover argument;
wenzelm
parents:
27831
diff
changeset
|
234 |
|> T.source {do_recover = SOME true} OuterKeyword.get_lexicons Position.none |
29311 | 235 |
|> toplevel_source term (SOME true) get_command; |
24868 | 236 |
|
237 |
||
27839
0be8644c45eb
Symbol.source/OuterLex.source: more explicit do_recover argument;
wenzelm
parents:
27831
diff
changeset
|
238 |
(* prepare toplevel commands -- fail-safe *) |
0be8644c45eb
Symbol.source/OuterLex.source: more explicit do_recover argument;
wenzelm
parents:
27831
diff
changeset
|
239 |
|
0be8644c45eb
Symbol.source/OuterLex.source: more explicit do_recover argument;
wenzelm
parents:
27831
diff
changeset
|
240 |
val not_singleton = "Exactly one command expected"; |
0be8644c45eb
Symbol.source/OuterLex.source: more explicit do_recover argument;
wenzelm
parents:
27831
diff
changeset
|
241 |
|
29311 | 242 |
fun prepare_span commands span = |
27839
0be8644c45eb
Symbol.source/OuterLex.source: more explicit do_recover argument;
wenzelm
parents:
27831
diff
changeset
|
243 |
let |
29315
b074c05f00ad
renamed ThyEdit (in thy_edit.ML) to ThySyntax (in thy_syntax.ML);
wenzelm
parents:
29311
diff
changeset
|
244 |
val range_pos = Position.encode_range (ThySyntax.span_range span); |
b074c05f00ad
renamed ThyEdit (in thy_edit.ML) to ThySyntax (in thy_syntax.ML);
wenzelm
parents:
29311
diff
changeset
|
245 |
val toks = ThySyntax.span_content span; |
b074c05f00ad
renamed ThyEdit (in thy_edit.ML) to ThySyntax (in thy_syntax.ML);
wenzelm
parents:
29311
diff
changeset
|
246 |
val _ = List.app ThySyntax.report_token toks; |
27839
0be8644c45eb
Symbol.source/OuterLex.source: more explicit do_recover argument;
wenzelm
parents:
27831
diff
changeset
|
247 |
in |
29311 | 248 |
(case Source.exhaust (toplevel_source false NONE (K commands) (Source.of_list toks)) of |
27839
0be8644c45eb
Symbol.source/OuterLex.source: more explicit do_recover argument;
wenzelm
parents:
27831
diff
changeset
|
249 |
[tr] => (tr, true) |
0be8644c45eb
Symbol.source/OuterLex.source: more explicit do_recover argument;
wenzelm
parents:
27831
diff
changeset
|
250 |
| [] => (Toplevel.ignored range_pos, false) |
0be8644c45eb
Symbol.source/OuterLex.source: more explicit do_recover argument;
wenzelm
parents:
27831
diff
changeset
|
251 |
| _ => (Toplevel.malformed range_pos not_singleton, true)) |
0be8644c45eb
Symbol.source/OuterLex.source: more explicit do_recover argument;
wenzelm
parents:
27831
diff
changeset
|
252 |
handle ERROR msg => (Toplevel.malformed range_pos msg, true) |
0be8644c45eb
Symbol.source/OuterLex.source: more explicit do_recover argument;
wenzelm
parents:
27831
diff
changeset
|
253 |
end; |
0be8644c45eb
Symbol.source/OuterLex.source: more explicit do_recover argument;
wenzelm
parents:
27831
diff
changeset
|
254 |
|
29311 | 255 |
fun prepare_unit commands (cmd, proof, proper_proof) = |
28436
4faf705a177d
load_thy: more precise treatment of improper cmd or proof (notably 'oops');
wenzelm
parents:
28432
diff
changeset
|
256 |
let |
29311 | 257 |
val (tr, proper_cmd) = prepare_span commands cmd; |
258 |
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
|
259 |
in |
4faf705a177d
load_thy: more precise treatment of improper cmd or proof (notably 'oops');
wenzelm
parents:
28432
diff
changeset
|
260 |
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
|
261 |
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
|
262 |
end; |
28432
944cb67f809a
load_thy: Toplevel.excursion based on units of command/proof pairs;
wenzelm
parents:
28424
diff
changeset
|
263 |
|
27839
0be8644c45eb
Symbol.source/OuterLex.source: more explicit do_recover argument;
wenzelm
parents:
27831
diff
changeset
|
264 |
fun prepare_command pos str = |
29311 | 265 |
let val (lexs, commands) = get_syntax () in |
29315
b074c05f00ad
renamed ThyEdit (in thy_edit.ML) to ThySyntax (in thy_syntax.ML);
wenzelm
parents:
29311
diff
changeset
|
266 |
(case ThySyntax.parse_spans lexs pos str of |
29311 | 267 |
[span] => #1 (prepare_span commands span) |
27839
0be8644c45eb
Symbol.source/OuterLex.source: more explicit do_recover argument;
wenzelm
parents:
27831
diff
changeset
|
268 |
| _ => Toplevel.malformed pos not_singleton) |
0be8644c45eb
Symbol.source/OuterLex.source: more explicit do_recover argument;
wenzelm
parents:
27831
diff
changeset
|
269 |
end; |
0be8644c45eb
Symbol.source/OuterLex.source: more explicit do_recover argument;
wenzelm
parents:
27831
diff
changeset
|
270 |
|
0be8644c45eb
Symbol.source/OuterLex.source: more explicit do_recover argument;
wenzelm
parents:
27831
diff
changeset
|
271 |
|
26611 | 272 |
(* load_thy *) |
7746 | 273 |
|
27839
0be8644c45eb
Symbol.source/OuterLex.source: more explicit do_recover argument;
wenzelm
parents:
27831
diff
changeset
|
274 |
fun load_thy name pos text time = |
7683 | 275 |
let |
29311 | 276 |
val (lexs, commands) = get_syntax (); |
23866
5295671034f8
moved deps_thy to ThyLoad (independent of outer syntax);
wenzelm
parents:
23796
diff
changeset
|
277 |
|
17932 | 278 |
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
|
279 |
|
29315
b074c05f00ad
renamed ThyEdit (in thy_edit.ML) to ThySyntax (in thy_syntax.ML);
wenzelm
parents:
29311
diff
changeset
|
280 |
val toks = Source.exhausted (ThySyntax.token_source lexs pos (Source.of_list text)); |
b074c05f00ad
renamed ThyEdit (in thy_edit.ML) to ThySyntax (in thy_syntax.ML);
wenzelm
parents:
29311
diff
changeset
|
281 |
val spans = Source.exhaust (ThySyntax.span_source toks); |
b074c05f00ad
renamed ThyEdit (in thy_edit.ML) to ThySyntax (in thy_syntax.ML);
wenzelm
parents:
29311
diff
changeset
|
282 |
val _ = List.app ThySyntax.report_span spans; |
b074c05f00ad
renamed ThyEdit (in thy_edit.ML) to ThySyntax (in thy_syntax.ML);
wenzelm
parents:
29311
diff
changeset
|
283 |
val units = Source.exhaust (ThySyntax.unit_source (Source.of_list spans)) |
29311 | 284 |
|> maps (prepare_unit commands); |
23866
5295671034f8
moved deps_thy to ThyLoad (independent of outer syntax);
wenzelm
parents:
23796
diff
changeset
|
285 |
|
27855
b1bf607e06c2
load_thy: no untabify (preserve position information!), present spans instead of verbatim source;
wenzelm
parents:
27839
diff
changeset
|
286 |
val _ = Present.theory_source name |
29315
b074c05f00ad
renamed ThyEdit (in thy_edit.ML) to ThySyntax (in thy_syntax.ML);
wenzelm
parents:
29311
diff
changeset
|
287 |
(fn () => HTML.html_mode (implode o map ThySyntax.present_span) spans); |
27855
b1bf607e06c2
load_thy: no untabify (preserve position information!), present spans instead of verbatim source;
wenzelm
parents:
27839
diff
changeset
|
288 |
|
23866
5295671034f8
moved deps_thy to ThyLoad (independent of outer syntax);
wenzelm
parents:
23796
diff
changeset
|
289 |
val _ = if time then writeln ("\n**** Starting theory " ^ quote name ^ " ****") else (); |
29428
3ab54b42ded8
load_thy: explicit after_load phase for presentation;
wenzelm
parents:
29380
diff
changeset
|
290 |
val results = cond_timeit time "" (fn () => Toplevel.excursion units); |
23866
5295671034f8
moved deps_thy to ThyLoad (independent of outer syntax);
wenzelm
parents:
23796
diff
changeset
|
291 |
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
|
292 |
|
3ab54b42ded8
load_thy: explicit after_load phase for presentation;
wenzelm
parents:
29380
diff
changeset
|
293 |
fun after_load () = |
3ab54b42ded8
load_thy: explicit after_load phase for presentation;
wenzelm
parents:
29380
diff
changeset
|
294 |
ThyOutput.present_thy (#1 lexs) OuterKeyword.command_tags is_markup (Lazy.force results) toks |
3ab54b42ded8
load_thy: explicit after_load phase for presentation;
wenzelm
parents:
29380
diff
changeset
|
295 |
|> Buffer.content |
3ab54b42ded8
load_thy: explicit after_load phase for presentation;
wenzelm
parents:
29380
diff
changeset
|
296 |
|> Present.theory_output name; |
3ab54b42ded8
load_thy: explicit after_load phase for presentation;
wenzelm
parents:
29380
diff
changeset
|
297 |
in after_load end; |
23866
5295671034f8
moved deps_thy to ThyLoad (independent of outer syntax);
wenzelm
parents:
23796
diff
changeset
|
298 |
|
5829 | 299 |
end; |