src/Pure/Syntax/token_trans.ML
author wenzelm
Fri, 18 Jul 1997 13:35:15 +0200
changeset 3526 df4d0dad2b4e
parent 2710 3b26198fdaa5
child 5406 83e1e2dadcca
permissions -rw-r--r--
tuned warning; renamed |-> <-| <-> to Parse/PrintRule;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2697
60999ba189b7 Token translations for xterm and LaTeX output.
wenzelm
parents:
diff changeset
     1
(*  Title:      Pure/Syntax/token_trans.ML
60999ba189b7 Token translations for xterm and LaTeX output.
wenzelm
parents:
diff changeset
     2
    ID:         $Id$
60999ba189b7 Token translations for xterm and LaTeX output.
wenzelm
parents:
diff changeset
     3
    Author:     Markus Wenzel, TU Muenchen
60999ba189b7 Token translations for xterm and LaTeX output.
wenzelm
parents:
diff changeset
     4
60999ba189b7 Token translations for xterm and LaTeX output.
wenzelm
parents:
diff changeset
     5
Token translations for xterm and LaTeX output.
60999ba189b7 Token translations for xterm and LaTeX output.
wenzelm
parents:
diff changeset
     6
*)
60999ba189b7 Token translations for xterm and LaTeX output.
wenzelm
parents:
diff changeset
     7
60999ba189b7 Token translations for xterm and LaTeX output.
wenzelm
parents:
diff changeset
     8
signature TOKEN_TRANS =
60999ba189b7 Token translations for xterm and LaTeX output.
wenzelm
parents:
diff changeset
     9
sig
2707
3a1fe1c21b77 added color styles;
wenzelm
parents: 2697
diff changeset
    10
  val normal: string
3a1fe1c21b77 added color styles;
wenzelm
parents: 2697
diff changeset
    11
  val bold: string
3a1fe1c21b77 added color styles;
wenzelm
parents: 2697
diff changeset
    12
  val underline: string
3a1fe1c21b77 added color styles;
wenzelm
parents: 2697
diff changeset
    13
  val reverse: string
3a1fe1c21b77 added color styles;
wenzelm
parents: 2697
diff changeset
    14
  val black: string
3a1fe1c21b77 added color styles;
wenzelm
parents: 2697
diff changeset
    15
  val red: string
3a1fe1c21b77 added color styles;
wenzelm
parents: 2697
diff changeset
    16
  val green: string
3a1fe1c21b77 added color styles;
wenzelm
parents: 2697
diff changeset
    17
  val yellow: string
3a1fe1c21b77 added color styles;
wenzelm
parents: 2697
diff changeset
    18
  val blue: string
3a1fe1c21b77 added color styles;
wenzelm
parents: 2697
diff changeset
    19
  val purple: string
3a1fe1c21b77 added color styles;
wenzelm
parents: 2697
diff changeset
    20
  val cyan: string
3a1fe1c21b77 added color styles;
wenzelm
parents: 2697
diff changeset
    21
  val white: string
2710
3b26198fdaa5 improved xterm, xterm_color;
wenzelm
parents: 2707
diff changeset
    22
  val xterm_class: string ref
3b26198fdaa5 improved xterm, xterm_color;
wenzelm
parents: 2707
diff changeset
    23
  val xterm_tfree: string ref
3b26198fdaa5 improved xterm, xterm_color;
wenzelm
parents: 2707
diff changeset
    24
  val xterm_tvar: string ref
3b26198fdaa5 improved xterm, xterm_color;
wenzelm
parents: 2707
diff changeset
    25
  val xterm_free: string ref
3b26198fdaa5 improved xterm, xterm_color;
wenzelm
parents: 2707
diff changeset
    26
  val xterm_bound: string ref
3b26198fdaa5 improved xterm, xterm_color;
wenzelm
parents: 2707
diff changeset
    27
  val xterm_var: string ref
3b26198fdaa5 improved xterm, xterm_color;
wenzelm
parents: 2707
diff changeset
    28
  val xterm_color_class: string ref
