src/Pure/Thy/thy_load.ML
changeset 56135 efa24d31e595
parent 56134 4a7a07c01857
child 56204 f70e69208a8c
equal deleted inserted replaced
56134:4a7a07c01857 56135:efa24d31e595
   188       end;
   188       end;
   189 
   189 
   190   in (thy, present, size text) end;
   190   in (thy, present, size text) end;
   191 
   191 
   192 
   192 
   193 (* document antiquotation *)
   193 (* antiquotations *)
   194 
   194 
   195 fun file_antiq strict ctxt (name, pos) =
   195 local
       
   196 
       
   197 fun check_path strict ctxt dir (name, pos) =
   196   let
   198   let
   197     val _ = Context_Position.report ctxt pos Markup.language_path;
   199     val _ = Context_Position.report ctxt pos Markup.language_path;
   198 
   200 
   199     val dir = master_directory (Proof_Context.theory_of ctxt);
       
   200     val path = Path.append dir (Path.explode name)
   201     val path = Path.append dir (Path.explode name)
   201       handle ERROR msg => error (msg ^ Position.here pos);
   202       handle ERROR msg => error (msg ^ Position.here pos);
   202 
   203 
   203     val _ = Context_Position.report ctxt pos (Markup.path (Path.smart_implode path));
   204     val _ = Context_Position.report ctxt pos (Markup.path (Path.smart_implode path));
   204     val _ =
   205     val _ =
   211           if strict then error msg
   212           if strict then error msg
   212           else
   213           else
   213             Context_Position.if_visible ctxt Output.report
   214             Context_Position.if_visible ctxt Output.report
   214               (Markup.markup (Markup.bad |> Markup.properties (Position.properties_of pos)) msg)
   215               (Markup.markup (Markup.bad |> Markup.properties (Position.properties_of pos)) msg)
   215         end;
   216         end;
       
   217   in path end;
       
   218 
       
   219 fun file_antiq strict ctxt (name, pos) =
       
   220   let
       
   221     val dir = master_directory (Proof_Context.theory_of ctxt);
       
   222     val _ = check_path strict ctxt dir (name, pos);
   216   in
   223   in
   217     space_explode "/" name
   224     space_explode "/" name
   218     |> map Thy_Output.verb_text
   225     |> map Thy_Output.verb_text
   219     |> space_implode (Thy_Output.verb_text "/" ^ "\\discretionary{}{}{}")
   226     |> space_implode (Thy_Output.verb_text "/" ^ "\\discretionary{}{}{}")
   220   end;
   227   end;
   221 
   228 
       
   229 in
       
   230 
   222 val _ = Theory.setup
   231 val _ = Theory.setup
   223   (Thy_Output.antiquotation (Binding.name "file") (Scan.lift (Parse.position Parse.path))
   232  (Thy_Output.antiquotation (Binding.name "file") (Scan.lift (Parse.position Parse.path))
   224     (file_antiq true o #context) #>
   233     (file_antiq true o #context) #>
   225   (Thy_Output.antiquotation (Binding.name "file_unchecked") (Scan.lift (Parse.position Parse.path))
   234   Thy_Output.antiquotation (Binding.name "file_unchecked") (Scan.lift (Parse.position Parse.path))
   226     (file_antiq false o #context)));
   235     (file_antiq false o #context) #>
       
   236   ML_Antiquotation.value (Binding.name "path")
       
   237     (Args.context -- Scan.lift (Parse.position Parse.path) >> (fn (ctxt, arg) =>
       
   238       let val path = check_path true ctxt Path.current arg
       
   239       in "Path.explode " ^ ML_Syntax.print_string (Path.implode path) end)));
   227 
   240 
   228 end;
   241 end;
       
   242 
       
   243 end;