src/Pure/PIDE/resources.ML
changeset 67471 bddfa23a4ea9
parent 67463 a5ca98950a91
child 67473 aad088768872
equal deleted inserted replaced
67470:d36fcde7e2c0 67471:bddfa23a4ea9
     7 signature RESOURCES =
     7 signature RESOURCES =
     8 sig
     8 sig
     9   val default_qualifier: string
     9   val default_qualifier: string
    10   val init_session_base:
    10   val init_session_base:
    11     {sessions: string list,
    11     {sessions: string list,
       
    12      doc_names: string list,
    12      global_theories: (string * string) list,
    13      global_theories: (string * string) list,
    13      loaded_theories: string list,
    14      loaded_theories: string list,
    14      known_theories: (string * string) list} -> unit
    15      known_theories: (string * string) list} -> unit
    15   val finish_session_base: unit -> unit
    16   val finish_session_base: unit -> unit
    16   val global_theory: string -> string option
    17   val global_theory: string -> string option
    17   val loaded_theory: string -> bool
    18   val loaded_theory: string -> bool
    18   val known_theory: string -> Path.T option
    19   val known_theory: string -> Path.T option
    19   val check_session: Proof.context -> string * Position.T -> string
    20   val check_session: Proof.context -> string * Position.T -> string
       
    21   val check_doc: Proof.context -> string * Position.T -> string
    20   val master_directory: theory -> Path.T
    22   val master_directory: theory -> Path.T
    21   val imports_of: theory -> (string * Position.T) list
    23   val imports_of: theory -> (string * Position.T) list
    22   val begin_theory: Path.T -> Thy_Header.header -> theory list -> theory
    24   val begin_theory: Path.T -> Thy_Header.header -> theory list -> theory
    23   val thy_path: Path.T -> Path.T
    25   val thy_path: Path.T -> Path.T
    24   val theory_qualifier: string -> string
    26   val theory_qualifier: string -> string
    43 
    45 
    44 val default_qualifier = "Draft";
    46 val default_qualifier = "Draft";
    45 
    47 
    46 val empty_session_base =
    48 val empty_session_base =
    47   {sessions = []: string list,
    49   {sessions = []: string list,
       
    50    doc_names = []: string list,
    48    global_theories = Symtab.empty: string Symtab.table,
    51    global_theories = Symtab.empty: string Symtab.table,
    49    loaded_theories = Symtab.empty: unit Symtab.table,
    52    loaded_theories = Symtab.empty: unit Symtab.table,
    50    known_theories = Symtab.empty: Path.T Symtab.table};
    53    known_theories = Symtab.empty: Path.T Symtab.table};
    51 
    54 
    52 val global_session_base =
    55 val global_session_base =
    53   Synchronized.var "Sessions.base" empty_session_base;
    56   Synchronized.var "Sessions.base" empty_session_base;
    54 
    57 
    55 fun init_session_base {sessions, global_theories, loaded_theories, known_theories} =
    58 fun init_session_base {sessions, doc_names, global_theories, loaded_theories, known_theories} =
    56   Synchronized.change global_session_base
    59   Synchronized.change global_session_base
    57     (fn _ =>
    60     (fn _ =>
    58       {sessions = sort_strings sessions,
    61       {sessions = sort_strings sessions,
       
    62        doc_names = doc_names,
    59        global_theories = Symtab.make global_theories,
    63        global_theories = Symtab.make global_theories,
    60        loaded_theories = Symtab.make_set loaded_theories,
    64        loaded_theories = Symtab.make_set loaded_theories,
    61        known_theories = Symtab.make (map (apsnd Path.explode) known_theories)});
    65        known_theories = Symtab.make (map (apsnd Path.explode) known_theories)});
    62 
    66 
    63 fun finish_session_base () =
    67 fun finish_session_base () =
    64   Synchronized.change global_session_base
    68   Synchronized.change global_session_base
    65     (fn {global_theories, loaded_theories, ...} =>
    69     (fn {global_theories, loaded_theories, ...} =>
    66       {sessions = [],
    70       {sessions = [],
       
    71        doc_names = [],
    67        global_theories = global_theories,
    72        global_theories = global_theories,
    68        loaded_theories = loaded_theories,
    73        loaded_theories = loaded_theories,
    69        known_theories = #known_theories empty_session_base});
    74        known_theories = #known_theories empty_session_base});
    70 
    75 
    71 fun get_session_base f = f (Synchronized.value global_session_base);
    76 fun get_session_base f = f (Synchronized.value global_session_base);
    72 
    77 
    73 fun global_theory a = Symtab.lookup (get_session_base #global_theories) a;
    78 fun global_theory a = Symtab.lookup (get_session_base #global_theories) a;
    74 fun loaded_theory a = Symtab.defined (get_session_base #loaded_theories) a;
    79 fun loaded_theory a = Symtab.defined (get_session_base #loaded_theories) a;
    75 fun known_theory a = Symtab.lookup (get_session_base #known_theories) a;
    80 fun known_theory a = Symtab.lookup (get_session_base #known_theories) a;
    76 
    81 
    77 fun check_session ctxt (name, pos) =
    82 fun check_name which kind markup ctxt (name, pos) =
    78   let val sessions = get_session_base #sessions in
    83   let val names = get_session_base which in
    79     if member (op =) sessions name then
    84     if member (op =) names name then
    80       (Context_Position.report ctxt pos (Markup.entity Markup.sessionN name); name)
    85       (Context_Position.report ctxt pos (markup name); name)
    81     else
    86     else
    82       let
    87       let
    83         val completion =
    88         val completion =
    84           Completion.make (name, pos) (fn completed =>
    89           Completion.make (name, pos) (fn completed =>
    85               sessions
    90               names
    86               |> filter completed
    91               |> filter completed
    87               |> map (fn a => (a, (Markup.sessionN, a))));
    92               |> map (fn a => (a, (kind, a))));
    88         val report = Markup.markup_report (Completion.reported_text completion);
    93         val report = Markup.markup_report (Completion.reported_text completion);
    89       in error ("Bad session " ^ quote name ^ Position.here pos ^ report) end
    94       in error ("Bad " ^ kind ^ " " ^ quote name ^ Position.here pos ^ report) end
    90   end;
    95   end;
       
    96 
       
    97 val check_session = check_name #sessions "session" (Markup.entity Markup.sessionN);
       
    98 val check_doc = check_name #doc_names "documentation" Markup.doc;
       
    99 
    91 
   100 
    92 
   101 
    93 (* manage source files *)
   102 (* manage source files *)
    94 
   103 
    95 type files =
   104 type files =
   256 in
   265 in
   257 
   266 
   258 val _ = Theory.setup
   267 val _ = Theory.setup
   259  (Thy_Output.antiquotation_verbatim \<^binding>\<open>session\<close>
   268  (Thy_Output.antiquotation_verbatim \<^binding>\<open>session\<close>
   260     (Scan.lift (Parse.position Parse.embedded)) check_session #>
   269     (Scan.lift (Parse.position Parse.embedded)) check_session #>
       
   270   Thy_Output.antiquotation_verbatim \<^binding>\<open>doc\<close>
       
   271     (Scan.lift (Parse.position Parse.embedded)) check_doc #>
   261   Thy_Output.antiquotation_raw \<^binding>\<open>path\<close>
   272   Thy_Output.antiquotation_raw \<^binding>\<open>path\<close>
   262     (Scan.lift (Parse.position Parse.path)) (document_antiq check_path) #>
   273     (Scan.lift (Parse.position Parse.path)) (document_antiq check_path) #>
   263   Thy_Output.antiquotation_raw \<^binding>\<open>file\<close>
   274   Thy_Output.antiquotation_raw \<^binding>\<open>file\<close>
   264     (Scan.lift (Parse.position Parse.path)) (document_antiq check_file) #>
   275     (Scan.lift (Parse.position Parse.path)) (document_antiq check_file) #>
   265   Thy_Output.antiquotation_raw \<^binding>\<open>dir\<close>
   276   Thy_Output.antiquotation_raw \<^binding>\<open>dir\<close>