278 (** naming context **) |
280 (** naming context **) |
279 |
281 |
280 (* datatype naming *) |
282 (* datatype naming *) |
281 |
283 |
282 datatype naming = Naming of |
284 datatype naming = Naming of |
283 {private: bool, |
285 {scopes: Binding.scope list, |
|
286 private: Binding.scope option, |
284 concealed: bool, |
287 concealed: bool, |
285 group: serial option, |
288 group: serial option, |
286 theory_name: string, |
289 theory_name: string, |
287 path: (string * bool) list}; |
290 path: (string * bool) list}; |
288 |
291 |
289 fun make_naming (private, concealed, group, theory_name, path) = |
292 fun make_naming (scopes, private, concealed, group, theory_name, path) = |
290 Naming {private = private, concealed = concealed, group = group, |
293 Naming {scopes = scopes, private = private, concealed = concealed, |
291 theory_name = theory_name, path = path}; |
294 group = group, theory_name = theory_name, path = path}; |
292 |
295 |
293 fun map_naming f (Naming {private, concealed, group, theory_name, path}) = |
296 fun map_naming f (Naming {scopes, private, concealed, group, theory_name, path}) = |
294 make_naming (f (private, concealed, group, theory_name, path)); |
297 make_naming (f (scopes, private, concealed, group, theory_name, path)); |
295 |
298 |
296 fun map_path f = map_naming (fn (private, concealed, group, theory_name, path) => |
299 fun map_path f = map_naming (fn (scopes, private, concealed, group, theory_name, path) => |
297 (private, concealed, group, theory_name, f path)); |
300 (scopes, private, concealed, group, theory_name, f path)); |
298 |
301 |
299 |
302 |
300 val private = map_naming (fn (_, concealed, group, theory_name, path) => |
303 fun get_scopes (Naming {scopes, ...}) = scopes; |
301 (true, concealed, group, theory_name, path)); |
304 val get_scope = try hd o get_scopes; |
302 |
305 |
303 val concealed = map_naming (fn (private, _, group, theory_name, path) => |
306 fun new_scope naming = |
304 (private, true, group, theory_name, path)); |
307 let |
305 |
308 val scope = Binding.new_scope (); |
306 fun set_theory_name theory_name = map_naming (fn (private, concealed, group, _, path) => |
309 val naming' = |
307 (private, concealed, group, theory_name, path)); |
310 naming |> map_naming (fn (scopes, private, concealed, group, theory_name, path) => |
308 |
311 (scope :: scopes, private, concealed, group, theory_name, path)); |
|
312 in (scope, naming') end; |
|
313 |
|
314 fun private scope = map_naming (fn (scopes, _, concealed, group, theory_name, path) => |
|
315 (scopes, SOME scope, concealed, group, theory_name, path)); |
|
316 |
|
317 val concealed = map_naming (fn (scopes, private, _, group, theory_name, path) => |
|
318 (scopes, private, true, group, theory_name, path)); |
|
319 |
|
320 fun set_theory_name theory_name = map_naming (fn (scopes, private, concealed, group, _, path) => |
|
321 (scopes, private, concealed, group, theory_name, path)); |
309 |
322 |
310 fun get_group (Naming {group, ...}) = group; |
323 fun get_group (Naming {group, ...}) = group; |
311 |
324 |
312 fun set_group group = map_naming (fn (private, concealed, _, theory_name, path) => |
325 fun set_group group = map_naming (fn (scopes, private, concealed, _, theory_name, path) => |
313 (private, concealed, group, theory_name, path)); |
326 (scopes, private, concealed, group, theory_name, path)); |
314 |
327 |
315 fun new_group naming = set_group (SOME (serial ())) naming; |
328 fun new_group naming = set_group (SOME (serial ())) naming; |
316 val reset_group = set_group NONE; |
329 val reset_group = set_group NONE; |
317 |
330 |
318 fun get_path (Naming {path, ...}) = path; |
331 fun get_path (Naming {path, ...}) = path; |
323 fun mandatory_path elems = map_path (fn path => path @ [(elems, true)]); |
336 fun mandatory_path elems = map_path (fn path => path @ [(elems, true)]); |
324 |
337 |
325 fun qualified_path mandatory binding = map_path (fn path => |
338 fun qualified_path mandatory binding = map_path (fn path => |
326 path @ Binding.path_of (Binding.qualified mandatory "" binding)); |
339 path @ Binding.path_of (Binding.qualified mandatory "" binding)); |
327 |
340 |
328 val global_naming = make_naming (false, false, NONE, "", []); |
341 val global_naming = make_naming ([], NONE, false, NONE, "", []); |
329 val local_naming = global_naming |> add_path Long_Name.localN; |
342 val local_naming = global_naming |> add_path Long_Name.localN; |
330 |
343 |
331 |
344 |
332 (* full name *) |
345 (* full name *) |
333 |
346 |
334 fun transform_binding (Naming {private, concealed, ...}) = |
347 fun transform_binding (Naming {private, concealed, ...}) = |
335 private ? Binding.private #> |
348 Binding.private_default private #> |
336 concealed ? Binding.concealed; |
349 concealed ? Binding.concealed; |
337 |
350 |
338 fun name_spec naming binding = |
351 fun name_spec naming binding = |
339 Binding.name_spec (get_path naming) (transform_binding naming binding); |
352 Binding.name_spec (get_scopes naming) (get_path naming) (transform_binding naming binding); |
340 |
353 |
341 fun full_name naming = |
354 fun full_name naming = |
342 name_spec naming #> #spec #> map #1 #> Long_Name.implode; |
355 name_spec naming #> #spec #> map #1 #> Long_Name.implode; |
343 |
356 |
344 val base_name = full_name global_naming #> Long_Name.base_name; |
357 val base_name = full_name global_naming #> Long_Name.base_name; |