332 (* add type constructors *) |
332 (* add type constructors *) |
333 |
333 |
334 fun add_types types thy = thy |> map_sign (fn (naming, syn, tsig, consts) => |
334 fun add_types types thy = thy |> map_sign (fn (naming, syn, tsig, consts) => |
335 let |
335 let |
336 fun type_syntax (b, n, mx) = |
336 fun type_syntax (b, n, mx) = |
337 (Syntax.mark_type (Name_Space.full_name naming b), Mixfix.make_type n, mx); |
337 (Lexicon.mark_type (Name_Space.full_name naming b), Mixfix.make_type n, mx); |
338 val syn' = Syntax.update_type_gram true Syntax.mode_default (map type_syntax types) syn; |
338 val syn' = Syntax.update_type_gram true Syntax.mode_default (map type_syntax types) syn; |
339 val tsig' = fold (fn (a, n, _) => Type.add_type naming (a, n)) types tsig; |
339 val tsig' = fold (fn (a, n, _) => Type.add_type naming (a, n)) types tsig; |
340 in (naming, syn', tsig', consts) end); |
340 in (naming, syn', tsig', consts) end); |
341 |
341 |
342 |
342 |
371 val del_modesyntax_i = gen_syntax (Syntax.update_const_gram false) (K I); |
371 val del_modesyntax_i = gen_syntax (Syntax.update_const_gram false) (K I); |
372 |
372 |
373 fun type_notation add mode args = |
373 fun type_notation add mode args = |
374 let |
374 let |
375 fun type_syntax (Type (c, args), mx) = |
375 fun type_syntax (Type (c, args), mx) = |
376 SOME (Syntax.mark_type c, Mixfix.make_type (length args), mx) |
376 SOME (Lexicon.mark_type c, Mixfix.make_type (length args), mx) |
377 | type_syntax _ = NONE; |
377 | type_syntax _ = NONE; |
378 in map_syn (Syntax.update_type_gram add mode (map_filter type_syntax args)) end; |
378 in map_syn (Syntax.update_type_gram add mode (map_filter type_syntax args)) end; |
379 |
379 |
380 fun notation add mode args thy = |
380 fun notation add mode args thy = |
381 let |
381 let |
382 fun const_syntax (Const (c, _), mx) = |
382 fun const_syntax (Const (c, _), mx) = |
383 (case try (Consts.type_scheme (consts_of thy)) c of |
383 (case try (Consts.type_scheme (consts_of thy)) c of |
384 SOME T => SOME (Syntax.mark_const c, T, mx) |
384 SOME T => SOME (Lexicon.mark_const c, T, mx) |
385 | NONE => NONE) |
385 | NONE => NONE) |
386 | const_syntax _ = NONE; |
386 | const_syntax _ = NONE; |
387 in gen_syntax (Syntax.update_const_gram add) (K I) mode (map_filter const_syntax args) thy end; |
387 in gen_syntax (Syntax.update_const_gram add) (K I) mode (map_filter const_syntax args) thy end; |
388 |
388 |
389 |
389 |
399 let |
399 let |
400 val c = full_name thy b; |
400 val c = full_name thy b; |
401 val T = (prepT raw_T handle TYPE (msg, _, _) => error msg) handle ERROR msg => |
401 val T = (prepT raw_T handle TYPE (msg, _, _) => error msg) handle ERROR msg => |
402 cat_error msg ("in declaration of constant " ^ quote (Binding.str_of b)); |
402 cat_error msg ("in declaration of constant " ^ quote (Binding.str_of b)); |
403 val T' = Logic.varifyT_global T; |
403 val T' = Logic.varifyT_global T; |
404 in ((b, T'), (Syntax.mark_const c, T', mx), Const (c, T)) end; |
404 in ((b, T'), (Lexicon.mark_const c, T', mx), Const (c, T)) end; |
405 val args = map prep raw_args; |
405 val args = map prep raw_args; |
406 in |
406 in |
407 thy |
407 thy |
408 |> map_consts (fold (Consts.declare (naming_of thy) o #1) args) |
408 |> map_consts (fold (Consts.declare (naming_of thy) o #1) args) |
409 |> add_syntax_i (map #2 args) |
409 |> add_syntax_i (map #2 args) |