src/Pure/sign.ML
changeset 35669 a91c7ed801b8
parent 35429 afa8cf9e63d8
child 35680 897740382442
equal deleted inserted replaced
35668:69e1740fbfb1 35669:a91c7ed801b8
    51   val extern_class: theory -> string -> xstring
    51   val extern_class: theory -> string -> xstring
    52   val intern_type: theory -> xstring -> string
    52   val intern_type: theory -> xstring -> string
    53   val extern_type: theory -> string -> xstring
    53   val extern_type: theory -> string -> xstring
    54   val intern_const: theory -> xstring -> string
    54   val intern_const: theory -> xstring -> string
    55   val extern_const: theory -> string -> xstring
    55   val extern_const: theory -> string -> xstring
    56   val intern_sort: theory -> sort -> sort
       
    57   val extern_sort: theory -> sort -> sort
       
    58   val intern_typ: theory -> typ -> typ
       
    59   val intern_term: theory -> term -> term
    56   val intern_term: theory -> term -> term
    60   val the_type_decl: theory -> string -> Type.decl
       
    61   val arity_number: theory -> string -> int
    57   val arity_number: theory -> string -> int
    62   val arity_sorts: theory -> string -> sort -> sort list
    58   val arity_sorts: theory -> string -> sort -> sort list
    63   val certify_class: theory -> class -> class
    59   val certify_class: theory -> class -> class
    64   val certify_sort: theory -> sort -> sort
    60   val certify_sort: theory -> sort -> sort
    65   val certify_typ: theory -> typ -> typ
    61   val certify_typ: theory -> typ -> typ
    69   val cert_term: theory -> term -> term
    65   val cert_term: theory -> term -> term
    70   val cert_prop: theory -> term -> term
    66   val cert_prop: theory -> term -> term
    71   val no_frees: Pretty.pp -> term -> term
    67   val no_frees: Pretty.pp -> term -> term
    72   val no_vars: Pretty.pp -> term -> term
    68   val no_vars: Pretty.pp -> term -> term
    73   val cert_def: Proof.context -> term -> (string * typ) * term
    69   val cert_def: Proof.context -> term -> (string * typ) * term
    74   val read_class: theory -> xstring -> class
       
    75   val read_arity: theory -> xstring * string list * string -> arity
       
    76   val cert_arity: theory -> arity -> arity
       
    77   val add_defsort: string -> theory -> theory
    70   val add_defsort: string -> theory -> theory
    78   val add_defsort_i: sort -> theory -> theory
    71   val add_defsort_i: sort -> theory -> theory
    79   val add_types: (binding * int * mixfix) list -> theory -> theory
    72   val add_types: (binding * int * mixfix) list -> theory -> theory
    80   val add_nonterminals: binding list -> theory -> theory
    73   val add_nonterminals: binding list -> theory -> theory
    81   val add_tyabbrs: (binding * string list * string * mixfix) list -> theory -> theory
    74   val add_tyabbrs: (binding * string list * string * mixfix) list -> theory -> theory
   152   type T = sign;
   145   type T = sign;
   153   fun extend (Sign {syn, tsig, consts, ...}) =
   146   fun extend (Sign {syn, tsig, consts, ...}) =
   154     make_sign (Name_Space.default_naming, syn, tsig, consts);
   147     make_sign (Name_Space.default_naming, syn, tsig, consts);
   155 
   148 
   156   val empty =
   149   val empty =
   157     make_sign (Name_Space.default_naming, Syntax.empty_syntax, Type.empty_tsig, Consts.empty);
   150     make_sign (Name_Space.default_naming, Syntax.basic_syntax, Type.empty_tsig, Consts.empty);
   158 
   151 
   159   fun merge pp (sign1, sign2) =
   152   fun merge pp (sign1, sign2) =
   160     let
   153     let
   161       val Sign {naming = _, syn = syn1, tsig = tsig1, consts = consts1} = sign1;
   154       val Sign {naming = _, syn = syn1, tsig = tsig1, consts = consts1} = sign1;
   162       val Sign {naming = _, syn = syn2, tsig = tsig2, consts = consts2} = sign2;
   155       val Sign {naming = _, syn = syn2, tsig = tsig2, consts = consts2} = sign2;
   234 
   227 
   235 
   228 
   236 
   229 
   237 (** intern / extern names **)
   230 (** intern / extern names **)
   238 
   231 
   239 val class_space = #1 o #classes o Type.rep_tsig o tsig_of;
   232 val class_space = Type.class_space o tsig_of;
   240 val type_space = #1 o #types o Type.rep_tsig o tsig_of;
   233 val type_space = Type.type_space o tsig_of;
   241 val const_space = Consts.space_of o consts_of;
   234 val const_space = Consts.space_of o consts_of;
   242 
   235 
   243 val intern_class = Name_Space.intern o class_space;
   236 val intern_class = Name_Space.intern o class_space;
   244 val extern_class = Name_Space.extern o class_space;
   237 val extern_class = Name_Space.extern o class_space;
   245 val intern_type = Name_Space.intern o type_space;
   238 val intern_type = Name_Space.intern o type_space;
   246 val extern_type = Name_Space.extern o type_space;
   239 val extern_type = Name_Space.extern o type_space;
   247 val intern_const = Name_Space.intern o const_space;
   240 val intern_const = Name_Space.intern o const_space;
   248 val extern_const = Name_Space.extern o const_space;
   241 val extern_const = Name_Space.extern o const_space;
   249 
   242 
   250 val intern_sort = map o intern_class;
       
   251 val extern_sort = map o extern_class;
       
   252 
       
   253 local
   243 local
   254 
   244 
   255 fun map_typ f g (Type (c, Ts)) = Type (g c, map (map_typ f g) Ts)
   245 fun map_typ f g (Type (c, Ts)) = Type (g c, map (map_typ f g) Ts)
   256   | map_typ f _ (TFree (x, S)) = TFree (x, map f S)
   246   | map_typ f _ (TFree (x, S)) = TFree (x, map f S)
   257   | map_typ f _ (TVar (xi, S)) = TVar (xi, map f S);
   247   | map_typ f _ (TVar (xi, S)) = TVar (xi, map f S);
   263   | map_term f g h (Abs (x, T, t)) = Abs (x, map_typ f g T, map_term f g h t)
   253   | map_term f g h (Abs (x, T, t)) = Abs (x, map_typ f g T, map_term f g h t)
   264   | map_term f g h (t $ u) = map_term f g h t $ map_term f g h u;
   254   | map_term f g h (t $ u) = map_term f g h t $ map_term f g h u;
   265 
   255 
   266 in
   256 in
   267 
   257 
   268 fun intern_typ thy = map_typ (intern_class thy) (intern_type thy);
       
   269 fun intern_term thy = map_term (intern_class thy) (intern_type thy) (intern_const thy);
   258 fun intern_term thy = map_term (intern_class thy) (intern_type thy) (intern_const thy);
   270 
   259 
   271 end;
   260 end;
   272 
   261 
   273 
   262 
   274 
   263 
   275 (** certify entities **)    (*exception TYPE*)
   264 (** certify entities **)    (*exception TYPE*)
   276 
   265 
   277 (* certify wrt. type signature *)
   266 (* certify wrt. type signature *)
   278 
   267 
   279 val the_type_decl = Type.the_decl o tsig_of;
       
   280 val arity_number = Type.arity_number o tsig_of;
   268 val arity_number = Type.arity_number o tsig_of;
   281 fun arity_sorts thy = Type.arity_sorts (Syntax.pp_global thy) (tsig_of thy);
   269 fun arity_sorts thy = Type.arity_sorts (Syntax.pp_global thy) (tsig_of thy);
   282 
   270 
   283 val certify_class         = Type.cert_class o tsig_of;
   271 val certify_class         = Type.cert_class o tsig_of;
   284 val certify_sort          = Type.cert_sort o tsig_of;
   272 val certify_sort          = Type.cert_sort o tsig_of;
   362     |> no_vars (Syntax.pp ctxt)
   350     |> no_vars (Syntax.pp ctxt)
   363     |> Logic.strip_imp_concl
   351     |> Logic.strip_imp_concl
   364     |> Primitive_Defs.dest_def ctxt Term.is_Const (K false) (K false)
   352     |> Primitive_Defs.dest_def ctxt Term.is_Const (K false) (K false)
   365   in (Term.dest_Const (Term.head_of lhs), rhs) end
   353   in (Term.dest_Const (Term.head_of lhs), rhs) end
   366   handle TERM (msg, _) => error msg;
   354   handle TERM (msg, _) => error msg;
   367 
       
   368 
       
   369 
       
   370 (** read and certify entities **)    (*exception ERROR*)
       
   371 
       
   372 (* classes *)
       
   373 
       
   374 fun read_class thy text =
       
   375   let
       
   376     val (syms, pos) = Syntax.read_token text;
       
   377     val c = certify_class thy (intern_class thy (Symbol_Pos.content syms))
       
   378       handle TYPE (msg, _, _) => error (msg ^ Position.str_of pos);
       
   379     val _ = Position.report (Markup.tclass c) pos;
       
   380   in c end;
       
   381 
       
   382 
       
   383 (* type arities *)
       
   384 
       
   385 fun prep_arity prep_tycon prep_sort thy (t, Ss, S) =
       
   386   let val arity = (prep_tycon thy t, map (prep_sort thy) Ss, prep_sort thy S)
       
   387   in Type.add_arity (Syntax.pp_global thy) arity (tsig_of thy); arity end;
       
   388 
       
   389 val read_arity = prep_arity intern_type Syntax.read_sort_global;
       
   390 val cert_arity = prep_arity (K I) certify_sort;
       
   391 
       
   392 
       
   393 (* type syntax entities *)
       
   394 
       
   395 local
       
   396 
       
   397 fun read_type thy text =
       
   398   let
       
   399     val (syms, pos) = Syntax.read_token text;
       
   400     val c = intern_type thy (Symbol_Pos.content syms);
       
   401     val _ = the_type_decl thy c;
       
   402     val _ = Position.report (Markup.tycon c) pos;
       
   403   in c end;
       
   404 
       
   405 in
       
   406 
       
   407 val _ = Context.>>
       
   408   (Context.map_theory
       
   409     (map_syn (K (Syntax.basic_syntax {read_class = read_class, read_type = read_type}))));
       
   410 
       
   411 end;
       
   412 
   355 
   413 
   356 
   414 
   357 
   415 (** signature extension functions **)  (*exception ERROR/TYPE*)
   358 (** signature extension functions **)  (*exception ERROR/TYPE*)
   416 
   359