src/Pure/Syntax/syn_ext.ML
changeset 4054 b33e02b3478e
parent 4050 543df9687d7b
child 4146 00136226f74b
equal deleted inserted replaced
4053:c88d0d5ae806 4054:b33e02b3478e
     7 
     7 
     8 signature SYN_EXT0 =
     8 signature SYN_EXT0 =
     9 sig
     9 sig
    10   val typeT: typ
    10   val typeT: typ
    11   val constrainC: string
    11   val constrainC: string
    12   val mixfix_args: string -> int
       
    13 end;
    12 end;
    14 
    13 
    15 signature SYN_EXT =
    14 signature SYN_EXT =
    16 sig
    15 sig
    17   include SYN_EXT0
    16   include SYN_EXT0
    42       parse_translation: (string * (term list -> term)) list,
    41       parse_translation: (string * (term list -> term)) list,
    43       print_translation: (string * (typ -> term list -> term)) list,
    42       print_translation: (string * (typ -> term list -> term)) list,
    44       print_rules: (Ast.ast * Ast.ast) list,
    43       print_rules: (Ast.ast * Ast.ast) list,
    45       print_ast_translation: (string * (Ast.ast list -> Ast.ast)) list,
    44       print_ast_translation: (string * (Ast.ast list -> Ast.ast)) list,
    46       token_translation: (string * string * (string -> string * int)) list}
    45       token_translation: (string * string * (string -> string * int)) list}
       
    46   val mfix_args: string -> int
    47   val mk_syn_ext: bool -> string list -> mfix list ->
    47   val mk_syn_ext: bool -> string list -> mfix list ->
    48     string list -> (string * (Ast.ast list -> Ast.ast)) list *
    48     string list -> (string * (Ast.ast list -> Ast.ast)) list *
    49     (string * (term list -> term)) list *
    49     (string * (term list -> term)) list *
    50     (string * (typ -> term list -> term)) list * (string * (Ast.ast list -> Ast.ast)) list
    50     (string * (typ -> term list -> term)) list * (string * (Ast.ast list -> Ast.ast)) list
    51     -> (string * string * (string -> string * int)) list
    51     -> (string * string * (string -> string * int)) list
   193   val scan_symbs = mapfilter I o #1 o repeat scan_symb;
   193   val scan_symbs = mapfilter I o #1 o repeat scan_symb;
   194 in
   194 in
   195   val scan_mixfix = scan_symbs o SymbolFont.read_charnames o explode;
   195   val scan_mixfix = scan_symbs o SymbolFont.read_charnames o explode;
   196 end;
   196 end;
   197 
   197 
   198 fun mixfix_args mx =
   198 fun mfix_args sy =
   199   foldl (fn (i, Argument _) => i + 1 | (i, _) => i) (0, scan_mixfix mx);
   199   foldl (fn (i, Argument _) => i + 1 | (i, _) => i) (0, scan_mixfix sy);
   200 
   200 
   201 
   201 
   202 (* mfix_to_xprod *)
   202 (* mfix_to_xprod *)
   203 
   203 
   204 fun mfix_to_xprod convert logtypes (Mfix (sy, typ, const, pris, pri)) =
   204 fun mfix_to_xprod convert logtypes (Mfix (sy, typ, const, pris, pri)) =
   247       | rem_pri sym = sym;
   247       | rem_pri sym = sym;
   248 
   248 
   249     fun is_delim (Delim _) = true
   249     fun is_delim (Delim _) = true
   250       | is_delim _ = false;
   250       | is_delim _ = false;
   251 
   251 
   252     (*replace logical types on rhs by "logic"*)
   252     fun logify_types copy_prod (a as (Argument (s, p))) =
   253     fun unify_logtypes copy_prod (a as (Argument (s, p))) =
   253           if s mem logtypes then Argument (logic, p) else a
   254           if s mem logtypes then Argument (logic, p)
   254       | logify_types _ a = a;
   255           else a
       
   256       | unify_logtypes _ a = a;
       
   257 
   255 
   258 
   256 
   259     val raw_symbs = scan_mixfix sy handle ERROR => err "";
   257     val raw_symbs = scan_mixfix sy handle ERROR => err "";
   260     val (symbs, lhs) = add_args raw_symbs typ pris;
   258     val (symbs, lhs) = add_args raw_symbs typ pris;
   261     val copy_prod =
   259     val copy_prod =
   266     val lhs' =
   264     val lhs' =
   267       if convert andalso not copy_prod then
   265       if convert andalso not copy_prod then
   268        (if lhs mem logtypes then logic
   266        (if lhs mem logtypes then logic
   269         else if lhs = "prop" then sprop else lhs)
   267         else if lhs = "prop" then sprop else lhs)
   270       else lhs;
   268       else lhs;
   271     val symbs' = map (unify_logtypes copy_prod) symbs;
   269     val symbs' = map (logify_types copy_prod) symbs;
   272     val xprod = XProd (lhs', symbs', const, pri);
   270     val xprod = XProd (lhs', symbs', const, pri);
   273   in
   271   in
   274     seq check_pri pris;
   272     seq check_pri pris;
   275     check_pri pri;
   273     check_pri pri;
   276     check_blocks symbs';
   274     check_blocks symbs';