3b26198fdaa5 improved xterm, xterm_color;
wenzelm
parents: 2707
diff changeset
    29
  val xterm_color_tfree: string ref
3b26198fdaa5 improved xterm, xterm_color;
wenzelm
parents: 2707
diff changeset
    30
  val xterm_color_tvar: string ref
3b26198fdaa5 improved xterm, xterm_color;
wenzelm
parents: 2707
diff changeset
    31
  val xterm_color_free: string ref
3b26198fdaa5 improved xterm, xterm_color;
wenzelm
parents: 2707
diff changeset
    32
  val xterm_color_bound: string ref
3b26198fdaa5 improved xterm, xterm_color;
wenzelm
parents: 2707
diff changeset
    33
  val xterm_color_var: string ref
3b26198fdaa5 improved xterm, xterm_color;
wenzelm
parents: 2707
diff changeset
    34
  val token_translation: (string * string * (string -> string * int)) list
2697
60999ba189b7 Token translations for xterm and LaTeX output.
wenzelm
parents:
diff changeset
    35
end;
60999ba189b7 Token translations for xterm and LaTeX output.
wenzelm
parents:
diff changeset
    36
60999ba189b7 Token translations for xterm and LaTeX output.
wenzelm
parents:
diff changeset
    37
structure TokenTrans: TOKEN_TRANS =
60999ba189b7 Token translations for xterm and LaTeX output.
wenzelm
parents:
diff changeset
    38
struct
60999ba189b7 Token translations for xterm and LaTeX output.
wenzelm
parents:
diff changeset
    39
60999ba189b7 Token translations for xterm and LaTeX output.
wenzelm
parents:
diff changeset
    40
(** misc utils **)
60999ba189b7 Token translations for xterm and LaTeX output.
wenzelm
parents:
diff changeset
    41
60999ba189b7 Token translations for xterm and LaTeX output.
wenzelm
parents:
diff changeset
    42
fun trans_mode m trs = map (fn (s, f) => (m, s, f)) trs;
60999ba189b7 Token translations for xterm and LaTeX output.
wenzelm
parents:
diff changeset
    43
60999ba189b7 Token translations for xterm and LaTeX output.
wenzelm
parents:
diff changeset
    44
val tok_classes = ["class", "tfree", "tvar", "free", "bound", "var"];
60999ba189b7 Token translations for xterm and LaTeX output.
wenzelm
parents:
diff changeset
    45
60999ba189b7 Token translations for xterm and LaTeX output.
wenzelm
parents:
diff changeset
    46
60999ba189b7 Token translations for xterm and LaTeX output.
wenzelm
parents:
diff changeset
    47
60999ba189b7 Token translations for xterm and LaTeX output.
wenzelm
parents:
diff changeset
    48
(** xterm output **)
60999ba189b7 Token translations for xterm and LaTeX output.
wenzelm
parents:
diff changeset
    49
60999ba189b7 Token translations for xterm and LaTeX output.
wenzelm
parents:
diff changeset
    50
(* styles *)
60999ba189b7 Token translations for xterm and LaTeX output.
wenzelm
parents:
diff changeset
    51
60999ba189b7 Token translations for xterm and LaTeX output.
wenzelm
parents:
diff changeset
    52
val normal = "\^[[0m";
60999ba189b7 Token translations for xterm and LaTeX output.
wenzelm
parents:
diff changeset
    53
val bold = "\^[[1m";
60999ba189b7 Token translations for xterm and LaTeX output.
wenzelm
parents:
diff changeset
    54
val underline = "\^[[4m";
2707
3a1fe1c21b77 added color styles;
wenzelm
parents: 2697
diff changeset
    55
val reverse = "\^[[7m";
3a1fe1c21b77 added color styles;
wenzelm
parents: 2697
diff changeset
    56
2710
3b26198fdaa5 improved xterm, xterm_color;
wenzelm
parents: 2707
diff changeset
    57
val black = "\^[[30m";
3b26198fdaa5 improved xterm, xterm_color;
wenzelm
parents: 2707
diff changeset
    58
val red = "\^[[31m";
3b26198fdaa5 improved xterm, xterm_color;
wenzelm
parents: 2707
diff changeset
    59
