src/Pure/sign.ML
changeset 30343 79f022df8527
parent 30280 eb98b49ef835
child 30364 577edc39b501
equal deleted inserted replaced
30342:d32daa6aba3c 30343:79f022df8527
    12     syn: Syntax.syntax,
    12     syn: Syntax.syntax,
    13     tsig: Type.tsig,
    13     tsig: Type.tsig,
    14     consts: Consts.T}
    14     consts: Consts.T}
    15   val naming_of: theory -> NameSpace.naming
    15   val naming_of: theory -> NameSpace.naming
    16   val full_name: theory -> binding -> string
    16   val full_name: theory -> binding -> string
       
    17   val full_name_path: theory -> string -> binding -> string
    17   val full_bname: theory -> bstring -> string
    18   val full_bname: theory -> bstring -> string
    18   val full_bname_path: theory -> string -> bstring -> string
    19   val full_bname_path: theory -> string -> bstring -> string
    19   val syn_of: theory -> Syntax.syntax
    20   val syn_of: theory -> Syntax.syntax
    20   val tsig_of: theory -> Type.tsig
    21   val tsig_of: theory -> Type.tsig
    21   val classes_of: theory -> Sorts.algebra
    22   val classes_of: theory -> Sorts.algebra
    76   val read_class: theory -> xstring -> class
    77   val read_class: theory -> xstring -> class
    77   val read_arity: theory -> xstring * string list * string -> arity
    78   val read_arity: theory -> xstring * string list * string -> arity
    78   val cert_arity: theory -> arity -> arity
    79   val cert_arity: theory -> arity -> arity
    79   val add_defsort: string -> theory -> theory
    80   val add_defsort: string -> theory -> theory
    80   val add_defsort_i: sort -> theory -> theory
    81   val add_defsort_i: sort -> theory -> theory
    81   val add_types: (bstring * int * mixfix) list -> theory -> theory
    82   val add_types: (binding * int * mixfix) list -> theory -> theory
    82   val add_nonterminals: bstring list -> theory -> theory
    83   val add_nonterminals: binding list -> theory -> theory
    83   val add_tyabbrs: (bstring * string list * string * mixfix) list -> theory -> theory
    84   val add_tyabbrs: (binding * string list * string * mixfix) list -> theory -> theory
    84   val add_tyabbrs_i: (bstring * string list * typ * mixfix) list -> theory -> theory
    85   val add_tyabbrs_i: (binding * string list * typ * mixfix) list -> theory -> theory
    85   val add_syntax: (bstring * string * mixfix) list -> theory -> theory
    86   val add_syntax: (string * string * mixfix) list -> theory -> theory
    86   val add_syntax_i: (bstring * typ * mixfix) list -> theory -> theory
    87   val add_syntax_i: (string * typ * mixfix) list -> theory -> theory
    87   val add_modesyntax: Syntax.mode -> (bstring * string * mixfix) list -> theory -> theory
    88   val add_modesyntax: Syntax.mode -> (string * string * mixfix) list -> theory -> theory
    88   val add_modesyntax_i: Syntax.mode -> (bstring * typ * mixfix) list -> theory -> theory
    89   val add_modesyntax_i: Syntax.mode -> (string * typ * mixfix) list -> theory -> theory
    89   val del_modesyntax: Syntax.mode -> (bstring * string * mixfix) list -> theory -> theory
    90   val del_modesyntax: Syntax.mode -> (string * string * mixfix) list -> theory -> theory
    90   val del_modesyntax_i: Syntax.mode -> (bstring * typ * mixfix) list -> theory -> theory
    91   val del_modesyntax_i: Syntax.mode -> (string * typ * mixfix) list -> theory -> theory
    91   val notation: bool -> Syntax.mode -> (term * mixfix) list -> theory -> theory
    92   val notation: bool -> Syntax.mode -> (term * mixfix) list -> theory -> theory
    92   val declare_const: Properties.T -> (binding * typ) * mixfix -> theory -> term * theory
    93   val declare_const: Properties.T -> (binding * typ) * mixfix -> theory -> term * theory
    93   val add_consts: (bstring * string * mixfix) list -> theory -> theory
    94   val add_consts: (binding * string * mixfix) list -> theory -> theory
    94   val add_consts_i: (bstring * typ * mixfix) list -> theory -> theory
    95   val add_consts_i: (binding * typ * mixfix) list -> theory -> theory
    95   val add_abbrev: string -> Properties.T -> binding * term -> theory -> (term * term) * theory
    96   val add_abbrev: string -> Properties.T -> binding * term -> theory -> (term * term) * theory
    96   val revert_abbrev: string -> string -> theory -> theory
    97   val revert_abbrev: string -> string -> theory -> theory
    97   val add_const_constraint: string * typ option -> theory -> theory
    98   val add_const_constraint: string * typ option -> theory -> theory
    98   val primitive_class: string * class list -> theory -> theory
    99   val primitive_class: binding * class list -> theory -> theory
    99   val primitive_classrel: class * class -> theory -> theory
   100   val primitive_classrel: class * class -> theory -> theory
   100   val primitive_arity: arity -> theory -> theory
   101   val primitive_arity: arity -> theory -> theory
   101   val add_trfuns:
   102   val add_trfuns:
   102     (string * (ast list -> ast)) list *
   103     (string * (ast list -> ast)) list *
   103     (string * (term list -> term)) list *
   104     (string * (term list -> term)) list *
   184 (* naming *)
   185 (* naming *)
   185 
   186 
   186 val naming_of = #naming o rep_sg;
   187 val naming_of = #naming o rep_sg;
   187 
   188 
   188 val full_name = NameSpace.full_name o naming_of;
   189 val full_name = NameSpace.full_name o naming_of;
       
   190 fun full_name_path thy path = NameSpace.full_name (NameSpace.add_path path (naming_of thy));
       
   191 
   189 fun full_bname thy = NameSpace.full_name (naming_of thy) o Binding.name;
   192 fun full_bname thy = NameSpace.full_name (naming_of thy) o Binding.name;
   190 fun full_bname_path thy elems =
   193 fun full_bname_path thy path = full_name_path thy path o Binding.name;
   191   NameSpace.full_name (NameSpace.add_path elems (naming_of thy)) o Binding.name;
       
   192 
   194 
   193 
   195 
   194 (* syntax *)
   196 (* syntax *)
   195 
   197 
   196 val syn_of = #syn o rep_sg;
   198 val syn_of = #syn o rep_sg;
   433 
   435 
   434 (* add type constructors *)
   436 (* add type constructors *)
   435 
   437 
   436 fun add_types types thy = thy |> map_sign (fn (naming, syn, tsig, consts) =>
   438 fun add_types types thy = thy |> map_sign (fn (naming, syn, tsig, consts) =>
   437   let
   439   let
   438     val syn' = Syntax.update_type_gram types syn;
   440     val syn' = Syntax.update_type_gram (map (fn (a, n, mx) => (Binding.name_of a, n, mx)) types) syn;
   439     val decls = map (fn (a, n, mx) => (Syntax.type_name a mx, n)) types;
   441     val decls = map (fn (a, n, mx) => (Binding.map_name (Syntax.type_name mx) a, n)) types;
   440     val tags = [(Markup.theory_nameN, Context.theory_name thy)];
   442     val tags = [(Markup.theory_nameN, Context.theory_name thy)];
   441     val tsig' = fold (Type.add_type naming tags) decls tsig;
   443     val tsig' = fold (Type.add_type naming tags) decls tsig;
   442   in (naming, syn', tsig', consts) end);
   444   in (naming, syn', tsig', consts) end);
   443 
   445 
   444 
   446 
   445 (* add nonterminals *)
   447 (* add nonterminals *)
   446 
   448 
   447 fun add_nonterminals ns thy = thy |> map_sign (fn (naming, syn, tsig, consts) =>
   449 fun add_nonterminals ns thy = thy |> map_sign (fn (naming, syn, tsig, consts) =>
   448   let
   450   let
   449     val syn' = Syntax.update_consts ns syn;
   451     val syn' = Syntax.update_consts (map Binding.name_of ns) syn;
   450     val tsig' = fold (Type.add_nonterminal naming []) ns tsig;
   452     val tsig' = fold (Type.add_nonterminal naming []) ns tsig;
   451   in (naming, syn', tsig', consts) end);
   453   in (naming, syn', tsig', consts) end);
   452 
   454 
   453 
   455 
   454 (* add type abbreviations *)
   456 (* add type abbreviations *)
   455 
   457 
   456 fun gen_add_tyabbr parse_typ (a, vs, rhs, mx) thy =
   458 fun gen_add_tyabbr parse_typ (a, vs, rhs, mx) thy =
   457   thy |> map_sign (fn (naming, syn, tsig, consts) =>
   459   thy |> map_sign (fn (naming, syn, tsig, consts) =>
   458     let
   460     let
   459       val ctxt = ProofContext.init thy;
   461       val ctxt = ProofContext.init thy;
   460       val syn' = Syntax.update_type_gram [(a, length vs, mx)] syn;
   462       val syn' = Syntax.update_type_gram [(Binding.name_of a, length vs, mx)] syn;
   461       val a' = Syntax.type_name a mx;
   463       val b = Binding.map_name (Syntax.type_name mx) a;
   462       val abbr = (a', vs, certify_typ_mode Type.mode_syntax thy (parse_typ ctxt rhs))
   464       val abbr = (b, vs, certify_typ_mode Type.mode_syntax thy (parse_typ ctxt rhs))
   463         handle ERROR msg => cat_error msg ("in type abbreviation " ^ quote a');
   465         handle ERROR msg => cat_error msg ("in type abbreviation " ^ quote (Binding.str_of b));
   464       val tsig' = Type.add_abbrev naming [] abbr tsig;
   466       val tsig' = Type.add_abbrev naming [] abbr tsig;
   465     in (naming, syn', tsig', consts) end);
   467     in (naming, syn', tsig', consts) end);
   466 
   468 
   467 val add_tyabbrs = fold (gen_add_tyabbr Syntax.parse_typ);
   469 val add_tyabbrs = fold (gen_add_tyabbr Syntax.parse_typ);
   468 val add_tyabbrs_i = fold (gen_add_tyabbr (K I));
   470 val add_tyabbrs_i = fold (gen_add_tyabbr (K I));
   473 fun gen_syntax change_gram parse_typ mode args thy =
   475 fun gen_syntax change_gram parse_typ mode args thy =
   474   let
   476   let
   475     val ctxt = ProofContext.init thy;
   477     val ctxt = ProofContext.init thy;
   476     fun prep (c, T, mx) = (c, certify_typ_mode Type.mode_syntax thy (parse_typ ctxt T), mx)
   478     fun prep (c, T, mx) = (c, certify_typ_mode Type.mode_syntax thy (parse_typ ctxt T), mx)
   477       handle ERROR msg =>
   479       handle ERROR msg =>
   478         cat_error msg ("in syntax declaration " ^ quote (Syntax.const_name c mx));
   480         cat_error msg ("in syntax declaration " ^ quote (Syntax.const_name mx c));
   479   in thy |> map_syn (change_gram (is_logtype thy) mode (map prep args)) end;
   481   in thy |> map_syn (change_gram (is_logtype thy) mode (map prep args)) end;
   480 
   482 
   481 fun gen_add_syntax x = gen_syntax Syntax.update_const_gram x;
   483 fun gen_add_syntax x = gen_syntax Syntax.update_const_gram x;
   482 
   484 
   483 val add_modesyntax = gen_add_syntax Syntax.parse_typ;
   485 val add_modesyntax = gen_add_syntax Syntax.parse_typ;
   520     |> map_consts (fold (Consts.declare authentic (naming_of thy) tags' o #1) args)
   522     |> map_consts (fold (Consts.declare authentic (naming_of thy) tags' o #1) args)
   521     |> add_syntax_i (map #2 args)
   523     |> add_syntax_i (map #2 args)
   522     |> pair (map #3 args)
   524     |> pair (map #3 args)
   523   end;
   525   end;
   524 
   526 
   525 fun bindify (name, T, mx) = (Binding.name name, T, mx);
       
   526 
       
   527 in
   527 in
   528 
   528 
   529 fun add_consts args = snd o gen_add_consts Syntax.parse_typ false [] (map bindify args);
   529 fun add_consts args = snd o gen_add_consts Syntax.parse_typ false [] args;
   530 fun add_consts_i args = snd o gen_add_consts (K I) false [] (map bindify args);
   530 fun add_consts_i args = snd o gen_add_consts (K I) false [] args;
   531 
   531 
   532 fun declare_const tags ((b, T), mx) thy =
   532 fun declare_const tags ((b, T), mx) thy =
   533   let
   533   let
   534     val pos = Binding.pos_of b;
   534     val pos = Binding.pos_of b;
   535     val tags' = Position.default_properties pos tags;
   535     val tags' = Position.default_properties pos tags;
   569 (* primitive classes and arities *)
   569 (* primitive classes and arities *)
   570 
   570 
   571 fun primitive_class (bclass, classes) thy =
   571 fun primitive_class (bclass, classes) thy =
   572   thy |> map_sign (fn (naming, syn, tsig, consts) =>
   572   thy |> map_sign (fn (naming, syn, tsig, consts) =>
   573     let
   573     let
   574       val syn' = Syntax.update_consts [bclass] syn;
   574       val syn' = Syntax.update_consts [Binding.name_of bclass] syn;
   575       val tsig' = Type.add_class (Syntax.pp_global thy) naming (bclass, classes) tsig;
   575       val tsig' = Type.add_class (Syntax.pp_global thy) naming (bclass, classes) tsig;
   576     in (naming, syn', tsig', consts) end)
   576     in (naming, syn', tsig', consts) end)
   577   |> add_consts_i [(Logic.const_of_class bclass, Term.a_itselfT --> propT, NoSyn)];
   577   |> add_consts_i [(Binding.map_name Logic.const_of_class bclass, Term.a_itselfT --> propT, NoSyn)];
   578 
   578 
   579 fun primitive_classrel arg thy = thy |> map_tsig (Type.add_classrel (Syntax.pp_global thy) arg);
   579 fun primitive_classrel arg thy = thy |> map_tsig (Type.add_classrel (Syntax.pp_global thy) arg);
   580 fun primitive_arity arg thy = thy |> map_tsig (Type.add_arity (Syntax.pp_global thy) arg);
   580 fun primitive_arity arg thy = thy |> map_tsig (Type.add_arity (Syntax.pp_global thy) arg);
   581 
   581 
   582 
   582