author | wenzelm |
Wed, 28 May 2014 16:16:40 +0200 | |
changeset 57105 | bf5ddf4ec64b |
parent 57026 | 90a3e39be0ca |
child 57623 | 249c0297cf10 |
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 |
|
43711 | 12 |
type outer_syntax |
55448
e42a3fc18458
explicit indication that redefining outer syntax commands is not supposed to happen -- NB: interactive mode requires global change of syntax;
wenzelm
parents:
54734
diff
changeset
|
13 |
val batch_mode: bool Unsynchronized.ref |
43712
3c2c912af2ef
moved Outer_Syntax.load_thy to Thy_Load.load_thy;
wenzelm
parents:
43711
diff
changeset
|
14 |
val is_markup: outer_syntax -> Thy_Output.markup -> string -> bool |
43711 | 15 |
val get_syntax: unit -> (Scan.lexicon * Scan.lexicon) * outer_syntax |
46970
9667e0dcb5e2
check declared vs. defined commands at end of session;
wenzelm
parents:
46961
diff
changeset
|
16 |
val check_syntax: unit -> unit |
48646
91281e9472d8
more official command specifications, including source position;
wenzelm
parents:
48638
diff
changeset
|
17 |
type command_spec = (string * Keyword.T) * Position.T |
46961
5c6955f487e5
outer syntax command definitions based on formal command_spec derived from theory header declarations;
wenzelm
parents:
46958
diff
changeset
|
18 |
val command: command_spec -> string -> |
29311 | 19 |
(Toplevel.transition -> Toplevel.transition) parser -> unit |
46961
5c6955f487e5
outer syntax command definitions based on formal command_spec derived from theory header declarations;
wenzelm
parents:
46958
diff
changeset
|
20 |
val markup_command: Thy_Output.markup -> command_spec -> string -> |
29311 | 21 |
(Toplevel.transition -> Toplevel.transition) parser -> unit |
46961
5c6955f487e5
outer syntax command definitions based on formal command_spec derived from theory header declarations;
wenzelm
parents:
46958
diff
changeset
|
22 |
val improper_command: command_spec -> string -> |
43711 | 23 |
(Toplevel.transition -> Toplevel.transition) parser -> unit |
46961
5c6955f487e5
outer syntax command definitions based on formal command_spec derived from theory header declarations;
wenzelm
parents:
46958
diff
changeset
|
24 |
val local_theory': command_spec -> string -> |
29380 | 25 |
(bool -> local_theory -> local_theory) parser -> unit |
46961
5c6955f487e5
outer syntax command definitions based on formal command_spec derived from theory header declarations;
wenzelm
parents:
46958
diff
changeset
|
26 |
val local_theory: command_spec -> string -> |
29311 | 27 |
(local_theory -> local_theory) parser -> unit |
46961
5c6955f487e5
outer syntax command definitions based on formal command_spec derived from theory header declarations;
wenzelm
parents:
46958
diff
changeset
|
28 |
val local_theory_to_proof': command_spec -> string -> |
29311 | 29 |
(bool -> local_theory -> Proof.state) parser -> unit |
46961
5c6955f487e5
outer syntax command definitions based on formal command_spec derived from theory header declarations;
wenzelm
parents:
46958
diff
changeset
|
30 |
val local_theory_to_proof: command_spec -> string -> |
29311 | 31 |
(local_theory -> Proof.state) parser -> unit |
50213 | 32 |
val help_outer_syntax: string list -> unit |
5883 | 33 |
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
|
34 |
val scan: Position.T -> string -> Token.T list |
25580 | 35 |
val parse: Position.T -> string -> Toplevel.transition list |
26600 | 36 |
type isar |
38253
3d4e521014f7
Isabelle_Process: separate input fifo for commands (still using the old tty protocol);
wenzelm
parents:
38236
diff
changeset
|
37 |
val isar: TextIO.instream -> bool -> isar |
52510 | 38 |
val side_comments: Token.T list -> Token.T list |
57105 | 39 |
val command_reports: outer_syntax -> Token.T -> Position.report_text list |
52510 | 40 |
val read_spans: outer_syntax -> Token.T list -> Toplevel.transition list |
5829 | 41 |
end; |
42 |
||
36953
2af1ad9aa1a3
renamed structure OuterSyntax to Outer_Syntax, keeping the old name as alias for some time;
wenzelm
parents:
36950
diff
changeset
|
43 |
structure Outer_Syntax: OUTER_SYNTAX = |
5829 | 44 |
struct |
45 |
||
46 |
(** outer syntax **) |
|
47 |
||
29311 | 48 |
(* command parsers *) |
5829 | 49 |
|
29311 | 50 |
datatype command = Command of |
24868 | 51 |
{comment: string, |
37216
3165bc303f66
modernized some structure names, keeping a few legacy aliases;
wenzelm
parents:
36959
diff
changeset
|
52 |
markup: Thy_Output.markup option, |
24868 | 53 |
int_only: bool, |
48647
a5144c4c26a2
report commands as formal entities, with def/ref positions;
wenzelm
parents:
48646
diff
changeset
|
54 |
parse: (Toplevel.transition -> Toplevel.transition) parser, |
a5144c4c26a2
report commands as formal entities, with def/ref positions;
wenzelm
parents:
48646
diff
changeset
|
55 |
pos: Position.T, |
a5144c4c26a2
report commands as formal entities, with def/ref positions;
wenzelm
parents:
48646
diff
changeset
|
56 |
id: serial}; |
5829 | 57 |
|
48647
a5144c4c26a2
report commands as formal entities, with def/ref positions;
wenzelm
parents:
48646
diff
changeset
|
58 |
fun new_command comment markup int_only parse pos = |
a5144c4c26a2
report commands as formal entities, with def/ref positions;
wenzelm
parents:
48646
diff
changeset
|
59 |
Command {comment = comment, markup = markup, int_only = int_only, parse = parse, |
a5144c4c26a2
report commands as formal entities, with def/ref positions;
wenzelm
parents:
48646
diff
changeset
|
60 |
pos = pos, id = serial ()}; |
a5144c4c26a2
report commands as formal entities, with def/ref positions;
wenzelm
parents:
48646
diff
changeset
|
61 |
|
a5144c4c26a2
report commands as formal entities, with def/ref positions;
wenzelm
parents:
48646
diff
changeset
|
62 |
fun command_markup def (name, Command {pos, id, ...}) = |
a5144c4c26a2
report commands as formal entities, with def/ref positions;
wenzelm
parents:
48646
diff
changeset
|
63 |
Markup.properties (Position.entity_properties_of def id pos) |
50201
c26369c9eda6
Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
wenzelm
parents:
49564
diff
changeset
|
64 |
(Markup.entity Markup.commandN name); |
5829 | 65 |
|
50213 | 66 |
fun pretty_command (cmd as (name, Command {comment, ...})) = |
67 |
Pretty.block |
|
68 |
(Pretty.marks_str |
|
50450
358b6020f8b6
generalized notion of active area, where sendback is just one application;
wenzelm
parents:
50215
diff
changeset
|
69 |
([Active.make_markup Markup.sendbackN {implicit = true, properties = [Markup.padding_line]}, |
50215 | 70 |
command_markup false cmd], name) :: Pretty.str ":" :: Pretty.brk 2 :: Pretty.text comment); |
50213 | 71 |
|
5829 | 72 |
|
73 |
(* parse command *) |
|
74 |
||
6860 | 75 |
local |
6199 | 76 |
|
14925
0f86a8a694f8
added read (provides transition names and sources);
wenzelm
parents:
14687
diff
changeset
|
77 |
fun terminate false = Scan.succeed () |
44357 | 78 |
| terminate true = |
79 |
Parse.group (fn () => "end of input") |
|
80 |
(Scan.option Parse.sync -- Parse.semicolon >> K ()); |
|
14925
0f86a8a694f8
added read (provides transition names and sources);
wenzelm
parents:
14687
diff
changeset
|
81 |
|
26620 | 82 |
fun body cmd (name, _) = |
7026 | 83 |
(case cmd name of |
29311 | 84 |
SOME (Command {int_only, parse, ...}) => |
36950 | 85 |
Parse.!!! (Scan.prompt (name ^ "# ") (Parse.tags |-- parse >> pair int_only)) |
48191
c1def7433a72
internalize error into command transaction -- relevant for commands that are declared via 'keywords', but not defined yet;
wenzelm
parents:
47416
diff
changeset
|
86 |
| NONE => |
c1def7433a72
internalize error into command transaction -- relevant for commands that are declared via 'keywords', but not defined yet;
wenzelm
parents:
47416
diff
changeset
|
87 |
Scan.succeed (false, Toplevel.imperative (fn () => |
c1def7433a72
internalize error into command transaction -- relevant for commands that are declared via 'keywords', but not defined yet;
wenzelm
parents:
47416
diff
changeset
|
88 |
error ("Bad parser for outer syntax command " ^ quote name)))); |
6860 | 89 |
|
90 |
in |
|
5829 | 91 |
|
26620 | 92 |
fun parse_command do_terminate cmd = |
36950 | 93 |
Parse.semicolon >> K NONE || |
94 |
Parse.sync >> K NONE || |
|
95 |
(Parse.position Parse.command :-- body cmd) --| terminate do_terminate |
|
6860 | 96 |
>> (fn ((name, pos), (int_only, f)) => |
15531 | 97 |
SOME (Toplevel.empty |> Toplevel.name name |> Toplevel.position pos |> |
6860 | 98 |
Toplevel.interactive int_only |> f)); |
5829 | 99 |
|
6199 | 100 |
end; |
101 |
||
5829 | 102 |
|
43711 | 103 |
(* type outer_syntax *) |
104 |
||
105 |
datatype outer_syntax = Outer_Syntax of |
|
106 |
{commands: command Symtab.table, |
|
107 |
markups: (string * Thy_Output.markup) list}; |
|
108 |
||
109 |
fun make_outer_syntax commands markups = |
|
110 |
Outer_Syntax {commands = commands, markups = markups}; |
|
111 |
||
112 |
val empty_outer_syntax = make_outer_syntax Symtab.empty []; |
|
113 |
||
114 |
||
115 |
fun map_commands f (Outer_Syntax {commands, ...}) = |
|
116 |
let |
|
117 |
val commands' = f commands; |
|
118 |
val markups' = |
|
119 |
Symtab.fold (fn (name, Command {markup = SOME m, ...}) => cons (name, m) | _ => I) |
|
120 |
commands' []; |
|
121 |
in make_outer_syntax commands' markups' end; |
|
122 |
||
123 |
fun dest_commands (Outer_Syntax {commands, ...}) = |
|
50213 | 124 |
commands |> Symtab.dest |> sort_wrt #1; |
43711 | 125 |
|
126 |
fun lookup_commands (Outer_Syntax {commands, ...}) = Symtab.lookup commands; |
|
127 |
||
128 |
fun is_markup (Outer_Syntax {markups, ...}) kind name = |
|
129 |
AList.lookup (op =) markups name = SOME kind; |
|
130 |
||
131 |
||
5829 | 132 |
|
9132 | 133 |
(** global outer syntax **) |
5829 | 134 |
|
48646
91281e9472d8
more official command specifications, including source position;
wenzelm
parents:
48638
diff
changeset
|
135 |
type command_spec = (string * Keyword.T) * Position.T; |
46961
5c6955f487e5
outer syntax command definitions based on formal command_spec derived from theory header declarations;
wenzelm
parents:
46958
diff
changeset
|
136 |
|
55448
e42a3fc18458
explicit indication that redefining outer syntax commands is not supposed to happen -- NB: interactive mode requires global change of syntax;
wenzelm
parents:
54734
diff
changeset
|
137 |
val batch_mode = Unsynchronized.ref false; |
e42a3fc18458
explicit indication that redefining outer syntax commands is not supposed to happen -- NB: interactive mode requires global change of syntax;
wenzelm
parents:
54734
diff
changeset
|
138 |
|
7026 | 139 |
local |
140 |
||
43711 | 141 |
(*synchronized wrt. Keywords*) |
142 |
val global_outer_syntax = Unsynchronized.ref empty_outer_syntax; |
|
5952 | 143 |
|
48647
a5144c4c26a2
report commands as formal entities, with def/ref positions;
wenzelm
parents:
48646
diff
changeset
|
144 |
fun add_command (name, kind) cmd = CRITICAL (fn () => |
46950
d0181abdbdac
declare command keywords via theory header, including strict checking outside Pure;
wenzelm
parents:
46876
diff
changeset
|
145 |
let |
56294
85911b8a6868
prefer Context_Position where a context is available;
wenzelm
parents:
56203
diff
changeset
|
146 |
val context = ML_Context.the_generic_context (); |
85911b8a6868
prefer Context_Position where a context is available;
wenzelm
parents:
56203
diff
changeset
|
147 |
val thy = Context.theory_of context; |
48647
a5144c4c26a2
report commands as formal entities, with def/ref positions;
wenzelm
parents:
48646
diff
changeset
|
148 |
val Command {pos, ...} = cmd; |
46950
d0181abdbdac
declare command keywords via theory header, including strict checking outside Pure;
wenzelm
parents:
46876
diff
changeset
|
149 |
val _ = |
d0181abdbdac
declare command keywords via theory header, including strict checking outside Pure;
wenzelm
parents:
46876
diff
changeset
|
150 |
(case try (Thy_Header.the_keyword thy) name of |
46961
5c6955f487e5
outer syntax command definitions based on formal command_spec derived from theory header declarations;
wenzelm
parents:
46958
diff
changeset
|
151 |
SOME spec => |
48864
3ee314ae1e0a
added keyword kind "thy_load" (with optional list of file extensions);
wenzelm
parents:
48771
diff
changeset
|
152 |
if Option.map #1 spec = SOME (Keyword.kind_files_of kind) then () |
48646
91281e9472d8
more official command specifications, including source position;
wenzelm
parents:
48638
diff
changeset
|
153 |
else error ("Inconsistent outer syntax keyword declaration " ^ |
48992 | 154 |
quote name ^ Position.here pos) |
46950
d0181abdbdac
declare command keywords via theory header, including strict checking outside Pure;
wenzelm
parents:
46876
diff
changeset
|
155 |
| NONE => |
46961
5c6955f487e5
outer syntax command definitions based on formal command_spec derived from theory header declarations;
wenzelm
parents:
46958
diff
changeset
|
156 |
if Context.theory_name thy = Context.PureN |
5c6955f487e5
outer syntax command definitions based on formal command_spec derived from theory header declarations;
wenzelm
parents:
46958
diff
changeset
|
157 |
then Keyword.define (name, SOME kind) |
48992 | 158 |
else error ("Undeclared outer syntax command " ^ quote name ^ Position.here pos)); |
56294
85911b8a6868
prefer Context_Position where a context is available;
wenzelm
parents:
56203
diff
changeset
|
159 |
val _ = Context_Position.report_generic context pos (command_markup true (name, cmd)); |
46950
d0181abdbdac
declare command keywords via theory header, including strict checking outside Pure;
wenzelm
parents:
46876
diff
changeset
|
160 |
in |
d0181abdbdac
declare command keywords via theory header, including strict checking outside Pure;
wenzelm
parents:
46876
diff
changeset
|
161 |
Unsynchronized.change global_outer_syntax (map_commands (fn commands => |
d0181abdbdac
declare command keywords via theory header, including strict checking outside Pure;
wenzelm
parents:
46876
diff
changeset
|
162 |
(if not (Symtab.defined commands name) then () |
57026 | 163 |
else if ! batch_mode then |
164 |
error ("Attempt to redefine outer syntax command " ^ quote name) |
|
55448
e42a3fc18458
explicit indication that redefining outer syntax commands is not supposed to happen -- NB: interactive mode requires global change of syntax;
wenzelm
parents:
54734
diff
changeset
|
165 |
else |
57026 | 166 |
warning ("Redefining outer syntax command " ^ quote name ^ |
167 |
Position.here (Position.thread_data ())); |
|
46950
d0181abdbdac
declare command keywords via theory header, including strict checking outside Pure;
wenzelm
parents:
46876
diff
changeset
|
168 |
Symtab.update (name, cmd) commands))) |
d0181abdbdac
declare command keywords via theory header, including strict checking outside Pure;
wenzelm
parents:
46876
diff
changeset
|
169 |
end); |
6722 | 170 |
|
7026 | 171 |
in |
172 |
||
43711 | 173 |
fun get_syntax () = CRITICAL (fn () => (Keyword.get_lexicons (), ! global_outer_syntax)); |
7789 | 174 |
|
46970
9667e0dcb5e2
check declared vs. defined commands at end of session;
wenzelm
parents:
46961
diff
changeset
|
175 |
fun check_syntax () = |
9667e0dcb5e2
check declared vs. defined commands at end of session;
wenzelm
parents:
46961
diff
changeset
|
176 |
let |
9667e0dcb5e2
check declared vs. defined commands at end of session;
wenzelm
parents:
46961
diff
changeset
|
177 |
val ((_, major), syntax) = CRITICAL (fn () => (Keyword.dest (), ! global_outer_syntax)); |
9667e0dcb5e2
check declared vs. defined commands at end of session;
wenzelm
parents:
46961
diff
changeset
|
178 |
in |
9667e0dcb5e2
check declared vs. defined commands at end of session;
wenzelm
parents:
46961
diff
changeset
|
179 |
(case subtract (op =) (map #1 (dest_commands syntax)) major of |
9667e0dcb5e2
check declared vs. defined commands at end of session;
wenzelm
parents:
46961
diff
changeset
|
180 |
[] => () |
9667e0dcb5e2
check declared vs. defined commands at end of session;
wenzelm
parents:
46961
diff
changeset
|
181 |
| missing => error ("Missing outer syntax command(s) " ^ commas_quote missing)) |
9667e0dcb5e2
check declared vs. defined commands at end of session;
wenzelm
parents:
46961
diff
changeset
|
182 |
end; |
9667e0dcb5e2
check declared vs. defined commands at end of session;
wenzelm
parents:
46961
diff
changeset
|
183 |
|
43711 | 184 |
fun lookup_commands_dynamic () = lookup_commands (! global_outer_syntax); |
5829 | 185 |
|
48647
a5144c4c26a2
report commands as formal entities, with def/ref positions;
wenzelm
parents:
48646
diff
changeset
|
186 |
fun command (spec, pos) comment parse = |
a5144c4c26a2
report commands as formal entities, with def/ref positions;
wenzelm
parents:
48646
diff
changeset
|
187 |
add_command spec (new_command comment NONE false parse pos); |
24868 | 188 |
|
48647
a5144c4c26a2
report commands as formal entities, with def/ref positions;
wenzelm
parents:
48646
diff
changeset
|
189 |
fun markup_command markup (spec, pos) comment parse = |
a5144c4c26a2
report commands as formal entities, with def/ref positions;
wenzelm
parents:
48646
diff
changeset
|
190 |
add_command spec (new_command comment (SOME markup) false parse pos); |
7026 | 191 |
|
48647
a5144c4c26a2
report commands as formal entities, with def/ref positions;
wenzelm
parents:
48646
diff
changeset
|
192 |
fun improper_command (spec, pos) comment parse = |
a5144c4c26a2
report commands as formal entities, with def/ref positions;
wenzelm
parents:
48646
diff
changeset
|
193 |
add_command spec (new_command comment NONE true parse pos); |
29311 | 194 |
|
43711 | 195 |
end; |
196 |
||
5829 | 197 |
|
26990 | 198 |
(* local_theory commands *) |
199 |
||
56895
f058120aaad4
discontinued Toplevel.print flag -- print uniformly according to Keyword.is_printed;
wenzelm
parents:
56334
diff
changeset
|
200 |
fun local_theory_command trans command_spec comment parse = |
f058120aaad4
discontinued Toplevel.print flag -- print uniformly according to Keyword.is_printed;
wenzelm
parents:
56334
diff
changeset
|
201 |
command command_spec comment (Parse.opt_target -- parse >> (fn (loc, f) => trans loc f)); |
26990 | 202 |
|
56895
f058120aaad4
discontinued Toplevel.print flag -- print uniformly according to Keyword.is_printed;
wenzelm
parents:
56334
diff
changeset
|
203 |
val local_theory' = local_theory_command Toplevel.local_theory'; |
f058120aaad4
discontinued Toplevel.print flag -- print uniformly according to Keyword.is_printed;
wenzelm
parents:
56334
diff
changeset
|
204 |
val local_theory = local_theory_command Toplevel.local_theory; |
f058120aaad4
discontinued Toplevel.print flag -- print uniformly according to Keyword.is_printed;
wenzelm
parents:
56334
diff
changeset
|
205 |
val local_theory_to_proof' = local_theory_command Toplevel.local_theory_to_proof'; |
f058120aaad4
discontinued Toplevel.print flag -- print uniformly according to Keyword.is_printed;
wenzelm
parents:
56334
diff
changeset
|
206 |
val local_theory_to_proof = local_theory_command Toplevel.local_theory_to_proof; |
26990 | 207 |
|
208 |
||
24872 | 209 |
(* inspect syntax *) |
7026 | 210 |
|
50213 | 211 |
fun help_outer_syntax pats = |
212 |
dest_commands (#2 (get_syntax ())) |
|
213 |
|> filter (fn (name, _) => forall (fn pat => match_string pat name) pats) |
|
214 |
|> map pretty_command |
|
56334
6b3739fee456
some shortcuts for chunks, which sometimes avoid bulky string output;
wenzelm
parents:
56294
diff
changeset
|
215 |
|> Pretty.writeln_chunks; |
50213 | 216 |
|
9223 | 217 |
fun print_outer_syntax () = |
7026 | 218 |
let |
46957
0c15caf47040
clarified Keyword.is_keyword: union of minor and major;
wenzelm
parents:
46950
diff
changeset
|
219 |
val ((keywords, _), outer_syntax) = |
0c15caf47040
clarified Keyword.is_keyword: union of minor and major;
wenzelm
parents:
46950
diff
changeset
|
220 |
CRITICAL (fn () => (Keyword.dest (), #2 (get_syntax ()))); |
50213 | 221 |
val (int_cmds, cmds) = |
222 |
List.partition (fn (_, Command {int_only, ...}) => int_only) (dest_commands outer_syntax); |
|
7026 | 223 |
in |
43711 | 224 |
[Pretty.strs ("syntax keywords:" :: map quote keywords), |
50213 | 225 |
Pretty.big_list "commands:" (map pretty_command cmds), |
226 |
Pretty.big_list "interactive-only commands:" (map pretty_command int_cmds)] |
|
56334
6b3739fee456
some shortcuts for chunks, which sometimes avoid bulky string output;
wenzelm
parents:
56294
diff
changeset
|
227 |
|> Pretty.writeln_chunks |
7026 | 228 |
end; |
5829 | 229 |
|
230 |
||
231 |
||
9132 | 232 |
(** toplevel parsing **) |
5829 | 233 |
|
9132 | 234 |
(* basic sources *) |
6860 | 235 |
|
26620 | 236 |
fun toplevel_source term do_recover cmd src = |
9132 | 237 |
let |
238 |
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
|
239 |
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
|
240 |
fun recover int = |
cf4773532006
nested source: explicit interactive flag for recover avoids duplicate errors;
wenzelm
parents:
23679
diff
changeset
|
241 |
(int, fn _ => Scan.prompt "recover# " (Scan.repeat no_terminator) >> K [NONE]); |
9132 | 242 |
in |
243 |
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
|
244 |
|> 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
|
245 |
|> Source.source Token.stopper |
51627
589daaf48dba
tuned signature -- agree with markup terminology;
wenzelm
parents:
51271
diff
changeset
|
246 |
(Scan.bulk (Parse.$$$ "--" -- Parse.!!! Parse.document_source >> K NONE || Parse.not_eof >> SOME)) |
23682
cf4773532006
nested source: explicit interactive flag for recover avoids duplicate errors;
wenzelm
parents:
23679
diff
changeset
|
247 |
(Option.map recover do_recover) |
19482
9f11af8f7ef9
tuned basic list operators (flat, maps, map_filter);
wenzelm
parents:
19060
diff
changeset
|
248 |
|> 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
|
249 |
|> Source.source Token.stopper |
36950 | 250 |
(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
|
251 |
(Option.map recover do_recover) |
19482
9f11af8f7ef9
tuned basic list operators (flat, maps, map_filter);
wenzelm
parents:
19060
diff
changeset
|
252 |
|> Source.map_filter I |
9132 | 253 |
end; |
5829 | 254 |
|
7746 | 255 |
|
25580 | 256 |
(* off-line scanning/parsing *) |
14925
0f86a8a694f8
added read (provides transition names and sources);
wenzelm
parents:
14687
diff
changeset
|
257 |
|
27839
0be8644c45eb
Symbol.source/OuterLex.source: more explicit do_recover argument;
wenzelm
parents:
27831
diff
changeset
|
258 |
fun scan pos str = |
16195 | 259 |
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
|
260 |
|> 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
|
261 |
|> Token.source {do_recover = SOME false} Keyword.get_lexicons pos |
16195 | 262 |
|> Source.exhaust; |
263 |
||
25580 | 264 |
fun parse pos str = |
265 |
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
|
266 |
|> 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
|
267 |
|> Token.source {do_recover = SOME false} Keyword.get_lexicons pos |
43711 | 268 |
|> toplevel_source false NONE lookup_commands_dynamic |
25580 | 269 |
|> Source.exhaust; |
270 |
||
14091 | 271 |
|
24868 | 272 |
(* interactive source of toplevel transformers *) |
273 |
||
26600 | 274 |
type isar = |
275 |
(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
|
276 |
(Token.T, (Token.T option, (Token.T, (Token.T, |
54734
b91afc3aa3e6
clarified Proof General legacy: special treatment of \<^newline> only in TTY mode;
wenzelm
parents:
52510
diff
changeset
|
277 |
(Symbol_Pos.T, |
b91afc3aa3e6
clarified Proof General legacy: special treatment of \<^newline> only in TTY mode;
wenzelm
parents:
52510
diff
changeset
|
278 |
Position.T * (Symbol.symbol, (Symbol.symbol, (string, unit) Source.source) Source.source) |
27770 | 279 |
Source.source) Source.source) Source.source) Source.source) |
280 |
Source.source) Source.source) Source.source) Source.source; |
|
26600 | 281 |
|
38253
3d4e521014f7
Isabelle_Process: separate input fifo for commands (still using the old tty protocol);
wenzelm
parents:
38236
diff
changeset
|
282 |
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
|
283 |
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
|
284 |
|> Symbol.source |
56203
76c72f4d0667
clarified bootstrap process: switch to ML with context and antiquotations earlier;
wenzelm
parents:
55708
diff
changeset
|
285 |
|> Source.map_filter (fn "\<^newline>" => SOME "\n" | s => SOME s) (*Proof General legacy*) |
36959
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents:
36955
diff
changeset
|
286 |
|> Token.source {do_recover = SOME true} Keyword.get_lexicons Position.none |
43711 | 287 |
|> toplevel_source term (SOME true) lookup_commands_dynamic; |
24868 | 288 |
|
289 |
||
52510 | 290 |
(* side-comments *) |
48749
c197b3c3e7fa
some attempts to keep malformed syntax errors focussed, without too much red spilled onto the document view;
wenzelm
parents:
48647
diff
changeset
|
291 |
|
52510 | 292 |
fun cmts (t1 :: t2 :: toks) = |
293 |
if Token.keyword_with (fn s => s = "--") t1 then t2 :: cmts toks |
|
294 |
else cmts (t2 :: toks) |
|
295 |
| cmts _ = []; |
|
296 |
||
297 |
val side_comments = filter Token.is_proper #> cmts; |
|
298 |
||
299 |
||
300 |
(* read commands *) |
|
48647
a5144c4c26a2
report commands as formal entities, with def/ref positions;
wenzelm
parents:
48646
diff
changeset
|
301 |
|
52510 | 302 |
fun command_reports outer_syntax tok = |
303 |
if Token.is_command tok then |
|
304 |
let val name = Token.content_of tok in |
|
305 |
(case lookup_commands outer_syntax name of |
|
306 |
NONE => [] |
|
55708 | 307 |
| SOME cmd => [((Token.pos_of tok, command_markup false (name, cmd)), "")]) |
52510 | 308 |
end |
309 |
else []; |
|
48749
c197b3c3e7fa
some attempts to keep malformed syntax errors focussed, without too much red spilled onto the document view;
wenzelm
parents:
48647
diff
changeset
|
310 |
|
52510 | 311 |
fun read_spans outer_syntax toks = |
312 |
Source.of_list toks |
|
313 |
|> toplevel_source false NONE (K (lookup_commands outer_syntax)) |
|
314 |
|> Source.exhaust; |
|
28432
944cb67f809a
load_thy: Toplevel.excursion based on units of command/proof pairs;
wenzelm
parents:
28424
diff
changeset
|
315 |
|
5829 | 316 |
end; |
36953
2af1ad9aa1a3
renamed structure OuterSyntax to Outer_Syntax, keeping the old name as alias for some time;
wenzelm
parents:
36950
diff
changeset
|
317 |