src/Pure/PIDE/resources.ML
changeset 76803 5ffe32b613ae
parent 76801 f425e0fda79c
child 76804 3e8340fcaa16
equal deleted inserted replaced
76802:ad01b550e74b 76803:5ffe32b613ae
    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 read_file_node: string -> Path.T -> Position.T -> bool -> Path.T -> Token.file
    40   val parse_files: (Path.T -> Path.T list) -> (theory -> Token.file list) parser
    41   val parse_files: (Path.T -> Path.T list) -> (theory -> Token.file list) parser
    41   val parse_file: (theory -> Token.file) parser
    42   val parse_file: (theory -> Token.file) parser
    42   val provide: Path.T * SHA1.digest -> theory -> theory
    43   val provide: Path.T * SHA1.digest -> theory -> theory
    43   val provide_file: Token.file -> theory -> theory
    44   val provide_file: Token.file -> theory -> theory
    44   val provide_file': Token.file -> theory -> Token.file * theory
    45   val provide_file': Token.file -> theory -> Token.file * theory
   325    {master = (master_file, SHA1.digest text), text = text, theory_pos = pos,
   326    {master = (master_file, SHA1.digest text), text = text, theory_pos = pos,
   326     imports = imports, keywords = keywords}
   327     imports = imports, keywords = keywords}
   327   end;
   328   end;
   328 
   329 
   329 
   330 
       
   331 (* read_file_node *)
       
   332 
       
   333 fun read_file_node file_node master_dir pos delimited src_path =
       
   334   let
       
   335     val _ =
       
   336       if Context_Position.pide_reports ()
       
   337       then Position.report pos (Markup.language_path delimited) else ();
       
   338 
       
   339     fun read_local () =
       
   340       let
       
   341         val path = File.check_file (File.full_path master_dir src_path);
       
   342         val text = File.read path;
       
   343         val file_pos = Path.position path;
       
   344       in (text, file_pos) end;
       
   345 
       
   346     fun read_remote () =
       
   347       let
       
   348         val text = Bytes.content (Isabelle_System.download file_node);
       
   349         val file_pos = Position.file file_node;
       
   350       in (text, file_pos) end;
       
   351 
       
   352     val (text, file_pos) =
       
   353       (case try Url.explode file_node of
       
   354         NONE => read_local ()
       
   355       | SOME (Url.File _) => read_local ()
       
   356       | _ => read_remote ());
       
   357 
       
   358     val lines = split_lines text;
       
   359     val digest = SHA1.digest text;
       
   360   in {src_path = src_path, lines = lines, digest = digest, pos = Position.copy_id pos file_pos} end
       
   361   handle ERROR msg => error (msg ^ Position.here pos);
       
   362 
       
   363 
   330 (* load files *)
   364 (* load files *)
   331 
   365 
   332 fun parse_files make_paths =
   366 fun parse_files make_paths =
   333   Scan.ahead Parse.not_eof -- Parse.path_input >> (fn (tok, source) => fn thy =>
   367   Scan.ahead Parse.not_eof -- Parse.path_input >> (fn (tok, source) => fn thy =>
   334     (case Token.get_files tok of
   368     (case Token.get_files tok of
   341           val src_paths = make_paths (Path.explode name);
   375           val src_paths = make_paths (Path.explode name);
   342           val reports =
   376           val reports =
   343             src_paths |> map (fn src_path =>
   377             src_paths |> map (fn src_path =>
   344               (pos, Markup.path (Path.implode_symbolic (master_dir + src_path))));
   378               (pos, Markup.path (Path.implode_symbolic (master_dir + src_path))));
   345           val _ = Position.reports reports;
   379           val _ = Position.reports reports;
   346         in map (Command.read_file master_dir pos delimited) src_paths end
   380         in map (read_file_node "" master_dir pos delimited) src_paths end
   347     | files => map Exn.release files));
   381     | files => map Exn.release files));
   348 
   382 
   349 val parse_file = parse_files single >> (fn f => f #> the_single);
   383 val parse_file = parse_files single >> (fn f => f #> the_single);
   350 
   384 
   351 
   385