src/Pure/General/path.scala
author wenzelm
Tue, 24 Jul 2012 20:56:18 +0200
changeset 48484 70898d016538
parent 48457 fd9e28d5a143
child 48548 49afe0e92163
permissions -rw-r--r--
more explicit checks during parsing;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
43600
4ac04bf9ff89 abstract algebra of file paths in Scala (cf. path.ML);
wenzelm
parents:
diff changeset
     1
/*  Title:      Pure/General/path.scala
4ac04bf9ff89 abstract algebra of file paths in Scala (cf. path.ML);
wenzelm
parents:
diff changeset
     2
    Author:     Makarius
4ac04bf9ff89 abstract algebra of file paths in Scala (cf. path.ML);
wenzelm
parents:
diff changeset
     3
43601
fd650d659275 tuned comments;
wenzelm
parents: 43600
diff changeset
     4
Algebra of file-system paths: basic POSIX notation, extended by named
fd650d659275 tuned comments;
wenzelm
parents: 43600
diff changeset
     5
roots (e.g. //foo) and variables (e.g. $BAR).
43600
4ac04bf9ff89 abstract algebra of file paths in Scala (cf. path.ML);
wenzelm
parents:
diff changeset
     6
*/
4ac04bf9ff89 abstract algebra of file paths in Scala (cf. path.ML);
wenzelm
parents:
diff changeset
     7
4ac04bf9ff89 abstract algebra of file paths in Scala (cf. path.ML);
wenzelm
parents:
diff changeset
     8
package isabelle
4ac04bf9ff89 abstract algebra of file paths in Scala (cf. path.ML);
wenzelm
parents:
diff changeset
     9
4ac04bf9ff89 abstract algebra of file paths in Scala (cf. path.ML);
wenzelm
parents:
diff changeset
    10
48409
0d2114eb412a more explicit java.io.{File => JFile};
wenzelm
parents: 48373
diff changeset
    11
import java.io.{File => JFile}
48373
527e2bad7cca further imitation of "usedir" shell script;
wenzelm
parents: 47661
diff changeset
    12
43697
77ce24aa1770 explicit Document.Node.Header, with master_dir and thy_name;
wenzelm
parents: 43670
diff changeset
    13
import scala.util.matching.Regex
77ce24aa1770 explicit Document.Node.Header, with master_dir and thy_name;
wenzelm
parents: 43670
diff changeset
    14
77ce24aa1770 explicit Document.Node.Header, with master_dir and thy_name;
wenzelm
parents: 43670
diff changeset
    15
43600
4ac04bf9ff89 abstract algebra of file paths in Scala (cf. path.ML);
wenzelm
parents:
diff changeset
    16
