src/Pure/PIDE/resources.ML
changeset 72747 5f9d66155081
parent 72669 5e7916535860
child 72754 1456c5747416
equal deleted inserted replaced
72746:049a71febf05 72747:5f9d66155081
    35   val import_name: string -> Path.T -> string ->
    35   val import_name: string -> Path.T -> string ->
    36     {node_name: Path.T, master_dir: Path.T, theory_name: string}
    36     {node_name: Path.T, master_dir: Path.T, theory_name: string}
    37   val check_thy: Path.T -> string ->
    37   val check_thy: Path.T -> string ->
    38    {master: Path.T * SHA1.digest, text: string, theory_pos: Position.T,
    38    {master: Path.T * SHA1.digest, text: string, theory_pos: Position.T,
    39     imports: (string * Position.T) list, keywords: Thy_Header.keywords}
    39     imports: (string * Position.T) list, keywords: Thy_Header.keywords}
    40   val parse_files: string -> (theory -> Token.file list) parser
    40   val extensions: string list -> Path.T -> Path.T list
       
    41   val parse_files: (Path.T -> Path.T list) -> (theory -> Token.file list) parser
       
    42   val parse_file: (theory -> Token.file) parser
    41   val provide: Path.T * SHA1.digest -> theory -> theory
    43   val provide: Path.T * SHA1.digest -> theory -> theory
    42   val provide_file: Token.file -> theory -> theory
    44   val provide_file: Token.file -> theory -> theory
    43   val provide_parse_files: string -> (theory -> Token.file list * theory) parser
    45   val provide_parse_files: (Path.T -> Path.T list) -> (theory -> Token.file list * theory) parser
       
    46   val provide_parse_file: (theory -> Token.file * theory) parser
    44   val loaded_files_current: theory -> bool
    47   val loaded_files_current: theory -> bool
    45   val check_path: Proof.context -> Path.T option -> string * Position.T -> Path.T
    48   val check_path: Proof.context -> Path.T option -> string * Position.T -> Path.T
    46   val check_file: Proof.context -> Path.T option -> string * Position.T -> Path.T
    49   val check_file: Proof.context -> Path.T option -> string * Position.T -> Path.T
    47   val check_dir: Proof.context -> Path.T option -> string * Position.T -> Path.T
    50   val check_dir: Proof.context -> Path.T option -> string * Position.T -> Path.T
    48 end;
    51 end;
   288   end;
   291   end;
   289 
   292 
   290 
   293 
   291 (* load files *)
   294 (* load files *)
   292 
   295 
   293 fun parse_files cmd =
   296 fun extensions exts path = map (fn ext => Path.ext ext path) exts;
       
   297 
       
   298 fun parse_files make_paths =
   294   Scan.ahead Parse.not_eof -- Parse.path >> (fn (tok, name) => fn thy =>
   299   Scan.ahead Parse.not_eof -- Parse.path >> (fn (tok, name) => fn thy =>
   295     (case Token.get_files tok of
   300     (case Token.get_files tok of
   296       [] =>
   301       [] =>
   297         let
   302         let
   298           val keywords = Thy_Header.get_keywords thy;
       
   299           val master_dir = master_directory thy;
   303           val master_dir = master_directory thy;
   300           val pos = Token.pos_of tok;
   304           val pos = Token.pos_of tok;
   301           val src_paths = Keyword.command_files keywords cmd (Path.explode name);
   305           val src_paths = make_paths (Path.explode name);
   302         in map (Command.read_file master_dir pos) src_paths end
   306         in map (Command.read_file master_dir pos) src_paths end
   303     | files => map Exn.release files));
   307     | files => map Exn.release files));
       
   308 
       
   309 val parse_file = parse_files single >> (fn f => f #> the_single);
       
   310 
   304 
   311 
   305 fun provide (src_path, id) =
   312 fun provide (src_path, id) =
   306   map_files (fn (master_dir, imports, provided) =>
   313   map_files (fn (master_dir, imports, provided) =>
   307     if AList.defined (op =) provided src_path then
   314     if AList.defined (op =) provided src_path then
   308       error ("Duplicate use of source file: " ^ Path.print src_path)
   315       error ("Duplicate use of source file: " ^ Path.print src_path)
   309     else (master_dir, imports, (src_path, id) :: provided));
   316     else (master_dir, imports, (src_path, id) :: provided));
   310 
   317 
   311 fun provide_file (file: Token.file) = provide (#src_path file, #digest file);
   318 fun provide_file (file: Token.file) = provide (#src_path file, #digest file);
   312 
   319 
   313 fun provide_parse_files cmd =
   320 fun provide_parse_files make_paths =
   314   parse_files cmd >> (fn files => fn thy =>
   321   parse_files make_paths >> (fn files => fn thy =>
   315     let
   322     let
   316       val fs = files thy;
   323       val fs = files thy;
   317       val thy' = fold (fn {src_path, digest, ...} => provide (src_path, digest)) fs thy;
   324       val thy' = fold (fn {src_path, digest, ...} => provide (src_path, digest)) fs thy;
   318     in (fs, thy') end);
   325     in (fs, thy') end);
       
   326 
       
   327 val provide_parse_file = provide_parse_files single >> (fn f => f #>> the_single);
       
   328 
   319 
   329 
   320 fun load_file thy src_path =
   330 fun load_file thy src_path =
   321   let
   331   let
   322     val full_path = check_file (master_directory thy) src_path;
   332     val full_path = check_file (master_directory thy) src_path;
   323     val text = File.read full_path;
   333     val text = File.read full_path;