4 Prover command execution: read -- eval -- print. |
4 Prover command execution: read -- eval -- print. |
5 *) |
5 *) |
6 |
6 |
7 signature COMMAND = |
7 signature COMMAND = |
8 sig |
8 sig |
9 type blob = (string * (SHA1.digest * string list) option) Exn.result |
9 type blob = {file_node: string, src_path: Path.T, content: (SHA1.digest * string list) option} |
10 val read_file: Path.T -> Position.T -> Path.T -> Token.file |
10 val read_file: Path.T -> Position.T -> Path.T -> Token.file |
11 val read_thy: Toplevel.state -> theory |
11 val read_thy: Toplevel.state -> theory |
12 val read: Keyword.keywords -> theory -> Path.T-> (unit -> theory) -> |
12 val read: Keyword.keywords -> theory -> Path.T-> (unit -> theory) -> |
13 blob list * int -> Token.T list -> Toplevel.transition |
13 blob Exn.result list * int -> Token.T list -> Toplevel.transition |
14 type eval |
14 type eval |
15 val eval_command_id: eval -> Document_ID.command |
15 val eval_command_id: eval -> Document_ID.command |
16 val eval_exec_id: eval -> Document_ID.exec |
16 val eval_exec_id: eval -> Document_ID.exec |
17 val eval_eq: eval * eval -> bool |
17 val eval_eq: eval * eval -> bool |
18 val eval_running: eval -> bool |
18 val eval_running: eval -> bool |
19 val eval_finished: eval -> bool |
19 val eval_finished: eval -> bool |
20 val eval_result_command: eval -> Toplevel.transition |
20 val eval_result_command: eval -> Toplevel.transition |
21 val eval_result_state: eval -> Toplevel.state |
21 val eval_result_state: eval -> Toplevel.state |
22 val eval: Keyword.keywords -> Path.T -> (unit -> theory) -> |
22 val eval: Keyword.keywords -> Path.T -> (unit -> theory) -> |
23 blob list * int -> Document_ID.command -> Token.T list -> eval -> eval |
23 blob Exn.result list * int -> Document_ID.command -> Token.T list -> eval -> eval |
24 type print |
24 type print |
25 type print_fn = Toplevel.transition -> Toplevel.state -> unit |
25 type print_fn = Toplevel.transition -> Toplevel.state -> unit |
26 val print0: {pri: int, print_fn: print_fn} -> eval -> print |
26 val print0: {pri: int, print_fn: print_fn} -> eval -> print |
27 val print: bool -> (string * string list) list -> Keyword.keywords -> string -> |
27 val print: bool -> (string * string list) list -> Keyword.keywords -> string -> |
28 eval -> print list -> print list option |
28 eval -> print list -> print list option |
87 (case Position.get_id (Position.thread_data ()) of |
86 (case Position.get_id (Position.thread_data ()) of |
88 NONE => I |
87 NONE => I |
89 | SOME exec_id => Position.put_id exec_id); |
88 | SOME exec_id => Position.put_id exec_id); |
90 in {src_path = src_path, lines = lines, digest = digest, pos = file_pos} end |
89 in {src_path = src_path, lines = lines, digest = digest, pos = file_pos} end |
91 |
90 |
92 fun resolve_files keywords master_dir (blobs, blobs_index) toks = |
91 fun resolve_files master_dir (blobs, blobs_index) toks = |
93 (case Outer_Syntax.parse_spans toks of |
92 (case Outer_Syntax.parse_spans toks of |
94 [Command_Span.Span (Command_Span.Command_Span (cmd, _), _)] => |
93 [Command_Span.Span (Command_Span.Command_Span (cmd, _), _)] => |
95 (case try (nth toks) blobs_index of |
94 (case try (nth toks) blobs_index of |
96 SOME tok => |
95 SOME tok => |
97 let |
96 let |
98 val pos = Token.pos_of tok; |
97 val pos = Token.pos_of tok; |
99 val path = Path.explode (Token.content_of tok) |
98 fun make_file (Exn.Res {file_node, src_path, content = NONE}) = |
100 handle ERROR msg => error (msg ^ Position.here pos); |
|
101 fun make_file src_path (Exn.Res (file_node, NONE)) = |
|
102 Exn.interruptible_capture (fn () => |
99 Exn.interruptible_capture (fn () => |
103 read_file_node file_node master_dir pos src_path) () |
100 read_file_node file_node master_dir pos src_path) () |
104 | make_file src_path (Exn.Res (file_node, SOME (digest, lines))) = |
101 | make_file (Exn.Res {file_node, src_path, content = SOME (digest, lines)}) = |
105 (Position.report pos Markup.language_path; |
102 (Position.report pos Markup.language_path; |
106 Exn.Res (blob_file src_path lines digest file_node)) |
103 Exn.Res (blob_file src_path lines digest file_node)) |
107 | make_file _ (Exn.Exn e) = Exn.Exn e; |
104 | make_file (Exn.Exn e) = Exn.Exn e; |
108 val src_paths = Keyword.command_files keywords cmd path; |
105 val files = map make_file blobs; |
109 val files = |
|
110 if null blobs then |
|
111 map2 make_file src_paths (map (K (Exn.Res ("", NONE))) src_paths) |
|
112 else if length src_paths = length blobs then |
|
113 map2 make_file src_paths blobs |
|
114 else error ("Misalignment of inlined files" ^ Position.here pos); |
|
115 in |
106 in |
116 toks |> map_index (fn (i, tok) => |
107 toks |> map_index (fn (i, tok) => |
117 if i = blobs_index then Token.put_files files tok else tok) |
108 if i = blobs_index then Token.put_files files tok else tok) |
118 end |
109 end |
119 | NONE => toks) |
110 | NONE => toks) |
155 if null verbatim then () |
146 if null verbatim then () |
156 else legacy_feature ("Old-style {* verbatim *} token -- use \<open>cartouche\<close> instead" ^ |
147 else legacy_feature ("Old-style {* verbatim *} token -- use \<open>cartouche\<close> instead" ^ |
157 Position.here_list verbatim); |
148 Position.here_list verbatim); |
158 in |
149 in |
159 if exists #1 token_reports then Toplevel.malformed pos "Malformed command syntax" |
150 if exists #1 token_reports then Toplevel.malformed pos "Malformed command syntax" |
160 else Outer_Syntax.parse_span thy init (resolve_files keywords master_dir blobs_info span) |
151 else Outer_Syntax.parse_span thy init (resolve_files master_dir blobs_info span) |
161 end; |
152 end; |
162 |
153 |
163 end; |
154 end; |
164 |
155 |
165 |
156 |