val green = "\^[[32m";
2707
3a1fe1c21b77 added color styles;
wenzelm
parents: 2697
diff changeset
    60
val yellow = "\^[[33m";
2710
3b26198fdaa5 improved xterm, xterm_color;
wenzelm
parents: 2707
diff changeset
    61
val blue = "\^[[34m";
3b26198fdaa5 improved xterm, xterm_color;
wenzelm
parents: 2707
diff changeset
    62
val purple = "\^[[35m";
2707
3a1fe1c21b77 added color styles;
wenzelm
parents: 2697
diff changeset
    63
val cyan = "\^[[36m";
3a1fe1c21b77 added color styles;
wenzelm
parents: 2697
diff changeset
    64
val white = "\^[[37m";
2697
60999ba189b7 Token translations for xterm and LaTeX output.
wenzelm
parents:
diff changeset
    65
2710
3b26198fdaa5 improved xterm, xterm_color;
wenzelm
parents: 2707
diff changeset
    66
fun style (ref s) x = (s ^ x ^ normal, size x);
3b26198fdaa5 improved xterm, xterm_color;
wenzelm
parents: 2707
diff changeset
    67
3b26198fdaa5 improved xterm, xterm_color;
wenzelm
parents: 2707
diff changeset
    68
3b26198fdaa5 improved xterm, xterm_color;
wenzelm
parents: 2707
diff changeset
    69
(* print modes "xterm" and "xterm_color" *)
2707
3a1fe1c21b77 added color styles;
wenzelm
parents: 2697
diff changeset
    70
2710
3b26198fdaa5 improved xterm, xterm_color;
wenzelm
parents: 2707
diff changeset
    71
val xterm_class = ref normal;
3b26198fdaa5 improved xterm, xterm_color;
wenzelm
parents: 2707
diff changeset
    72
val xterm_tfree = ref bold;
3b26198fdaa5 improved xterm, xterm_color;
wenzelm
parents: 2707
diff changeset
    73
val xterm_tvar = ref bold;
3b26198fdaa5 improved xterm, xterm_color;
wenzelm
parents: 2707
diff changeset
    74
val xterm_free = ref bold;
3b26198fdaa5 improved xterm, xterm_color;
wenzelm
parents: 2707
diff changeset
    75
val xterm_bound = ref underline;
3b26198fdaa5 improved xterm, xterm_color;
wenzelm
parents: 2707
diff changeset
    76
val xterm_var = ref bold;
2697
60999ba189b7 Token translations for xterm and LaTeX output.
wenzelm
parents:
diff changeset
    77
2710
3b26198fdaa5 improved xterm, xterm_color;
wenzelm
parents: 2707
diff changeset
    78
val xterm_color_class = ref red;
3b26198fdaa5 improved xterm, xterm_color;
wenzelm
parents: 2707
diff changeset
    79
val xterm_color_tfree = ref purple;
3b26198fdaa5 improved xterm, xterm_color;
wenzelm
parents: 2707
diff changeset
    80
val xterm_color_tvar = ref purple;
3b26198fdaa5 improved xterm, xterm_color;
wenzelm
parents: 2707
diff changeset
    81
val xterm_color_free = ref blue;
3b26198fdaa5 improved xterm, xterm_color;
wenzelm
parents: 2707
diff changeset
    82
val xterm_color_bound = ref green;
3b26198fdaa5 improved xterm, xterm_color;
wenzelm
parents: 2707
diff changeset
    83
val xterm_color_var = ref blue;
2697
60999ba189b7 Token translations for xterm and LaTeX output.
wenzelm
parents:
diff changeset
    84
60999ba189b7 Token translations for xterm and LaTeX output.
wenzelm
parents:
diff changeset
    85
val xterm_trans =
60999ba189b7 Token translations for xterm and LaTeX output.
wenzelm
parents:
diff changeset
    86
 trans_mode "xterm"
