src/Pure/PIDE/resources.ML
changeset 67217 53867014e299
parent 67215 03d0c958d65a
child 67219 81e9804b2014
equal deleted inserted replaced
67216:99815211970c 67217:53867014e299
   195       (case try (load_file thy) src_path of
   195       (case try (load_file thy) src_path of
   196         NONE => false
   196         NONE => false
   197       | SOME ((_, id'), _) => id = id'));
   197       | SOME ((_, id'), _) => id = id'));
   198 
   198 
   199 
   199 
   200 (* antiquotations *)
   200 (* formal check *)
   201 
   201 
   202 local
   202 fun formal_check check_file ctxt dir (name, pos) =
   203 
       
   204 fun gen_check check_file ctxt dir (name, pos) =
       
   205   let
   203   let
   206     fun err msg = error (msg ^ Position.here pos);
   204     fun err msg = error (msg ^ Position.here pos);
   207 
   205 
   208     val _ = Context_Position.report ctxt pos Markup.language_path;
   206     val _ = Context_Position.report ctxt pos Markup.language_path;
   209     val path = Path.append dir (Path.explode name) handle ERROR msg => err msg;
   207     val path = Path.append dir (Path.explode name) handle ERROR msg => err msg;
   210     val _ = Path.expand path handle ERROR msg => err msg;
   208     val _ = Path.expand path handle ERROR msg => err msg;
   211     val _ = Context_Position.report ctxt pos (Markup.path (Path.smart_implode path));
   209     val _ = Context_Position.report ctxt pos (Markup.path (Path.smart_implode path));
   212     val _ = check_file path handle ERROR msg => err msg;
   210     val _ = check_file path handle ERROR msg => err msg;
   213   in path end;
   211   in path end;
       
   212 
       
   213 val check_path = formal_check I;
       
   214 val check_file = formal_check File.check_file;
       
   215 val check_dir = formal_check File.check_dir;
       
   216 
       
   217 
       
   218 (* antiquotations *)
       
   219 
       
   220 local
   214 
   221 
   215 fun document_antiq check ctxt (name, pos) =
   222 fun document_antiq check ctxt (name, pos) =
   216   let
   223   let
   217     val dir = master_directory (Proof_Context.theory_of ctxt);
   224     val dir = master_directory (Proof_Context.theory_of ctxt);
   218     val _ = check ctxt dir (name, pos);
   225     val _ = check ctxt dir (name, pos);
   226 fun ML_antiq check ctxt (name, pos) =
   233 fun ML_antiq check ctxt (name, pos) =
   227   let val path = check ctxt Path.current (name, pos);
   234   let val path = check ctxt Path.current (name, pos);
   228   in "Path.explode " ^ ML_Syntax.print_string (Path.implode path) end;
   235   in "Path.explode " ^ ML_Syntax.print_string (Path.implode path) end;
   229 
   236 
   230 in
   237 in
   231 
       
   232 val check_path = gen_check I;
       
   233 val check_file = gen_check File.check_file;
       
   234 val check_dir = gen_check File.check_dir;
       
   235 
   238 
   236 val _ = Theory.setup
   239 val _ = Theory.setup
   237  (Thy_Output.antiquotation \<^binding>\<open>path\<close> (Scan.lift (Parse.position Parse.path))
   240  (Thy_Output.antiquotation \<^binding>\<open>path\<close> (Scan.lift (Parse.position Parse.path))
   238     (document_antiq check_path o #context) #>
   241     (document_antiq check_path o #context) #>
   239   Thy_Output.antiquotation \<^binding>\<open>file\<close> (Scan.lift (Parse.position Parse.path))
   242   Thy_Output.antiquotation \<^binding>\<open>file\<close> (Scan.lift (Parse.position Parse.path))