author | wenzelm |
Thu, 15 Oct 2020 13:47:55 +0200 | |
changeset 72479 | 7d0861af3cb0 |
parent 72162 | 5894859c5c84 |
child 72511 | 460d743010bc |
permissions | -rw-r--r-- |
6118 | 1 |
(* Title: Pure/General/path.ML |
5011 | 2 |
Author: Markus Wenzel, TU Muenchen |
3 |
||
43601 | 4 |
Algebra of file-system paths: basic POSIX notation, extended by named |
5 |
roots (e.g. //foo) and variables (e.g. $BAR). |
|
5011 | 6 |
*) |
7 |
||
8 |
signature PATH = |
|
9 |
sig |
|
6183 | 10 |
eqtype T |
6460 | 11 |
val is_current: T -> bool |
6183 | 12 |
val current: T |
13 |
val root: T |
|
36135
89d1903fbd50
support named_root, which approximates UNC server prefix (for Cygwin);
wenzelm
parents:
33957
diff
changeset
|
14 |
val named_root: string -> T |
6183 | 15 |
val parent: T |
69670 | 16 |
val make: string list -> T |
6183 | 17 |
val basic: string -> T |
18 |
val variable: string -> T |
|
69381
4c9b4e2c5460
more general command 'generate_file' for registered file types, notably Haskell;
wenzelm
parents:
69366
diff
changeset
|
19 |
val has_parent: T -> bool |
6183 | 20 |
val is_absolute: T -> bool |
21 |
val is_basic: T -> bool |
|
56533
cd8b6d849b6a
explicit 'document_files' in session ROOT specifications;
wenzelm
parents:
56136
diff
changeset
|
22 |
val starts_basic: T -> bool |
6183 | 23 |
val append: T -> T -> T |
6270 | 24 |
val appends: T list -> T |
21858
05f57309170c
avoid conflict with Alice keywords: renamed pack -> implode, unpack -> explode, any -> many, avoided assert;
wenzelm
parents:
19482
diff
changeset
|
25 |
val implode: T -> string |
05f57309170c
avoid conflict with Alice keywords: renamed pack -> implode, unpack -> explode, any -> many, avoided assert;
wenzelm
parents:
19482
diff
changeset
|
26 |
val explode: string -> T |
70015
c8e08d8ffb93
clarified signature: more explicit type Path.binding;
wenzelm
parents:
70013
diff
changeset
|
27 |
val explode_pos: string * Position.T -> T * Position.T |
59363
4660b0409096
added Path.decode in ML, in correspondence to Path.encode in Scala;
wenzelm
parents:
56533
diff
changeset
|
28 |
val decode: T XML.Decode.T |
53045 | 29 |
val split: string -> T list |
43593 | 30 |
val pretty: T -> Pretty.T |
31 |
val print: T -> string |
|
14912 | 32 |
val dir: T -> T |
6183 | 33 |
val base: T -> T |
34 |
val ext: string -> T -> T |
|
72479 | 35 |
val platform_exe: T -> T |
14912 | 36 |
val split_ext: T -> T * string |
70013 | 37 |
val exe: T -> T |
6183 | 38 |
val expand: T -> T |
69366 | 39 |
val file_name: T -> string |
72162 | 40 |
val implode_symbolic: T -> string |
26881 | 41 |
val position: T -> Position.T |
70015
c8e08d8ffb93
clarified signature: more explicit type Path.binding;
wenzelm
parents:
70013
diff
changeset
|
42 |
eqtype binding |
c8e08d8ffb93
clarified signature: more explicit type Path.binding;
wenzelm
parents:
70013
diff
changeset
|
43 |
val binding: T * Position.T -> binding |
c8e08d8ffb93
clarified signature: more explicit type Path.binding;
wenzelm
parents:
70013
diff
changeset
|
44 |
val binding0: T -> binding |
70020 | 45 |
val map_binding: (T -> T) -> binding -> binding |
70015
c8e08d8ffb93
clarified signature: more explicit type Path.binding;
wenzelm
parents:
70013
diff
changeset
|
46 |
val dest_binding: binding -> T * Position.T |
70048 | 47 |
val path_of_binding: binding -> T |
48 |
val pos_of_binding: binding -> Position.T |
|
70055
36fb663145e5
type Path.binding may be empty: check later via proper_binding;
wenzelm
parents:
70048
diff
changeset
|
49 |
val proper_binding: binding -> unit |
70015
c8e08d8ffb93
clarified signature: more explicit type Path.binding;
wenzelm
parents:
70013
diff
changeset
|
50 |
val implode_binding: binding -> string |
c8e08d8ffb93
clarified signature: more explicit type Path.binding;
wenzelm
parents:
70013
diff
changeset
|
51 |
val explode_binding: string * Position.T -> binding |
c8e08d8ffb93
clarified signature: more explicit type Path.binding;
wenzelm
parents:
70013
diff
changeset
|
52 |
val explode_binding0: string -> binding |
5011 | 53 |
end; |
54 |
||
6187 | 55 |
structure Path: PATH = |
5011 | 56 |
struct |
57 |
||
6183 | 58 |
(* path elements *) |
59 |
||
36135
89d1903fbd50
support named_root, which approximates UNC server prefix (for Cygwin);
wenzelm
parents:
33957
diff
changeset
|
60 |
datatype elem = |
89d1903fbd50
support named_root, which approximates UNC server prefix (for Cygwin);
wenzelm
parents:
33957
diff
changeset
|
61 |
Root of string | |
89d1903fbd50
support named_root, which approximates UNC server prefix (for Cygwin);
wenzelm
parents:
33957
diff
changeset
|
62 |
Basic of string | |
89d1903fbd50
support named_root, which approximates UNC server prefix (for Cygwin);
wenzelm
parents:
33957
diff
changeset
|
63 |
Variable of string | |
89d1903fbd50
support named_root, which approximates UNC server prefix (for Cygwin);
wenzelm
parents:
33957
diff
changeset
|
64 |
Parent; |
89d1903fbd50
support named_root, which approximates UNC server prefix (for Cygwin);
wenzelm
parents:
33957
diff
changeset
|
65 |
|
89d1903fbd50
support named_root, which approximates UNC server prefix (for Cygwin);
wenzelm
parents:
33957
diff
changeset
|
66 |
local |
6183 | 67 |
|
69547 | 68 |
fun err_elem msg s = error (msg ^ " path element " ^ quote s); |
6183 | 69 |
|
69548
415dc92050a6
more strict check: avoid confusion of Path.basic with Path.current / Path.parent;
wenzelm
parents:
69547
diff
changeset
|
70 |
val illegal_elem = ["", "~", "~~", ".", ".."]; |
69550
57ff523d9008
reject further illegal chars according to https://docs.microsoft.com/en-us/windows/desktop/fileio/naming-a-file
wenzelm
parents:
69549
diff
changeset
|
71 |
val illegal_char = ["/", "\\", "$", ":", "\"", "'", "<", ">", "|", "?", "*"]; |
69547 | 72 |
|
69627 | 73 |
fun check_elem s = |
69547 | 74 |
if member (op =) illegal_elem s then err_elem "Illegal" s |
52106 | 75 |
else |
69549 | 76 |
(s, ()) |-> fold_string (fn c => fn () => |
69550
57ff523d9008
reject further illegal chars according to https://docs.microsoft.com/en-us/windows/desktop/fileio/naming-a-file
wenzelm
parents:
69549
diff
changeset
|
77 |
if ord c < 32 then |
57ff523d9008
reject further illegal chars according to https://docs.microsoft.com/en-us/windows/desktop/fileio/naming-a-file
wenzelm
parents:
69549
diff
changeset
|
78 |
err_elem ("Illegal control character " ^ string_of_int (ord c) ^ " in") s |
57ff523d9008
reject further illegal chars according to https://docs.microsoft.com/en-us/windows/desktop/fileio/naming-a-file
wenzelm
parents:
69549
diff
changeset
|
79 |
else if member (op =) illegal_char c then |
69547 | 80 |
err_elem ("Illegal character " ^ quote c ^ " in") s |
69627 | 81 |
else ()); |
36135
89d1903fbd50
support named_root, which approximates UNC server prefix (for Cygwin);
wenzelm
parents:
33957
diff
changeset
|
82 |
|
69784
24bbc4e30e5b
clarified signature: Path.T as in Generated_Files;
wenzelm
parents:
69670
diff
changeset
|
83 |
in |
24bbc4e30e5b
clarified signature: Path.T as in Generated_Files;
wenzelm
parents:
69670
diff
changeset
|
84 |
|
69627 | 85 |
val root_elem = Root o tap check_elem; |
86 |
val basic_elem = Basic o tap check_elem; |
|
87 |
val variable_elem = Variable o tap check_elem; |
|
6183 | 88 |
|
36135
89d1903fbd50
support named_root, which approximates UNC server prefix (for Cygwin);
wenzelm
parents:
33957
diff
changeset
|
89 |
end; |
6183 | 90 |
|
91 |
||
5011 | 92 |
(* type path *) |
93 |
||
36135
89d1903fbd50
support named_root, which approximates UNC server prefix (for Cygwin);
wenzelm
parents:
33957
diff
changeset
|
94 |
datatype T = Path of elem list; (*reversed elements*) |
6183 | 95 |
|
96 |
fun rep (Path xs) = xs; |
|
5011 | 97 |
|
6460 | 98 |
fun is_current (Path []) = true |
99 |
| is_current _ = false; |
|
100 |
||
5011 | 101 |
val current = Path []; |
36135
89d1903fbd50
support named_root, which approximates UNC server prefix (for Cygwin);
wenzelm
parents:
33957
diff
changeset
|
102 |
val root = Path [Root ""]; |
52106 | 103 |
fun named_root s = Path [root_elem s]; |
69670 | 104 |
val make = Path o rev o map basic_elem; |
52106 | 105 |
fun basic s = Path [basic_elem s]; |
106 |
fun variable s = Path [variable_elem s]; |
|
36135
89d1903fbd50
support named_root, which approximates UNC server prefix (for Cygwin);
wenzelm
parents:
33957
diff
changeset
|
107 |
val parent = Path [Parent]; |
5011 | 108 |
|
69381
4c9b4e2c5460
more general command 'generate_file' for registered file types, notably Haskell;
wenzelm
parents:
69366
diff
changeset
|
109 |
fun has_parent (Path xs) = exists (fn Parent => true | _ => false) xs; |
4c9b4e2c5460
more general command 'generate_file' for registered file types, notably Haskell;
wenzelm
parents:
69366
diff
changeset
|
110 |
|
36135
89d1903fbd50
support named_root, which approximates UNC server prefix (for Cygwin);
wenzelm
parents:
33957
diff
changeset
|
111 |
fun is_absolute (Path xs) = |
89d1903fbd50
support named_root, which approximates UNC server prefix (for Cygwin);
wenzelm
parents:
33957
diff
changeset
|
112 |
(case try List.last xs of |
89d1903fbd50
support named_root, which approximates UNC server prefix (for Cygwin);
wenzelm
parents:
33957
diff
changeset
|
113 |
SOME (Root _) => true |
89d1903fbd50
support named_root, which approximates UNC server prefix (for Cygwin);
wenzelm
parents:
33957
diff
changeset
|
114 |
| _ => false); |
5011 | 115 |
|
6183 | 116 |
fun is_basic (Path [Basic _]) = true |
117 |
| is_basic _ = false; |
|
5011 | 118 |
|
69784
24bbc4e30e5b
clarified signature: Path.T as in Generated_Files;
wenzelm
parents:
69670
diff
changeset
|
119 |
fun all_basic (Path elems) = |
24bbc4e30e5b
clarified signature: Path.T as in Generated_Files;
wenzelm
parents:
69670
diff
changeset
|
120 |
forall (fn Basic _ => true | _ => false) elems; |
24bbc4e30e5b
clarified signature: Path.T as in Generated_Files;
wenzelm
parents:
69670
diff
changeset
|
121 |
|
56533
cd8b6d849b6a
explicit 'document_files' in session ROOT specifications;
wenzelm
parents:
56136
diff
changeset
|
122 |
fun starts_basic (Path xs) = |
cd8b6d849b6a
explicit 'document_files' in session ROOT specifications;
wenzelm
parents:
56136
diff
changeset
|
123 |
(case try List.last xs of |
cd8b6d849b6a
explicit 'document_files' in session ROOT specifications;
wenzelm
parents:
56136
diff
changeset
|
124 |
SOME (Basic _) => true |
cd8b6d849b6a
explicit 'document_files' in session ROOT specifications;
wenzelm
parents:
56136
diff
changeset
|
125 |
| _ => false); |
cd8b6d849b6a
explicit 'document_files' in session ROOT specifications;
wenzelm
parents:
56136
diff
changeset
|
126 |
|
5011 | 127 |
|
128 |
(* append and norm *) |
|
129 |
||
36135
89d1903fbd50
support named_root, which approximates UNC server prefix (for Cygwin);
wenzelm
parents:
33957
diff
changeset
|
130 |
fun apply (y as Root _) _ = [y] |
89d1903fbd50
support named_root, which approximates UNC server prefix (for Cygwin);
wenzelm
parents:
33957
diff
changeset
|
131 |
| apply Parent (xs as (Root _ :: _)) = xs |
89d1903fbd50
support named_root, which approximates UNC server prefix (for Cygwin);
wenzelm
parents:
33957
diff
changeset
|
132 |
| apply Parent (Basic _ :: rest) = rest |
89d1903fbd50
support named_root, which approximates UNC server prefix (for Cygwin);
wenzelm
parents:
33957
diff
changeset
|
133 |
| apply y xs = y :: xs; |
5011 | 134 |
|
36135
89d1903fbd50
support named_root, which approximates UNC server prefix (for Cygwin);
wenzelm
parents:
33957
diff
changeset
|
135 |
fun append (Path xs) (Path ys) = Path (fold_rev apply ys xs); |
15570 | 136 |
fun appends paths = Library.foldl (uncurry append) (current, paths); |
36135
89d1903fbd50
support named_root, which approximates UNC server prefix (for Cygwin);
wenzelm
parents:
33957
diff
changeset
|
137 |
|
89d1903fbd50
support named_root, which approximates UNC server prefix (for Cygwin);
wenzelm
parents:
33957
diff
changeset
|
138 |
fun norm elems = fold_rev apply elems []; |
5011 | 139 |
|
6183 | 140 |
|
21858
05f57309170c
avoid conflict with Alice keywords: renamed pack -> implode, unpack -> explode, any -> many, avoided assert;
wenzelm
parents:
19482
diff
changeset
|
141 |
(* implode *) |
5011 | 142 |
|
36135
89d1903fbd50
support named_root, which approximates UNC server prefix (for Cygwin);
wenzelm
parents:
33957
diff
changeset
|
143 |
local |
89d1903fbd50
support named_root, which approximates UNC server prefix (for Cygwin);
wenzelm
parents:
33957
diff
changeset
|
144 |
|
89d1903fbd50
support named_root, which approximates UNC server prefix (for Cygwin);
wenzelm
parents:
33957
diff
changeset
|
145 |
fun implode_elem (Root "") = "" |
89d1903fbd50
support named_root, which approximates UNC server prefix (for Cygwin);
wenzelm
parents:
33957
diff
changeset
|
146 |
| implode_elem (Root s) = "//" ^ s |
21858
05f57309170c
avoid conflict with Alice keywords: renamed pack -> implode, unpack -> explode, any -> many, avoided assert;
wenzelm
parents:
19482
diff
changeset
|
147 |
| implode_elem (Basic s) = s |
36135
89d1903fbd50
support named_root, which approximates UNC server prefix (for Cygwin);
wenzelm
parents:
33957
diff
changeset
|
148 |
| implode_elem (Variable s) = "$" ^ s |
89d1903fbd50
support named_root, which approximates UNC server prefix (for Cygwin);
wenzelm
parents:
33957
diff
changeset
|
149 |
| implode_elem Parent = ".."; |
89d1903fbd50
support named_root, which approximates UNC server prefix (for Cygwin);
wenzelm
parents:
33957
diff
changeset
|
150 |
|
89d1903fbd50
support named_root, which approximates UNC server prefix (for Cygwin);
wenzelm
parents:
33957
diff
changeset
|
151 |
in |
5011 | 152 |
|
21858
05f57309170c
avoid conflict with Alice keywords: renamed pack -> implode, unpack -> explode, any -> many, avoided assert;
wenzelm
parents:
19482
diff
changeset
|
153 |
fun implode_path (Path []) = "." |
36135
89d1903fbd50
support named_root, which approximates UNC server prefix (for Cygwin);
wenzelm
parents:
33957
diff
changeset
|
154 |
| implode_path (Path [Root ""]) = "/" |
89d1903fbd50
support named_root, which approximates UNC server prefix (for Cygwin);
wenzelm
parents:
33957
diff
changeset
|
155 |
| implode_path (Path xs) = space_implode "/" (rev (map implode_elem xs)); |
89d1903fbd50
support named_root, which approximates UNC server prefix (for Cygwin);
wenzelm
parents:
33957
diff
changeset
|
156 |
|
89d1903fbd50
support named_root, which approximates UNC server prefix (for Cygwin);
wenzelm
parents:
33957
diff
changeset
|
157 |
end; |
5011 | 158 |
|
159 |
||
21858
05f57309170c
avoid conflict with Alice keywords: renamed pack -> implode, unpack -> explode, any -> many, avoided assert;
wenzelm
parents:
19482
diff
changeset
|
160 |
(* explode *) |
6183 | 161 |
|
52106 | 162 |
fun explode_path str = |
163 |
let |
|
164 |
fun explode_elem s = |
|
165 |
(if s = ".." then Parent |
|
166 |
else if s = "~" then Variable "USER_HOME" |
|
167 |
else if s = "~~" then Variable "ISABELLE_HOME" |
|
168 |
else |
|
169 |
(case try (unprefix "$") s of |
|
170 |
SOME s' => variable_elem s' |
|
171 |
| NONE => basic_elem s)) |
|
172 |
handle ERROR msg => cat_error msg ("The error(s) above occurred in " ^ quote str); |
|
36135
89d1903fbd50
support named_root, which approximates UNC server prefix (for Cygwin);
wenzelm
parents:
33957
diff
changeset
|
173 |
|
52106 | 174 |
val (roots, raw_elems) = |
67522 | 175 |
(case chop_prefix (equal "") (space_explode "/" str) |>> length of |
52106 | 176 |
(0, es) => ([], es) |
177 |
| (1, es) => ([Root ""], es) |
|
178 |
| (_, []) => ([Root ""], []) |
|
179 |
| (_, e :: es) => ([root_elem e], es)); |
|
180 |
val elems = raw_elems |> filter_out (fn c => c = "" orelse c = ".") |> map explode_elem; |
|
6183 | 181 |
|
52106 | 182 |
in Path (norm (rev elems @ roots)) end; |
6183 | 183 |
|
70015
c8e08d8ffb93
clarified signature: more explicit type Path.binding;
wenzelm
parents:
70013
diff
changeset
|
184 |
fun explode_pos (s, pos) = |
c8e08d8ffb93
clarified signature: more explicit type Path.binding;
wenzelm
parents:
70013
diff
changeset
|
185 |
(explode_path s handle ERROR msg => error (msg ^ Position.here pos), pos); |
c8e08d8ffb93
clarified signature: more explicit type Path.binding;
wenzelm
parents:
70013
diff
changeset
|
186 |
|
53045 | 187 |
fun split str = |
188 |
space_explode ":" str |
|
189 |
|> map_filter (fn s => if s = "" then NONE else SOME (explode_path s)); |
|
190 |
||
59363
4660b0409096
added Path.decode in ML, in correspondence to Path.encode in Scala;
wenzelm
parents:
56533
diff
changeset
|
191 |
val decode = XML.Decode.string #> explode_path; |
4660b0409096
added Path.decode in ML, in correspondence to Path.encode in Scala;
wenzelm
parents:
56533
diff
changeset
|
192 |
|
5011 | 193 |
|
43593 | 194 |
(* print *) |
195 |
||
196 |
fun pretty path = |
|
197 |
let val s = implode_path path |
|
50201
c26369c9eda6
Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
wenzelm
parents:
48866
diff
changeset
|
198 |
in Pretty.mark (Markup.path s) (Pretty.str (quote s)) end; |
43593 | 199 |
|
61877
276ad4354069
renamed Pretty.str_of to Pretty.unformatted_string_of to emphasize its meaning;
wenzelm
parents:
59363
diff
changeset
|
200 |
val print = Pretty.unformatted_string_of o pretty; |
43593 | 201 |
|
62819
d3ff367a16a0
careful export of type-dependent functions, without losing their special status;
wenzelm
parents:
62663
diff
changeset
|
202 |
val _ = ML_system_pp (fn _ => fn _ => Pretty.to_polyml o pretty); |
62663 | 203 |
|
43593 | 204 |
|
6183 | 205 |
(* base element *) |
206 |
||
36135
89d1903fbd50
support named_root, which approximates UNC server prefix (for Cygwin);
wenzelm
parents:
33957
diff
changeset
|
207 |
fun split_path f (Path (Basic s :: xs)) = f (Path xs, s) |
43599 | 208 |
| split_path _ path = error ("Cannot split path into dir/base: " ^ print path); |
6183 | 209 |
|
36135
89d1903fbd50
support named_root, which approximates UNC server prefix (for Cygwin);
wenzelm
parents:
33957
diff
changeset
|
210 |
val dir = split_path #1; |
7929 | 211 |
val base = split_path (fn (_, s) => Path [Basic s]); |
6183 | 212 |
|
36135
89d1903fbd50
support named_root, which approximates UNC server prefix (for Cygwin);
wenzelm
parents:
33957
diff
changeset
|
213 |
fun ext "" = I |
89d1903fbd50
support named_root, which approximates UNC server prefix (for Cygwin);
wenzelm
parents:
33957
diff
changeset
|
214 |
| ext e = split_path (fn (prfx, s) => append prfx (basic (s ^ "." ^ e))); |
6183 | 215 |
|
72479 | 216 |
val platform_exe = ML_System.platform_is_windows ? ext "exe"; |
217 |
||
36135
89d1903fbd50
support named_root, which approximates UNC server prefix (for Cygwin);
wenzelm
parents:
33957
diff
changeset
|
218 |
val split_ext = split_path (fn (prfx, s) => apfst (append prfx) |
67522 | 219 |
(case chop_suffix (fn c => c <> ".") (raw_explode s) of |
14912 | 220 |
([], _) => (Path [Basic s], "") |
33957 | 221 |
| (cs, e) => (Path [Basic (implode (take (length cs - 1) cs))], implode e))); |
6319 | 222 |
|
70013 | 223 |
val exe = ML_System.platform_is_windows ? ext "exe"; |
224 |
||
6183 | 225 |
|
17827 | 226 |
(* expand variables *) |
5011 | 227 |
|
48658 | 228 |
fun eval (Variable s) = |
229 |
let val path = explode_path (getenv_strict s) in |
|
230 |
if exists (fn Variable _ => true | _ => false) (rep path) then |
|
231 |
error ("Illegal path variable nesting: " ^ s ^ "=" ^ print path) |
|
232 |
else rep path |
|
233 |
end |
|
17827 | 234 |
| eval x = [x]; |
5011 | 235 |
|
19482
9f11af8f7ef9
tuned basic list operators (flat, maps, map_filter);
wenzelm
parents:
19305
diff
changeset
|
236 |
val expand = rep #> maps eval #> norm #> Path; |
21858
05f57309170c
avoid conflict with Alice keywords: renamed pack -> implode, unpack -> explode, any -> many, avoided assert;
wenzelm
parents:
19482
diff
changeset
|
237 |
|
69366 | 238 |
val file_name = implode_path o base o expand; |
239 |
||
21858
05f57309170c
avoid conflict with Alice keywords: renamed pack -> implode, unpack -> explode, any -> many, avoided assert;
wenzelm
parents:
19482
diff
changeset
|
240 |
|
72162 | 241 |
(* implode wrt. given directories *) |
44863
49ea566cb3b4
more symbolic file positions via smart replacement of ISABELLE_HOME -- allows Isabelle distribution to be moved later on;
wenzelm
parents:
44161
diff
changeset
|
242 |
|
72162 | 243 |
fun implode_symbolic path = |
44863
49ea566cb3b4
more symbolic file positions via smart replacement of ISABELLE_HOME -- allows Isabelle distribution to be moved later on;
wenzelm
parents:
44161
diff
changeset
|
244 |
let |
72162 | 245 |
val directories = rev (space_explode ":" (getenv "ISABELLE_DIRECTORIES")); |
56134 | 246 |
val full_name = implode_path (expand path); |
56136 | 247 |
fun fold_path a = |
68519 | 248 |
(case try (implode_path o expand o explode_path) a of |
249 |
SOME b => |
|
250 |
if full_name = b then SOME a |
|
251 |
else |
|
252 |
(case try (unprefix (b ^ "/")) full_name of |
|
253 |
SOME name => SOME (a ^ "/" ^ name) |
|
254 |
| NONE => NONE) |
|
255 |
| NONE => NONE); |
|
44863
49ea566cb3b4
more symbolic file positions via smart replacement of ISABELLE_HOME -- allows Isabelle distribution to be moved later on;
wenzelm
parents:
44161
diff
changeset
|
256 |
in |
72162 | 257 |
(case get_first fold_path directories of |
56136 | 258 |
SOME name => name |
259 |
| NONE => implode_path path) |
|
44863
49ea566cb3b4
more symbolic file positions via smart replacement of ISABELLE_HOME -- allows Isabelle distribution to be moved later on;
wenzelm
parents:
44161
diff
changeset
|
260 |
end; |
26881 | 261 |
|
72162 | 262 |
val position = Position.file o implode_symbolic; |
26881 | 263 |
|
70015
c8e08d8ffb93
clarified signature: more explicit type Path.binding;
wenzelm
parents:
70013
diff
changeset
|
264 |
|
c8e08d8ffb93
clarified signature: more explicit type Path.binding;
wenzelm
parents:
70013
diff
changeset
|
265 |
(* binding: strictly monotonic path with position *) |
c8e08d8ffb93
clarified signature: more explicit type Path.binding;
wenzelm
parents:
70013
diff
changeset
|
266 |
|
c8e08d8ffb93
clarified signature: more explicit type Path.binding;
wenzelm
parents:
70013
diff
changeset
|
267 |
datatype binding = Binding of T * Position.T; |
c8e08d8ffb93
clarified signature: more explicit type Path.binding;
wenzelm
parents:
70013
diff
changeset
|
268 |
|
c8e08d8ffb93
clarified signature: more explicit type Path.binding;
wenzelm
parents:
70013
diff
changeset
|
269 |
fun binding (path, pos) = |
70055
36fb663145e5
type Path.binding may be empty: check later via proper_binding;
wenzelm
parents:
70048
diff
changeset
|
270 |
if all_basic path then Binding (path, pos) |
70015
c8e08d8ffb93
clarified signature: more explicit type Path.binding;
wenzelm
parents:
70013
diff
changeset
|
271 |
else error ("Bad path binding: " ^ print path ^ Position.here pos); |
c8e08d8ffb93
clarified signature: more explicit type Path.binding;
wenzelm
parents:
70013
diff
changeset
|
272 |
|
c8e08d8ffb93
clarified signature: more explicit type Path.binding;
wenzelm
parents:
70013
diff
changeset
|
273 |
fun binding0 path = binding (path, Position.none); |
70020 | 274 |
|
275 |
fun map_binding f (Binding (path, pos)) = binding (f path, pos); |
|
70015
c8e08d8ffb93
clarified signature: more explicit type Path.binding;
wenzelm
parents:
70013
diff
changeset
|
276 |
|
c8e08d8ffb93
clarified signature: more explicit type Path.binding;
wenzelm
parents:
70013
diff
changeset
|
277 |
fun dest_binding (Binding args) = args; |
70048 | 278 |
val path_of_binding = dest_binding #> #1; |
279 |
val pos_of_binding = dest_binding #> #2; |
|
70015
c8e08d8ffb93
clarified signature: more explicit type Path.binding;
wenzelm
parents:
70013
diff
changeset
|
280 |
|
70055
36fb663145e5
type Path.binding may be empty: check later via proper_binding;
wenzelm
parents:
70048
diff
changeset
|
281 |
fun proper_binding binding = |
36fb663145e5
type Path.binding may be empty: check later via proper_binding;
wenzelm
parents:
70048
diff
changeset
|
282 |
if is_current (path_of_binding binding) |
36fb663145e5
type Path.binding may be empty: check later via proper_binding;
wenzelm
parents:
70048
diff
changeset
|
283 |
then error ("Empty path" ^ Position.here (pos_of_binding binding)) |
36fb663145e5
type Path.binding may be empty: check later via proper_binding;
wenzelm
parents:
70048
diff
changeset
|
284 |
else (); |
36fb663145e5
type Path.binding may be empty: check later via proper_binding;
wenzelm
parents:
70048
diff
changeset
|
285 |
|
70048 | 286 |
val implode_binding = path_of_binding #> implode_path; |
70015
c8e08d8ffb93
clarified signature: more explicit type Path.binding;
wenzelm
parents:
70013
diff
changeset
|
287 |
|
c8e08d8ffb93
clarified signature: more explicit type Path.binding;
wenzelm
parents:
70013
diff
changeset
|
288 |
val explode_binding = binding o explode_pos; |
c8e08d8ffb93
clarified signature: more explicit type Path.binding;
wenzelm
parents:
70013
diff
changeset
|
289 |
fun explode_binding0 s = explode_binding (s, Position.none); |
c8e08d8ffb93
clarified signature: more explicit type Path.binding;
wenzelm
parents:
70013
diff
changeset
|
290 |
|
c8e08d8ffb93
clarified signature: more explicit type Path.binding;
wenzelm
parents:
70013
diff
changeset
|
291 |
|
21858
05f57309170c
avoid conflict with Alice keywords: renamed pack -> implode, unpack -> explode, any -> many, avoided assert;
wenzelm
parents:
19482
diff
changeset
|
292 |
(*final declarations of this structure!*) |
05f57309170c
avoid conflict with Alice keywords: renamed pack -> implode, unpack -> explode, any -> many, avoided assert;
wenzelm
parents:
19482
diff
changeset
|
293 |
val implode = implode_path; |
05f57309170c
avoid conflict with Alice keywords: renamed pack -> implode, unpack -> explode, any -> many, avoided assert;
wenzelm
parents:
19482
diff
changeset
|
294 |
val explode = explode_path; |
5011 | 295 |
|
296 |
end; |