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