src/Pure/ML/ml_root.scala
changeset 62866 d20262cd20e8
child 62881 20b0cb2f0b87
equal deleted inserted replaced
62865:cf03cb9578d4 62866:d20262cd20e8
       
     1 /*  Title:      Pure/ML/ml_root.scala
       
     2     Author:     Makarius
       
     3 
       
     4 Support for ML project ROOT file, with imitation of ML "use" commands.
       
     5 */
       
     6 
       
     7 package isabelle
       
     8 
       
     9 
       
    10 object ML_Root
       
    11 {
       
    12   /* parser */
       
    13 
       
    14   val ROOT_ML = Path.explode("ROOT.ML")
       
    15 
       
    16   val USE = "use"
       
    17   val USE_DEBUG = "use_debug"
       
    18   val USE_NO_DEBUG = "use_no_debug"
       
    19   val USE_THY = "use_thy"
       
    20 
       
    21   lazy val syntax =
       
    22     Outer_Syntax.init() + ";" +
       
    23       (USE, Some((Keyword.THY_LOAD, Nil)), None) +
       
    24       (USE_DEBUG, Some((Keyword.THY_LOAD, Nil)), None) +
       
    25       (USE_NO_DEBUG, Some((Keyword.THY_LOAD, Nil)), None) +
       
    26       (USE_THY, Some((Keyword.THY_LOAD, Nil)), None)
       
    27 
       
    28   private object Parser extends Parse.Parser
       
    29   {
       
    30     val entry: Parser[(String, String)] =
       
    31       (command(USE) | command(USE_DEBUG) | command(USE_NO_DEBUG) | command(USE_THY)) ~!
       
    32         (string ~ $$$(";")) ^^ { case a ~ (b ~ _) => (a, b) }
       
    33 
       
    34     def parse(in: Token.Reader): ParseResult[List[(String, String)]] =
       
    35       parse_all(rep(entry), in)
       
    36   }
       
    37 
       
    38   def read(dir: Path): List[(String, Path)] =
       
    39   {
       
    40     val root = dir + ROOT_ML
       
    41 
       
    42     val toks = Token.explode(syntax.keywords, File.read(root))
       
    43     val start = Token.Pos.file(root.implode)
       
    44 
       
    45     Parser.parse(Token.reader(toks, start)) match {
       
    46       case Parser.Success(entries, _) =>
       
    47         for ((a, b) <- entries) yield {
       
    48           val path = dir + Path.explode(b)
       
    49           (a, if (a == USE_THY) Resources.thy_path(path) else path)
       
    50         }
       
    51       case bad => error(bad.toString)
       
    52     }
       
    53   }
       
    54 }