src/Pure/sign.ML
changeset 28861 f53abb0733ee
parent 28792 1d80cee865de
child 28863 32e83a854e5e
equal deleted inserted replaced
28860:b1d46059d502 28861:f53abb0733ee
    16   val naming_of: theory -> NameSpace.naming
    16   val naming_of: theory -> NameSpace.naming
    17   val base_name: string -> bstring
    17   val base_name: string -> bstring
    18   val name_decl: (string * 'a -> theory -> 'b * theory)
    18   val name_decl: (string * 'a -> theory -> 'b * theory)
    19     -> Name.binding * 'a -> theory -> (string * 'b) * theory
    19     -> Name.binding * 'a -> theory -> (string * 'b) * theory
    20   val full_name: theory -> bstring -> string
    20   val full_name: theory -> bstring -> string
       
    21   val full_binding: theory -> Name.binding -> string
    21   val full_name_path: theory -> string -> bstring -> string
    22   val full_name_path: theory -> string -> bstring -> string
    22   val declare_name: theory -> string -> NameSpace.T -> NameSpace.T
    23   val declare_name: theory -> string -> NameSpace.T -> NameSpace.T
    23   val syn_of: theory -> Syntax.syntax
    24   val syn_of: theory -> Syntax.syntax
    24   val tsig_of: theory -> Type.tsig
    25   val tsig_of: theory -> Type.tsig
    25   val classes_of: theory -> Sorts.algebra
    26   val classes_of: theory -> Sorts.algebra
    91   val add_modesyntax: Syntax.mode -> (bstring * string * mixfix) list -> theory -> theory
    92   val add_modesyntax: Syntax.mode -> (bstring * string * mixfix) list -> theory -> theory
    92   val add_modesyntax_i: Syntax.mode -> (bstring * typ * mixfix) list -> theory -> theory
    93   val add_modesyntax_i: Syntax.mode -> (bstring * typ * mixfix) list -> theory -> theory
    93   val del_modesyntax: Syntax.mode -> (bstring * string * mixfix) list -> theory -> theory
    94   val del_modesyntax: Syntax.mode -> (bstring * string * mixfix) list -> theory -> theory
    94   val del_modesyntax_i: Syntax.mode -> (bstring * typ * mixfix) list -> theory -> theory
    95   val del_modesyntax_i: Syntax.mode -> (bstring * typ * mixfix) list -> theory -> theory
    95   val notation: bool -> Syntax.mode -> (term * mixfix) list -> theory -> theory
    96   val notation: bool -> Syntax.mode -> (term * mixfix) list -> theory -> theory
       
    97   val declare_const: Properties.T -> (Name.binding * typ) * mixfix -> theory -> term * theory
    96   val add_consts: (bstring * string * mixfix) list -> theory -> theory
    98   val add_consts: (bstring * string * mixfix) list -> theory -> theory
    97   val add_consts_i: (bstring * typ * mixfix) list -> theory -> theory
    99   val add_consts_i: (bstring * typ * mixfix) list -> theory -> theory
    98   val declare_const: Properties.T -> (Name.binding * typ) * mixfix -> theory -> term * theory
   100   val add_abbrev: string -> Properties.T -> Name.binding * term -> theory -> (term * term) * theory
    99   val add_abbrev: string -> Properties.T -> bstring * term -> theory -> (term * term) * theory
       
   100   val revert_abbrev: string -> string -> theory -> theory
   101   val revert_abbrev: string -> string -> theory -> theory
   101   val add_const_constraint: string * typ option -> theory -> theory
   102   val add_const_constraint: string * typ option -> theory -> theory
   102   val primitive_class: string * class list -> theory -> theory
   103   val primitive_class: string * class list -> theory -> theory
   103   val primitive_classrel: class * class -> theory -> theory
   104   val primitive_classrel: class * class -> theory -> theory
   104   val primitive_arity: arity -> theory -> theory
   105   val primitive_arity: arity -> theory -> theory
   188 (* naming *)
   189 (* naming *)
   189 
   190 
   190 val naming_of = #naming o rep_sg;
   191 val naming_of = #naming o rep_sg;
   191 val base_name = NameSpace.base;
   192 val base_name = NameSpace.base;
   192 
   193 
   193 fun name_decl decl (binding, x) thy =
   194 fun name_decl decl (b, x) thy =
   194   let
   195   let
   195     val naming = naming_of thy;
   196     val naming = naming_of thy;
   196     val (naming', name) = Name.namify naming binding;
   197     val (naming', name) = Name.namify naming b;
   197   in
   198   in
   198     thy
   199     thy
   199     |> map_naming (K naming')
   200     |> map_naming (K naming')
   200     |> decl (Name.name_of binding, x)
   201     |> decl (Name.name_of b, x)
   201     |>> pair name
   202     |>> pair name
   202     ||> map_naming (K naming)
   203     ||> map_naming (K naming)
   203   end;
   204   end;
   204 
   205 
   205 val namify = Name.namify o naming_of;
   206 val namify = Name.namify o naming_of;
   206 val full_name = NameSpace.full o naming_of;
   207 val full_name = NameSpace.full o naming_of;
       
   208 val full_binding = NameSpace.full_binding o naming_of;
   207 fun full_name_path thy elems = NameSpace.full (NameSpace.add_path elems (naming_of thy));
   209 fun full_name_path thy elems = NameSpace.full (NameSpace.add_path elems (naming_of thy));
   208 val declare_name = NameSpace.declare o naming_of;
   210 val declare_name = NameSpace.declare o naming_of;
   209 
   211 
   210 
   212 
   211 (* syntax *)
   213 (* syntax *)
   518 
   520 
   519 fun gen_add_consts parse_typ authentic tags raw_args thy =
   521 fun gen_add_consts parse_typ authentic tags raw_args thy =
   520   let
   522   let
   521     val ctxt = ProofContext.init thy;
   523     val ctxt = ProofContext.init thy;
   522     val prepT = Type.no_tvars o Term.no_dummyT o certify_typ thy o parse_typ ctxt;
   524     val prepT = Type.no_tvars o Term.no_dummyT o certify_typ thy o parse_typ ctxt;
   523     fun prep (raw_c, raw_T, raw_mx) =
   525     fun prep (raw_b, raw_T, raw_mx) =
   524       let
   526       let
   525         val (c, mx) = Syntax.const_mixfix raw_c raw_mx;
   527         val (mx_name, mx) = Syntax.const_mixfix (Name.name_of raw_b) raw_mx;
   526         val full_c = full_name thy c;
   528         val b = Name.map_name (K mx_name) raw_b;
   527         val c' = if authentic then Syntax.constN ^ full_c else c;
   529         val c = full_binding thy b;
       
   530         val c_syn = if authentic then Syntax.constN ^ c else Name.name_of b;
   528         val T = (prepT raw_T handle TYPE (msg, _, _) => error msg) handle ERROR msg =>
   531         val T = (prepT raw_T handle TYPE (msg, _, _) => error msg) handle ERROR msg =>
   529           cat_error msg ("in declaration of constant " ^ quote c);
   532           cat_error msg ("in declaration of constant " ^ quote (Name.display b));
   530         val T' = Logic.varifyT T;
   533         val T' = Logic.varifyT T;
   531       in ((c, T'), (c', T', mx), Const (full_c, T)) end;
   534       in ((b, T'), (c_syn, T', mx), Const (c, T)) end;
   532     val args = map prep raw_args;
   535     val args = map prep raw_args;
   533     val tags' = tags |> Properties.put (Markup.theory_nameN, Context.theory_name thy);
   536     val tags' = tags |> Properties.put (Markup.theory_nameN, Context.theory_name thy);
   534   in
   537   in
   535     thy
   538     thy
   536     |> map_consts (fold (Consts.declare authentic (naming_of thy) tags' o #1) args)
   539     |> map_consts (fold (Consts.declare authentic (naming_of thy) tags' o #1) args)
   537     |> add_syntax_i (map #2 args)
   540     |> add_syntax_i (map #2 args)
   538     |> pair (map #3 args)
   541     |> pair (map #3 args)
   539   end;
   542   end;
   540 
   543 
       
   544 fun bindify (name, T, mx) = (Name.binding name, T, mx);
       
   545 
   541 in
   546 in
   542 
   547 
   543 val add_consts = snd oo gen_add_consts Syntax.parse_typ false [];
   548 fun add_consts args = snd o gen_add_consts Syntax.parse_typ false [] (map bindify args);
   544 val add_consts_i = snd oo gen_add_consts (K I) false [];
   549 fun add_consts_i args = snd o gen_add_consts (K I) false [] (map bindify args);
   545 
   550 
   546 fun declare_const tags ((b, T), mx) thy =
   551 fun declare_const tags ((b, T), mx) thy =
   547   let
   552   let
   548     val c = Name.name_of b;
       
   549     val pos = Name.pos_of b;
   553     val pos = Name.pos_of b;
   550     val tags' = Position.default_properties pos tags;
   554     val tags' = Position.default_properties pos tags;
   551     val ([const as Const (full_c, _)], thy') = gen_add_consts (K I) true tags' [(c, T, mx)] thy;
   555     val ([const as Const (c, _)], thy') = gen_add_consts (K I) true tags' [(b, T, mx)] thy;
   552     val _ = Position.report (Markup.const_decl full_c) pos;
   556     val _ = Position.report (Markup.const_decl c) pos;
   553   in (const, thy') end;
   557   in (const, thy') end;
   554 
   558 
   555 end;
   559 end;
   556 
   560 
   557 
   561 
   558 (* abbreviations *)
   562 (* abbreviations *)
   559 
   563 
   560 fun add_abbrev mode tags (c, raw_t) thy =
   564 fun add_abbrev mode tags (b, raw_t) thy =
   561   let
   565   let
   562     val pp = Syntax.pp_global thy;
   566     val pp = Syntax.pp_global thy;
   563     val prep_tm = no_frees pp o Term.no_dummy_patterns o cert_term_abbrev thy;
   567     val prep_tm = no_frees pp o Term.no_dummy_patterns o cert_term_abbrev thy;
   564     val t = (prep_tm raw_t handle TYPE (msg, _, _) => error msg | TERM (msg, _) => error msg)
   568     val t = (prep_tm raw_t handle TYPE (msg, _, _) => error msg | TERM (msg, _) => error msg)
   565       handle ERROR msg => cat_error msg ("in constant abbreviation " ^ quote c);
   569       handle ERROR msg => cat_error msg ("in constant abbreviation " ^ quote (Name.display b));
   566     val (res, consts') = consts_of thy
   570     val (res, consts') = consts_of thy
   567       |> Consts.abbreviate pp (tsig_of thy) (naming_of thy) mode tags (c, t);
   571       |> Consts.abbreviate pp (tsig_of thy) (naming_of thy) mode tags (b, t);
   568   in (res, thy |> map_consts (K consts')) end;
   572   in (res, thy |> map_consts (K consts')) end;
   569 
   573 
   570 fun revert_abbrev mode c = map_consts (Consts.revert_abbrev mode c);
   574 fun revert_abbrev mode c = map_consts (Consts.revert_abbrev mode c);
   571 
   575 
   572 
   576