src/Pure/Syntax/syntax.ML
changeset 24278 cf82c471f9ee
parent 24263 aff00d8b2e32
child 24341 7b8da2396c49
equal deleted inserted replaced
24277:6442fde2daaa 24278:cf82c471f9ee
    71   val basic_nonterms: string list
    71   val basic_nonterms: string list
    72   val print_gram: syntax -> unit
    72   val print_gram: syntax -> unit
    73   val print_trans: syntax -> unit
    73   val print_trans: syntax -> unit
    74   val print_syntax: syntax -> unit
    74   val print_syntax: syntax -> unit
    75   val read: Proof.context -> (string -> bool) -> syntax -> typ -> string -> term list
    75   val read: Proof.context -> (string -> bool) -> syntax -> typ -> string -> term list
    76   val standard_read_term:
    76   val standard_parse_term:
    77     (((string * int) * sort) list -> string * int -> Term.sort) ->
    77     (((string * int) * sort) list -> string * int -> Term.sort) ->
    78     (string -> string option) -> (string -> string option) ->
    78     (string -> string option) -> (string -> string option) ->
    79     (typ -> typ) -> (sort -> sort) -> Proof.context ->
    79     (typ -> typ) -> (sort -> sort) -> Proof.context ->
    80     (string -> bool) -> syntax -> typ -> string -> term list
    80     (string -> bool) -> syntax -> typ -> string -> term list
    81   val standard_read_typ: Proof.context -> syntax -> ((indexname * sort) list -> indexname -> sort) ->
    81   val standard_parse_typ: Proof.context -> syntax -> ((indexname * sort) list -> indexname -> sort) ->
    82     (sort -> sort) -> string -> typ
    82     (sort -> sort) -> string -> typ
    83   val standard_read_sort: Proof.context -> syntax -> (sort -> sort) -> string -> sort
    83   val standard_parse_sort: Proof.context -> syntax -> (sort -> sort) -> string -> sort
    84   val pretty_term: (string -> xstring) -> Proof.context -> syntax -> bool -> term -> Pretty.T
    84   val pretty_term: (string -> xstring) -> Proof.context -> syntax -> bool -> term -> Pretty.T
    85   val pretty_typ: Proof.context -> syntax -> typ -> Pretty.T
    85   val pretty_typ: Proof.context -> syntax -> typ -> Pretty.T
    86   val pretty_sort: Proof.context -> syntax -> sort -> Pretty.T
    86   val pretty_sort: Proof.context -> syntax -> sort -> Pretty.T
    87   val ambiguity_level: int ref
    87   val ambiguity_level: int ref
    88   val ambiguity_is_error: bool ref
    88   val ambiguity_is_error: bool ref
    93     prop: Proof.context -> string -> term} -> unit
    93     prop: Proof.context -> string -> term} -> unit
    94   val parse_sort: Proof.context -> string -> sort
    94   val parse_sort: Proof.context -> string -> sort
    95   val parse_typ: Proof.context -> string -> typ
    95   val parse_typ: Proof.context -> string -> typ
    96   val parse_term: Proof.context -> string -> term
    96   val parse_term: Proof.context -> string -> term
    97   val parse_prop: Proof.context -> string -> term
    97   val parse_prop: Proof.context -> string -> term
       
    98   val global_parse_sort: theory -> string -> sort
       
    99   val global_parse_typ: theory -> string -> typ
       
   100   val global_parse_term: theory -> string -> term
       
   101   val global_parse_prop: theory -> string -> term
    98   val add_type_check: (term list -> Proof.context -> Term.term list * Proof.context) ->
   102   val add_type_check: (term list -> Proof.context -> Term.term list * Proof.context) ->
    99     Context.generic -> Context.generic
   103     Context.generic -> Context.generic
   100   val type_check: term list -> Proof.context -> term list * Proof.context
   104   val type_check: term list -> Proof.context -> term list * Proof.context
   101   val check_terms: Proof.context -> term list -> term list
   105   val check_terms: Proof.context -> term list -> term list
   102   val check_props: Proof.context -> term list -> term list
   106   val check_props: Proof.context -> term list -> term list
   105   val read_typ: Proof.context -> string -> typ
   109   val read_typ: Proof.context -> string -> typ
   106   val read_terms: Proof.context -> string list -> term list
   110   val read_terms: Proof.context -> string list -> term list
   107   val read_props: Proof.context -> string list -> term list
   111   val read_props: Proof.context -> string list -> term list
   108   val read_term: Proof.context -> string -> term
   112   val read_term: Proof.context -> string -> term
   109   val read_prop: Proof.context -> string -> term
   113   val read_prop: Proof.context -> string -> term
       
   114   val global_read_sort: theory -> string -> sort
       
   115   val global_read_typ: theory -> string -> typ
       
   116   val global_read_term: theory -> string -> term
       
   117   val global_read_prop: theory -> string -> term
   110 end;
   118 end;
   111 
   119 
   112 structure Syntax: SYNTAX =
   120 structure Syntax: SYNTAX =
   113 struct
   121 struct
   114 
   122 
   431   end;
   439   end;
   432 
   440 
   433 
   441 
   434 (* read terms *)
   442 (* read terms *)
   435 
   443 
   436 fun standard_read_term get_sort map_const map_free map_type map_sort ctxt is_logtype syn ty str =
   444 fun standard_parse_term get_sort map_const map_free map_type map_sort ctxt is_logtype syn ty str =
   437   map (TypeExt.decode_term get_sort map_const map_free map_type map_sort)
   445   map (TypeExt.decode_term get_sort map_const map_free map_type map_sort)
   438     (read ctxt is_logtype syn ty str);
   446     (read ctxt is_logtype syn ty str);
   439 
   447 
   440 
   448 
   441 (* read types *)
   449 (* read types *)
   442 
   450 
   443 fun standard_read_typ ctxt syn get_sort map_sort str =
   451 fun standard_parse_typ ctxt syn get_sort map_sort str =
   444   (case read ctxt (K false) syn SynExt.typeT str of
   452   (case read ctxt (K false) syn SynExt.typeT str of
   445     [t] => TypeExt.typ_of_term (get_sort (TypeExt.term_sorts map_sort t)) map_sort t
   453     [t] => TypeExt.typ_of_term (get_sort (TypeExt.term_sorts map_sort t)) map_sort t
   446   | _ => error "read_typ: ambiguous syntax");
   454   | _ => error "read_typ: ambiguous syntax");
   447 
   455 
   448 
   456 
   449 (* read sorts *)
   457 (* read sorts *)
   450 
   458 
   451 fun standard_read_sort ctxt syn map_sort str =
   459 fun standard_parse_sort ctxt syn map_sort str =
   452   (case read ctxt (K false) syn TypeExt.sortT str of
   460   (case read ctxt (K false) syn TypeExt.sortT str of
   453     [t] => TypeExt.sort_of_term map_sort t
   461     [t] => TypeExt.sort_of_term map_sort t
   454   | _ => error "read_sort: ambiguous syntax");
   462   | _ => error "read_sort: ambiguous syntax");
   455 
   463 
   456 
   464 
   591 
   599 
   592 val parse_sort = parse #sort;
   600 val parse_sort = parse #sort;
   593 val parse_typ = parse #typ;
   601 val parse_typ = parse #typ;
   594 val parse_term = parse #term;
   602 val parse_term = parse #term;
   595 val parse_prop = parse #prop;
   603 val parse_prop = parse #prop;
       
   604 
       
   605 val global_parse_sort = parse_sort o ProofContext.init;
       
   606 val global_parse_typ = parse_typ o ProofContext.init;
       
   607 val global_parse_term = parse_term o ProofContext.init;
       
   608 val global_parse_prop = parse_prop o ProofContext.init;
   596 
   609 
   597 
   610 
   598 (* type-checking *)
   611 (* type-checking *)
   599 
   612 
   600 structure TypeCheck = GenericDataFun
   613 structure TypeCheck = GenericDataFun
   638 fun read_terms ctxt = map (parse_term ctxt) #> check_terms ctxt;
   651 fun read_terms ctxt = map (parse_term ctxt) #> check_terms ctxt;
   639 fun read_props ctxt = map (parse_prop ctxt) #> check_props ctxt;
   652 fun read_props ctxt = map (parse_prop ctxt) #> check_props ctxt;
   640 
   653 
   641 val read_term = singleton o read_terms;
   654 val read_term = singleton o read_terms;
   642 val read_prop = singleton o read_props;
   655 val read_prop = singleton o read_props;
       
   656 
       
   657 val global_read_sort = read_sort o ProofContext.init;
       
   658 val global_read_typ = read_typ o ProofContext.init;
       
   659 val global_read_term = read_term o ProofContext.init;
       
   660 val global_read_prop = read_prop o ProofContext.init;
   643 
   661 
   644 
   662 
   645 (*export parts of internal Syntax structures*)
   663 (*export parts of internal Syntax structures*)
   646 open Lexicon SynExt Ast Parser TypeExt SynTrans Mixfix Printer;
   664 open Lexicon SynExt Ast Parser TypeExt SynTrans Mixfix Printer;
   647 
   665