src/ZF/Tools/numeral_syntax.ML
changeset 42246 8f798ba04393
parent 41310 65631ca437c9
child 42290 b1f544c84040
equal deleted inserted replaced
42245:29e3967550d5 42246:8f798ba04393
     1 (*  Title:      ZF/Tools/numeral_syntax.ML
     1 (*  Title:      ZF/Tools/numeral_syntax.ML
     2     Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
     2     Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
     3 
     3 
     4 Concrete syntax for generic numerals.  Assumes consts and syntax of
     4 Concrete syntax for generic numerals.
     5 theory Bin.
       
     6 *)
     5 *)
     7 
     6 
     8 signature NUMERAL_SYNTAX =
     7 signature NUMERAL_SYNTAX =
     9 sig
     8 sig
    10   val make_binary: int -> int list
     9   val make_binary: int -> int list
    11   val dest_binary: int list -> int
    10   val dest_binary: int list -> int
    12   val int_tr: term list -> term
       
    13   val int_tr': bool -> typ -> term list -> term
       
    14   val setup: theory -> theory
    11   val setup: theory -> theory
    15 end;
    12 end;
    16 
    13 
    17 structure Numeral_Syntax: NUMERAL_SYNTAX =
    14 structure Numeral_Syntax: NUMERAL_SYNTAX =
    18 struct
    15 struct
    71   end;
    68   end;
    72 
    69 
    73 
    70 
    74 (* translation of integer constant tokens to and from binary *)
    71 (* translation of integer constant tokens to and from binary *)
    75 
    72 
    76 fun int_tr (*"_Int"*) [t as Free (str, _)] =
    73 fun int_tr [t as Free (str, _)] =
    77       Syntax.const @{const_syntax integ_of} $ mk_bin (#value (Syntax.read_xnum str))
    74       Syntax.const @{const_syntax integ_of} $ mk_bin (#value (Syntax.read_xnum str))
    78   | int_tr (*"_Int"*) ts = raise TERM ("int_tr", ts);
    75   | int_tr ts = raise TERM ("int_tr", ts);
    79 
    76 
    80 fun int_tr' _ _ (*"integ_of"*) [t] =
    77 fun int_tr' [t] = Syntax.const @{syntax_const "_Int"} $ Syntax.free (show_int t)
    81       Syntax.const @{syntax_const "_Int"} $ Syntax.free (show_int t)
    78   | int_tr' _ = raise Match;
    82   | int_tr' (_: bool) (_: typ) _ = raise Match;
       
    83 
    79 
    84 
    80 
    85 val setup =
    81 val setup =
    86  (Sign.add_trfuns ([], [(@{syntax_const "_Int"}, int_tr)], [], []) #>
    82  Sign.add_trfuns ([], [(@{syntax_const "_Int"}, int_tr)], [(@{const_syntax integ_of}, int_tr')], []);
    87   Sign.add_trfunsT [(@{const_syntax integ_of}, int_tr')]);
       
    88 
    83 
    89 end;
    84 end;