src/Pure/PIDE/document.ML
changeset 72946 9329abcdd651
parent 72747 5f9d66155081
child 72947 19484bb038a8
equal deleted inserted replaced
72945:756b9cb8a176 72946:9329abcdd651
    20   val define_blob: string -> string -> state -> state
    20   val define_blob: string -> string -> state -> state
    21   type blob_digest = {file_node: string, src_path: Path.T, digest: string option} Exn.result
    21   type blob_digest = {file_node: string, src_path: Path.T, digest: string option} Exn.result
    22   type command =
    22   type command =
    23    {command_id: Document_ID.command,
    23    {command_id: Document_ID.command,
    24     name: string,
    24     name: string,
       
    25     parents: string list,
    25     blobs_digests: blob_digest list,
    26     blobs_digests: blob_digest list,
    26     blobs_index: int,
    27     blobs_index: int,
    27     tokens: ((int * int) * string) list}
    28     tokens: ((int * int) * string) list}
    28   val define_command: command -> state -> state
    29   val define_command: command -> state -> state
    29   val command_exec: state -> string -> Document_ID.command -> Command.exec option
    30   val command_exec: state -> string -> Document_ID.command -> Command.exec option
   408 (* commands *)
   409 (* commands *)
   409 
   410 
   410 type command =
   411 type command =
   411   {command_id: Document_ID.command,
   412   {command_id: Document_ID.command,
   412    name: string,
   413    name: string,
       
   414    parents: string list,
   413    blobs_digests: blob_digest list,
   415    blobs_digests: blob_digest list,
   414    blobs_index: int,
   416    blobs_index: int,
   415    tokens: ((int * int) * string) list};
   417    tokens: ((int * int) * string) list};
   416 
   418 
   417 fun define_command {command_id, name, blobs_digests, blobs_index, tokens} =
   419 fun define_command {command_id, name, parents, blobs_digests, blobs_index, tokens} =
   418   map_state (fn (versions, blobs, commands, execution) =>
   420   map_state (fn (versions, blobs, commands, execution) =>
   419     let
   421     let
   420       val id = Document_ID.print command_id;
   422       val id = Document_ID.print command_id;
   421       val span =
   423       val span =
   422         Lazy.lazy_name "Document.define_command" (fn () =>
   424         Lazy.lazy_name "Document.define_command" (fn () =>
   423           Position.setmp_thread_data (Position.id_only id)
   425           Position.setmp_thread_data (Position.id_only id)
   424             (fn () =>
   426             (fn () =>
   425               let
   427               let
   426                 val (tokens, _) = fold_map Token.make tokens (Position.id id);
   428                 val (tokens, _) = fold_map Token.make tokens (Position.id id);
       
   429                 val imports =
       
   430                   if name = Thy_Header.theoryN then
       
   431                     #imports (Thy_Header.read_tokens Position.none tokens)
       
   432                   else [];
       
   433                 val _ =
       
   434                   if length parents = length imports then
       
   435                     (parents, imports) |> ListPair.app (fn (parent, (_, pos)) =>
       
   436                       let val markup =
       
   437                         (case Thy_Info.lookup_theory parent of
       
   438                           SOME thy => Theory.get_markup thy
       
   439                         | NONE =>
       
   440                             (case try Url.explode parent of
       
   441                               NONE => Markup.path parent
       
   442                             | SOME (Url.File path) => Markup.path (Path.implode path)
       
   443                             | SOME _ => Markup.url parent))
       
   444                       in Position.report pos markup end)
       
   445                   else ();
   427                 val _ =
   446                 val _ =
   428                   if blobs_index < 0
   447                   if blobs_index < 0
   429                   then (*inlined errors*)
   448                   then (*inlined errors*)
   430                     map_filter Exn.get_exn blobs_digests
   449                     map_filter Exn.get_exn blobs_digests
   431                     |> List.app (Output.error_message o Runtime.exn_message)
   450                     |> List.app (Output.error_message o Runtime.exn_message)
   596           NONE =>
   615           NONE =>
   597             maybe_end_theory pos
   616             maybe_end_theory pos
   598               (case get_result (snd (the (AList.lookup (op =) deps import))) of
   617               (case get_result (snd (the (AList.lookup (op =) deps import))) of
   599                 NONE => Toplevel.init_toplevel ()
   618                 NONE => Toplevel.init_toplevel ()
   600               | SOME (_, eval) => maybe_eval_result eval)
   619               | SOME (_, eval) => maybe_eval_result eval)
   601         | some => some)
   620             |> Option.map (fn thy => (thy, (pos, Theory.get_markup thy)))
   602         |> Option.map (fn thy => (thy, (pos, Theory.get_markup thy))));
   621         | SOME thy => SOME (thy, (Position.none, Markup.empty))));
   603 
   622 
   604     val parents =
   623     val parents =
   605       if null parents_reports then [Theory.get_pure ()] else map #1 parents_reports;
   624       if null parents_reports then [Theory.get_pure ()] else map #1 parents_reports;
   606     val _ = List.app (fn (thy, r) => Context_Position.reports_global thy [r]) parents_reports;
   625     val _ = List.app (fn (thy, r) => Context_Position.reports_global thy [r]) parents_reports;
   607 
   626