object Path
4ac04bf9ff89 abstract algebra of file paths in Scala (cf. path.ML);
wenzelm
parents:
diff changeset
    17
{
4ac04bf9ff89 abstract algebra of file paths in Scala (cf. path.ML);
wenzelm
parents:
diff changeset
    18
  /* path elements */
4ac04bf9ff89 abstract algebra of file paths in Scala (cf. path.ML);
wenzelm
parents:
diff changeset
    19
45244
c149b61bc372 class Path as abstract datatype;
wenzelm
parents: 43697
diff changeset
    20
  sealed abstract class Elem
43600
4ac04bf9ff89 abstract algebra of file paths in Scala (cf. path.ML);
wenzelm
parents:
diff changeset
    21
  private case class Root(val name: String) extends Elem
4ac04bf9ff89 abstract algebra of file paths in Scala (cf. path.ML);
wenzelm
parents:
diff changeset
    22
  private case class Basic(val name: String) extends Elem
4ac04bf9ff89 abstract algebra of file paths in Scala (cf. path.ML);
wenzelm
parents:
diff changeset
    23
  private case class Variable(val name: String) extends Elem
4ac04bf9ff89 abstract algebra of file paths in Scala (cf. path.ML);
wenzelm
parents:
diff changeset
    24
  private case object Parent extends Elem
4ac04bf9ff89 abstract algebra of file paths in Scala (cf. path.ML);
wenzelm
parents:
diff changeset
    25
4ac04bf9ff89 abstract algebra of file paths in Scala (cf. path.ML);
wenzelm
parents:
diff changeset
    26
  private def err_elem(msg: String, s: String): Nothing =
43652
dcd0b667f73d pervasive Basic_Library in Scala;
wenzelm
parents: 43605
diff changeset
    27
    error (msg + " path element specification: " + quote(s))
43600
4ac04bf9ff89 abstract algebra of file paths in Scala (cf. path.ML);
wenzelm
parents:
diff changeset
    28
4ac04bf9ff89 abstract algebra of file paths in Scala (cf. path.ML);
wenzelm
parents:
diff changeset
    29
  private def check_elem(s: String): String =
4ac04bf9ff89 abstract algebra of file paths in Scala (cf. path.ML);
wenzelm
parents:
diff changeset
    30
    if (s == "" || s == "~" || s == "~~") err_elem("Illegal", s)
4ac04bf9ff89 abstract algebra of file paths in Scala (cf. path.ML);
wenzelm
parents:
diff changeset
    31
    else
48420
a8ed41b6280b disallow quotes in path specifications -- extra paranoia;
wenzelm
parents: 48409
diff changeset
    32
      s.iterator.filter(c =>
a8ed41b6280b disallow quotes in path specifications -- extra paranoia;
wenzelm
parents: 48409
diff changeset
    33
          c == '/' || c == '\\' || c == '$' || c == ':' || c == '"' || c == '\'').toList match {
43600
4ac04bf9ff89 abstract algebra of file paths in Scala (cf. path.ML);
wenzelm
parents:
diff changeset
    34
        case Nil => s
4ac04bf9ff89 abstract algebra of file paths in Scala (cf. path.ML);
wenzelm
parents:
diff changeset
    35
        case bads =>
43652
dcd0b667f73d pervasive Basic_Library in Scala;
wenzelm
parents: 43605
diff changeset
    36
          err_elem ("Illegal character(s) " + commas_quote(bads.map(_.toString)) + " in", s)
43600
4ac04bf9ff89 abstract algebra of file paths in Scala (cf. path.ML);
wenzelm
parents:
diff changeset
    37
      }
4ac04bf9ff89 abstract algebra of file paths in Scala (cf. path.ML);
wenzelm
parents:
diff changeset
    38
4ac04bf9ff89 abstract algebra of file paths in Scala (cf. path.ML);
wenzelm
parents:
diff changeset
    39
  private def root_elem(s: String): Elem = Root(check_elem(s))
4ac04bf9ff89 abstract algebra of file paths in Scala (cf. path.ML);
wenzelm
parents:
diff changeset
    40
  private def basic_elem(s: String): Elem = Basic(check_elem(s))
4ac04bf9ff89 abstract algebra of file paths in Scala (cf. path.ML);
wenzelm
parents:
diff changeset
    41
  private def variable_elem(s: String): Elem = Variable(check_elem(s))
4ac04bf9ff89 abstract algebra of file paths in Scala (cf. path.ML);
wenzelm
parents:
diff changeset
    42
4ac04bf9ff89 abstract algebra of file paths in Scala (cf. path.ML);
wenzelm
parents:
diff changeset
    43
  private def apply_elem(y: Elem, xs: List[Elem]): List[Elem] =
4ac04bf9ff89 abstract algebra of file paths in Scala (cf. path.ML);
wenzelm
parents:
diff changeset
    44
    (y, xs) match {
4ac04bf9ff89 abstract algebra of file paths in Scala (cf. path.ML);
wenzelm
parents:
diff changeset
    45
      case (Root(_), _) => List(y)
4ac04bf9ff89 abstract algebra of file paths in Scala (cf. path.ML);
wenzelm
parents:
diff changeset
    46
      case (Parent, Root(_) :: _) => xs
4ac04bf9ff89 abstract algebra of file paths in Scala (cf. path.ML);
wenzelm
parents:
diff changeset
    47
      case (Parent, Basic(_) :: rest) => rest
4ac04bf9ff89 abstract algebra of file paths in Scala (cf. path.ML);
wenzelm
parents:
diff changeset
    48
      case _ => y :: xs
4ac04bf9ff89 abstract algebra of file paths in Scala (cf. path.ML);
wenzelm
parents:
diff changeset
    49
    }
4ac04bf9ff89 abstract algebra of file paths in Scala (cf. path.ML);
wenzelm
parents:
diff changeset
    50
4ac04bf9ff89 abstract algebra of file paths in Scala (cf. path.ML);
wenzelm
parents:
diff changeset
    51
  private def norm_elems(elems: List[Elem]): List[Elem] =
4ac04bf9ff89 abstract algebra of file paths in Scala (cf. path.ML);
wenzelm
parents:
diff changeset
    52
    (elems :\ (Nil: List[Elem]))(apply_elem)
4ac04bf9ff89 abstract algebra of file paths in Scala (cf. path.ML);
wenzelm
parents:
diff changeset
    53
4ac04bf9ff89 abstract algebra of file paths in Scala (cf. path.ML);
wenzelm
parents:
diff changeset
    54
  private def implode_elem(elem: Elem): String =
4ac04bf9ff89 abstract algebra of file paths in Scala (cf. path.ML);
wenzelm
parents:
diff changeset
    55
    elem match {
4ac04bf9ff89 abstract algebra of file paths in Scala (cf. path.ML);
wenzelm
parents:
diff changeset
    56
      case Root("") => ""
4ac04bf9ff89 abstract algebra of file paths in Scala (cf. path.ML);
wenzelm
parents:
diff changeset
    57
      case Root(s) => "//" + s
4ac04bf9ff89 abstract algebra of file paths in Scala (cf. path.ML);
wenzelm
parents:
diff changeset
    58
      case Basic(s) => s
4ac04bf9ff89 abstract algebra of file paths in Scala (cf. path.ML);
wenzelm
parents:
diff changeset
    59
      case Variable(s) => "$" + s
4ac04bf9ff89 abstract algebra of file paths in Scala (cf. path.ML);
wenzelm
parents:
diff changeset
    60
      case Parent => ".."
4ac04bf9ff89 abstract algebra of file paths in Scala (cf. path.ML);
wenzelm
parents:
diff changeset
    61
    }
4ac04bf9ff89 abstract algebra of file paths in Scala (cf. path.ML);
wenzelm
parents:
diff changeset
    62
4ac04bf9ff89 abstract algebra of file paths in Scala (cf. path.ML);
wenzelm
parents:
diff changeset
    63
4ac04bf9ff89 abstract algebra of file paths in Scala (cf. path.ML);
wenzelm
parents:
diff changeset
    64
  /* path constructors */
4ac04bf9ff89 abstract algebra of file paths in Scala (cf. path.ML);
wenzelm
parents:
diff changeset
    65
45244
c149b61bc372 class Path as abstract datatype;
wenzelm
parents: 43697
diff changeset
    66
  val current: Path = new Path(Nil)
c149b61bc372 class Path as abstract datatype;
wenzelm
parents: 43697
diff changeset
    67
  val root: Path = new Path(List(Root("")))
c149b61bc372 class Path as abstract datatype;
wenzelm
parents: 43697
diff changeset
    68
  def named_root(s: String): Path = new Path(List(root_elem(s)))
c149b61bc372 class Path as abstract datatype;
wenzelm
parents: 43697
diff changeset
    69
  def basic(s: String): Path = new Path(List(basic_elem(s)))
c149b61bc372 class Path as abstract datatype;
wenzelm
parents: 43697
diff changeset
    70
  def variable(s: String): Path = new Path(List(variable_elem(s)))
c149b61bc372 class Path as abstract datatype;
wenzelm
parents: 43697
diff changeset
    71
  val parent: Path = new Path(List(Parent))
43600
4ac04bf9ff89 abstract algebra of file paths in Scala (cf. path.ML);
wenzelm
parents:
diff changeset
    72
4ac04bf9ff89 abstract algebra of file paths in Scala (cf. path.ML);
wenzelm
parents:
diff changeset
    73
4ac04bf9ff89 abstract algebra of file paths in Scala (cf. path.ML);
wenzelm
parents:
diff changeset
    74
  /* explode */
4ac04bf9ff89 abstract algebra of file paths in Scala (cf. path.ML);
wenzelm
parents:
diff changeset
    75
4ac04bf9ff89 abstract algebra of file paths in Scala (cf. path.ML);
wenzelm
parents:
diff changeset
    76
  private def explode_elem(s: String): Elem =
4ac04bf9ff89 abstract algebra of file paths in Scala (cf. path.ML);
wenzelm
parents:
diff changeset
    77
    if (s == "..") Parent
47661
012a887997f3 USER_HOME settings variable points to cross-platform user home directory;
wenzelm
parents: 46712
diff changeset
    78
    else if (s == "~") Variable("USER_HOME")
43600
4ac04bf9ff89 abstract algebra of file paths in Scala (cf. path.ML);
wenzelm
parents:
diff changeset
    79
    else if (s == "~~") Variable("ISABELLE_HOME")
4ac04bf9ff89 abstract algebra of file paths in Scala (cf. path.ML);
wenzelm
parents:
diff changeset
    80
    else if (s.startsWith("$")) variable_elem(s.substring(1))
4ac04bf9ff89 abstract algebra of file paths in Scala (cf. path.ML);
wenzelm
parents:
diff changeset
    81
    else basic_elem(s)
4ac04bf9ff89 abstract algebra of file paths in Scala (cf. path.ML);
wenzelm
parents:
diff changeset
    82
4ac04bf9ff89 abstract algebra of file paths in Scala (cf. path.ML);
wenzelm
parents:
diff changeset
    83
  private def explode_elems(ss: List[String]): List[Elem] =
4ac04bf9ff89 abstract algebra of file paths in Scala (cf. path.ML);
wenzelm
parents:
diff changeset
    84
    ss.filterNot(s => s.isEmpty || s == ".").map(explode_elem).reverse
4ac04bf9ff89 abstract algebra of file paths in Scala (cf. path.ML);
wenzelm
parents:
diff changeset
    85
4ac04bf9ff89 abstract algebra of file paths in Scala (cf. path.ML);
wenzelm
parents:
diff changeset
    86
  def explode(str: String): Path =
4ac04bf9ff89 abstract algebra of file paths in Scala (cf. path.ML);
wenzelm
parents:
diff changeset
    87
  {
43670
7f933761764b prefer space_explode/split_lines as in Isabelle/ML;
wenzelm
parents: 43669
diff changeset
    88
    val ss = space_explode('/', str)
43600
4ac04bf9ff89 abstract algebra of file paths in Scala (cf. path.ML);
wenzelm
parents:
diff changeset
    89
    val r = ss.takeWhile(_.isEmpty).length
4ac04bf9ff89 abstract algebra of file paths in Scala (cf. path.ML);
wenzelm
parents:
diff changeset
    90
    val es = ss.dropWhile(_.isEmpty)
4ac04bf9ff89 abstract algebra of file paths in Scala (cf. path.ML);
wenzelm
parents:
diff changeset
    91
    val (roots, raw_elems) =
4ac04bf9ff89 abstract algebra of file paths in Scala (cf. path.ML);
wenzelm
parents:
diff changeset
    92
      if (r == 0) (Nil, es)
4ac04bf9ff89 abstract algebra of file paths in Scala (cf. path.ML);
wenzelm
parents:
diff changeset
    93
      else if (r == 1) (List(Root("")), es)
4ac04bf9ff89 abstract algebra of file paths in Scala (cf. path.ML);
wenzelm
parents:
diff changeset
    94
      else if (es.isEmpty) (List(Root("")), Nil)
4ac04bf9ff89 abstract algebra of file paths in Scala (cf. path.ML);
wenzelm
parents:
diff changeset
    95
      else (List(root_elem(es.head)), es.tail)
45244
c149b61bc372 class Path as abstract datatype;
wenzelm
parents: 43697
diff changeset
    96
    new Path(norm_elems(explode_elems(raw_elems) ++ roots))
43600
4ac04bf9ff89 abstract algebra of file paths in Scala (cf. path.ML);
wenzelm
parents:
diff changeset
    97
  }
43669
9d34288e9351 Path.split convenience;
wenzelm
parents: 43664
diff changeset
    98
48484
70898d016538 more explicit checks during parsing;
wenzelm
parents: 48457
diff changeset
    99
  def is_ok(str: String): Boolean =
70898d016538 more explicit checks during parsing;
wenzelm
parents: 48457
diff changeset
   100
    try { explode(str); true } catch { case ERROR(_) => false }
70898d016538 more explicit checks during parsing;
wenzelm
parents: 48457
diff changeset
   101
43669
9d34288e9351 Path.split convenience;
wenzelm
parents: 43664
diff changeset
   102
  def split(str: String): List[Path] =
43670
7f933761764b prefer space_explode/split_lines as in Isabelle/ML;
wenzelm
parents: 43669
diff changeset
   103
    space_explode(':', str).filterNot(_.isEmpty).map(explode)
48457
fd9e28d5a143 pass build options to ML;
wenzelm
parents: 48420
diff changeset
   104
fd9e28d5a143 pass build options to ML;
wenzelm
parents: 48420
diff changeset
   105
fd9e28d5a143 pass build options to ML;
wenzelm
parents: 48420
diff changeset
   106
  /* encode */
fd9e28d5a143 pass build options to ML;
wenzelm
parents: 48420
diff changeset
   107
fd9e28d5a143 pass build options to ML;
wenzelm
parents: 48420
diff changeset
   108
  val encode: XML.Encode.T[Path] = (path => XML.Encode.string(path.implode))
43600
4ac04bf9ff89 abstract algebra of file paths in Scala (cf. path.ML);
wenzelm
parents:
diff changeset
   109
}
4ac04bf9ff89 abstract algebra of file paths in Scala (cf. path.ML);
wenzelm
parents:
diff changeset
   110