2710
3b26198fdaa5 improved xterm, xterm_color;
wenzelm
parents: 2707
diff changeset
    87
  [("class", style xterm_class),
3b26198fdaa5 improved xterm, xterm_color;
wenzelm
parents: 2707
diff changeset
    88
   ("tfree", style xterm_tfree),
3b26198fdaa5 improved xterm, xterm_color;
wenzelm
parents: 2707
diff changeset
    89
   ("tvar", style xterm_tvar),
3b26198fdaa5 improved xterm, xterm_color;
wenzelm
parents: 2707
diff changeset
    90
   ("free", style xterm_free),
3b26198fdaa5 improved xterm, xterm_color;
wenzelm
parents: 2707
diff changeset
    91
   ("bound", style xterm_bound),
3b26198fdaa5 improved xterm, xterm_color;
wenzelm
parents: 2707
diff changeset
    92
   ("var", style xterm_var)] @
3b26198fdaa5 improved xterm, xterm_color;
wenzelm
parents: 2707
diff changeset
    93
 trans_mode "xterm_color"
3b26198fdaa5 improved xterm, xterm_color;
wenzelm
parents: 2707
diff changeset
    94
  [("class", style xterm_color_class),
3b26198fdaa5 improved xterm, xterm_color;
wenzelm
parents: 2707
diff changeset
    95
   ("tfree", style xterm_color_tfree),
3b26198fdaa5 improved xterm, xterm_color;
wenzelm
parents: 2707
diff changeset
    96
   ("tvar", style xterm_color_tvar),
3b26198fdaa5 improved xterm, xterm_color;
wenzelm
parents: 2707
diff changeset
    97
   ("free", style xterm_color_free),
3b26198fdaa5 improved xterm, xterm_color;
wenzelm
parents: 2707
diff changeset
    98
   ("bound", style xterm_color_bound),
3b26198fdaa5 improved xterm, xterm_color;
wenzelm
parents: 2707
diff changeset
    99
   ("var", style xterm_color_var)];
2697
60999ba189b7 Token translations for xterm and LaTeX output.
wenzelm
parents:
diff changeset
   100
60999ba189b7 Token translations for xterm and LaTeX output.
wenzelm
parents:
diff changeset
   101
60999ba189b7 Token translations for xterm and LaTeX output.
wenzelm
parents:
diff changeset
   102
(** LaTeX output **)
60999ba189b7 Token translations for xterm and LaTeX output.
wenzelm
parents:
diff changeset
   103
60999ba189b7 Token translations for xterm and LaTeX output.
wenzelm
parents:
diff changeset
   104
(* FIXME 'a -> \alpha etc. *)
60999ba189b7 Token translations for xterm and LaTeX output.
wenzelm
parents:
diff changeset
   105
60999ba189b7 Token translations for xterm and LaTeX output.
wenzelm
parents:
diff changeset
   106
60999ba189b7 Token translations for xterm and LaTeX output.
wenzelm
parents:
diff changeset
   107
(** token translations **)
60999ba189b7 Token translations for xterm and LaTeX output.
wenzelm
parents:
diff changeset
   108
60999ba189b7 Token translations for xterm and LaTeX output.
wenzelm
parents:
diff changeset
   109
val token_translation =
60999ba189b7 Token translations for xterm and LaTeX output.
wenzelm
parents:
diff changeset
   110
  map (fn s => ("", s, fn x => (x, size x))) tok_classes @
60999ba189b7 Token translations for xterm and LaTeX output.
wenzelm
parents:
diff changeset
   111
  (* FIXME tmp test *)
60999ba189b7 Token translations for xterm and LaTeX output.
wenzelm
parents:
diff changeset
   112
  map (fn s => ("test", s, fn x => (s ^ "[" ^ x ^ "]", size x + size s + 2))) tok_classes @
60999ba189b7 Token translations for xterm and LaTeX output.
wenzelm
parents:
diff changeset
   113
  xterm_trans;
60999ba189b7 Token translations for xterm and LaTeX output.
wenzelm
parents:
diff changeset
   114
60999ba189b7 Token translations for xterm and LaTeX output.
wenzelm
parents:
diff changeset
   115
60999ba189b7 Token translations for xterm and LaTeX output.
wenzelm
parents:
diff changeset
   116
end;