src/Pure/PIDE/resources.scala
changeset 56823 37be55461dbe
parent 56801 8dd9df88f647
child 56913 df4cd6e1fdfa
equal deleted inserted replaced
56822:6101243e6740 56823:37be55461dbe
     6 
     6 
     7 package isabelle
     7 package isabelle
     8 
     8 
     9 
     9 
    10 import scala.annotation.tailrec
    10 import scala.annotation.tailrec
       
    11 import scala.util.parsing.input.Reader
    11 
    12 
    12 import java.io.{File => JFile}
    13 import java.io.{File => JFile}
    13 
    14 
    14 
    15 
    15 object Resources
    16 object Resources
    38   /* file-system operations */
    39   /* file-system operations */
    39 
    40 
    40   def append(dir: String, source_path: Path): String =
    41   def append(dir: String, source_path: Path): String =
    41     (Path.explode(dir) + source_path).expand.implode
    42     (Path.explode(dir) + source_path).expand.implode
    42 
    43 
    43   def with_thy_text[A](name: Document.Node.Name, f: CharSequence => A): A =
    44   def with_thy_reader[A](name: Document.Node.Name, f: Reader[Char] => A): A =
    44   {
    45   {
    45     val path = Path.explode(name.node)
    46     val path = Path.explode(name.node)
    46     if (!path.is_file) error("No such file: " + path.toString)
    47     if (!path.is_file) error("No such file: " + path.toString)
    47 
    48 
    48     val text = File.read(path)
    49     val reader = Scan.byte_reader(path.file)
    49     Symbol.decode_strict(text)
    50     try { f(reader) } finally { reader.close }
    50     f(text)
       
    51   }
    51   }
    52 
    52 
    53 
    53 
    54   /* theory files */
    54   /* theory files */
    55 
    55 
    82           Document.Node.Name(node, master_dir, Long_Name.qualify(qualifier, theory))
    82           Document.Node.Name(node, master_dir, Long_Name.qualify(qualifier, theory))
    83         }
    83         }
    84     }
    84     }
    85   }
    85   }
    86 
    86 
    87   def check_thy_text(qualifier: String, name: Document.Node.Name, text: CharSequence)
    87   def check_thy_reader(qualifier: String, name: Document.Node.Name, reader: Reader[Char])
    88     : Document.Node.Header =
    88     : Document.Node.Header =
    89   {
    89   {
    90     try {
    90     try {
    91       val header = Thy_Header.read(text)
    91       val header = Thy_Header.read(reader).decode_symbols
    92 
    92 
    93       val base_name = Long_Name.base_name(name.theory)
    93       val base_name = Long_Name.base_name(name.theory)
    94       val name1 = header.name
    94       val name1 = header.name
    95       if (base_name != name1)
    95       if (base_name != name1)
    96         error("Bad file name " + Resources.thy_path(Path.basic(base_name)) +
    96         error("Bad file name " + Resources.thy_path(Path.basic(base_name)) +
   101     }
   101     }
   102     catch { case exn: Throwable => Document.Node.bad_header(Exn.message(exn)) }
   102     catch { case exn: Throwable => Document.Node.bad_header(Exn.message(exn)) }
   103   }
   103   }
   104 
   104 
   105   def check_thy(qualifier: String, name: Document.Node.Name): Document.Node.Header =
   105   def check_thy(qualifier: String, name: Document.Node.Name): Document.Node.Header =
   106     with_thy_text(name, check_thy_text(qualifier, name, _))
   106     with_thy_reader(name, check_thy_reader(qualifier, name, _))
   107 
   107 
   108 
   108 
   109   /* document changes */
   109   /* document changes */
   110 
   110 
   111   def parse_change(
   111   def parse_change(