43669
9d34288e9351 Path.split convenience;
wenzelm
parents: 43664
diff changeset
   111
46712
8650d9a95736 prefer final ADTs -- prevent ooddities;
wenzelm
parents: 45244
diff changeset
   112
final class Path private(private val elems: List[Path.Elem]) // reversed elements
43600
4ac04bf9ff89 abstract algebra of file paths in Scala (cf. path.ML);
wenzelm
parents:
diff changeset
   113
{
4ac04bf9ff89 abstract algebra of file paths in Scala (cf. path.ML);
wenzelm
parents:
diff changeset
   114
  def is_current: Boolean = elems.isEmpty
4ac04bf9ff89 abstract algebra of file paths in Scala (cf. path.ML);
wenzelm
parents:
diff changeset
   115
  def is_absolute: Boolean = !elems.isEmpty && elems.last.isInstanceOf[Path.Root]
4ac04bf9ff89 abstract algebra of file paths in Scala (cf. path.ML);
wenzelm
parents:
diff changeset
   116
  def is_basic: Boolean = elems match { case List(Path.Basic(_)) => true case _ => false }
4ac04bf9ff89 abstract algebra of file paths in Scala (cf. path.ML);
wenzelm
parents:
diff changeset
   117
45244
c149b61bc372 class Path as abstract datatype;
wenzelm
parents: 43697
diff changeset
   118
  def +(other: Path): Path = new Path((other.elems :\ elems)(Path.apply_elem))
43600
4ac04bf9ff89 abstract algebra of file paths in Scala (cf. path.ML);
wenzelm
parents:
diff changeset
   119
4ac04bf9ff89 abstract algebra of file paths in Scala (cf. path.ML);
wenzelm
parents:
diff changeset
   120
43604
ff33fea12337 more Path operations;
wenzelm
parents: 43601
diff changeset
   121
  /* implode */
43600
4ac04bf9ff89 abstract algebra of file paths in Scala (cf. path.ML);
wenzelm
parents:
diff changeset
   122
43604
ff33fea12337 more Path operations;
wenzelm
parents: 43601
diff changeset
   123
  def implode: String =
43600
4ac04bf9ff89 abstract algebra of file paths in Scala (cf. path.ML);
wenzelm
parents:
diff changeset
   124
    elems match {
4ac04bf9ff89 abstract algebra of file paths in Scala (cf. path.ML);
wenzelm
parents:
diff changeset
   125
      case Nil => "."
4ac04bf9ff89 abstract algebra of file paths in Scala (cf. path.ML);
wenzelm
parents:
diff changeset
   126
      case List(Path.Root("")) => "/"
43604
ff33fea12337 more Path operations;
wenzelm
parents: 43601
diff changeset
   127
      case _ => elems.map(Path.implode_elem).reverse.mkString("/")
43600
4ac04bf9ff89 abstract algebra of file paths in Scala (cf. path.ML);
wenzelm
parents:
diff changeset
   128
    }
4ac04bf9ff89 abstract algebra of file paths in Scala (cf. path.ML);
wenzelm
parents:
diff changeset
   129
43652
dcd0b667f73d pervasive Basic_Library in Scala;
wenzelm
parents: 43605
diff changeset
   130
  override def toString: String = quote(implode)
43600
4ac04bf9ff89 abstract algebra of file paths in Scala (cf. path.ML);
wenzelm
parents:
diff changeset
   131
4ac04bf9ff89 abstract algebra of file paths in Scala (cf. path.ML);
wenzelm
parents:
diff changeset
   132
4ac04bf9ff89 abstract algebra of file paths in Scala (cf. path.ML);
wenzelm
parents:
diff changeset
   133
  /* base element */
4ac04bf9ff89 abstract algebra of file paths in Scala (cf. path.ML);
wenzelm
parents:
diff changeset
   134
4ac04bf9ff89 abstract algebra of file paths in Scala (cf. path.ML);
wenzelm
parents:
diff changeset
   135
  private def split_path: (Path, String) =
4ac04bf9ff89 abstract algebra of file paths in Scala (cf. path.ML);
wenzelm
parents:
diff changeset
   136
    elems match {
45244
c149b61bc372 class Path as abstract datatype;
wenzelm
parents: 43697
diff changeset
   137
      case Path.Basic(s) :: xs => (new Path(xs), s)
43604
ff33fea12337 more Path operations;
wenzelm
parents: 43601
diff changeset
   138
      case _ => error("Cannot split path into dir/base: " + toString)
43600
4ac04bf9ff89 abstract algebra of file paths in Scala (cf. path.ML);
wenzelm
parents:
diff changeset
   139
    }
4ac04bf9ff89 abstract algebra of file paths in Scala (cf. path.ML);
wenzelm
parents:
diff changeset
   140
4ac04bf9ff89 abstract algebra of file paths in Scala (cf. path.ML);
wenzelm
parents:
diff changeset
   141
  def dir: Path = split_path._1
45244
c149b61bc372 class Path as abstract datatype;
wenzelm
parents: 43697
diff changeset
   142
  def base: Path = new Path(List(Path.Basic(split_path._2)))
43600
4ac04bf9ff89 abstract algebra of file paths in Scala (cf. path.ML);
wenzelm
parents:
diff changeset
   143
4ac04bf9ff89 abstract algebra of file paths in Scala (cf. path.ML);
wenzelm
parents:
diff changeset
   144
  def ext(e: String): Path =
4ac04bf9ff89 abstract algebra of file paths in Scala (cf. path.ML);
wenzelm
parents:
diff changeset
   145
    if (e == "") this
4ac04bf9ff89 abstract algebra of file paths in Scala (cf. path.ML);
wenzelm
parents:
diff changeset
   146
    else {
4ac04bf9ff89 abstract algebra of file paths in Scala (cf. path.ML);
wenzelm
parents:
diff changeset
   147
      val (prfx, s) = split_path
43604
ff33fea12337 more Path operations;
wenzelm
parents: 43601
diff changeset
   148
      prfx + Path.basic(s + "." + e)
43600
4ac04bf9ff89 abstract algebra of file paths in Scala (cf. path.ML);
wenzelm
parents:
diff changeset
   149
    }
43604
ff33fea12337 more Path operations;
wenzelm
parents: 43601
diff changeset
   150
43697
77ce24aa1770 explicit Document.Node.Header, with master_dir and thy_name;
wenzelm
parents: 43670
diff changeset
   151
  private val Ext = new Regex("(.*)\\.([^.]*)")
77ce24aa1770 explicit Document.Node.Header, with master_dir and thy_name;
wenzelm
parents: 43670
diff changeset
   152
77ce24aa1770 explicit Document.Node.Header, with master_dir and thy_name;
wenzelm
parents: 43670
diff changeset
   153
  def split_ext: (Path, String) =
77ce24aa1770 explicit Document.Node.Header, with master_dir and thy_name;
wenzelm
parents: 43670
diff changeset
   154
  {
77ce24aa1770 explicit Document.Node.Header, with master_dir and thy_name;
wenzelm
parents: 43670
diff changeset
   155
    val (prefix, base) = split_path
77ce24aa1770 explicit Document.Node.Header, with master_dir and thy_name;
wenzelm
parents: 43670
diff changeset
   156
    base match {
77ce24aa1770 explicit Document.Node.Header, with master_dir and thy_name;
wenzelm
parents: 43670
diff changeset
   157
      case Ext(b, e) => (prefix + Path.basic(b), e)
77ce24aa1770 explicit Document.Node.Header, with master_dir and thy_name;
wenzelm
parents: 43670
diff changeset
   158
      case _ => (Path.basic(base), "")
77ce24aa1770 explicit Document.Node.Header, with master_dir and thy_name;
wenzelm
parents: 43670
diff changeset
   159
    }
77ce24aa1770 explicit Document.Node.Header, with master_dir and thy_name;
wenzelm
parents: 43670
diff changeset
   160
  }
77ce24aa1770 explicit Document.Node.Header, with master_dir and thy_name;
wenzelm
parents: 43670
diff changeset
   161
43604
ff33fea12337 more Path operations;
wenzelm
parents: 43601
diff changeset
   162
ff33fea12337 more Path operations;
wenzelm
parents: 43601
diff changeset
   163
  /* expand */
ff33fea12337 more Path operations;
wenzelm
parents: 43601
diff changeset
   164
43664
wenzelm
parents: 43652
diff changeset
   165
  def expand: Path =
43604
ff33fea12337 more Path operations;
wenzelm
parents: 43601
diff changeset
   166
  {
ff33fea12337 more Path operations;
wenzelm
parents: 43601
diff changeset
   167
    def eval(elem: Path.Elem): List[Path.Elem] =
ff33fea12337 more Path operations;
wenzelm
parents: 43601
diff changeset
   168
      elem match {
43664
wenzelm
parents: 43652
diff changeset
   169
        case Path.Variable(s) =>
wenzelm
parents: 43652
diff changeset
   170
          Path.explode(Isabelle_System.getenv_strict(s)).elems
43604
ff33fea12337 more Path operations;
wenzelm
parents: 43601
diff changeset
   171
        case x => List(x)
ff33fea12337 more Path operations;
wenzelm
parents: 43601
diff changeset
   172
      }
ff33fea12337 more Path operations;
wenzelm
parents: 43601
diff changeset
   173
45244
c149b61bc372 class Path as abstract datatype;
wenzelm
parents: 43697
diff changeset
   174
    new Path(Path.norm_elems(elems.map(eval).flatten))
43604
ff33fea12337 more Path operations;
wenzelm
parents: 43601
diff changeset
   175
  }
48373
527e2bad7cca further imitation of "usedir" shell script;
wenzelm
parents: 47661
diff changeset
   176
527e2bad7cca further imitation of "usedir" shell script;
wenzelm
parents: 47661
diff changeset
   177
527e2bad7cca further imitation of "usedir" shell script;
wenzelm
parents: 47661
diff changeset
   178
  /* platform file */
527e2bad7cca further imitation of "usedir" shell script;
wenzelm
parents: 47661
diff changeset
   179
48409
0d2114eb412a more explicit java.io.{File => JFile};
wenzelm
parents: 48373
diff changeset
   180
  def file: JFile = Isabelle_System.platform_file(this)
43600
4ac04bf9ff89 abstract algebra of file paths in Scala (cf. path.ML);
wenzelm
parents:
diff changeset
   181
}