src/Pure/Syntax/token_trans.ML
author wenzelm
Wed, 09 Jun 2004 18:52:42 +0200
changeset 14898 a25550451b51
parent 14880 7586233bd4bd
child 14981 e73f8140af78
permissions -rw-r--r--
Url.File;
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
12785
wenzelm
parents: 11795
diff changeset
     4
    License:    GPL (GNU GENERAL PUBLIC LICENSE)
2697
60999ba189b7 Token translations for xterm and LaTeX output.
wenzelm
parents:
diff changeset
     5
6695
d3ba5427d562 Isamode and ProofGeneral configuration moved to Pure/Interface;
wenzelm
parents: 6322
diff changeset
     6
Token translations for xterm output.
2697
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
6322
7047300264c9 token translation: real;
wenzelm
parents: 5989
diff changeset
     9
signature TOKEN_TRANS0 =
7047300264c9 token translation: real;
wenzelm
parents: 5989
diff changeset
    10
sig
7047300264c9 token translation: real;
wenzelm
parents: 5989
diff changeset
    11
  val standard_token_classes: string list
6695
d3ba5427d562 Isamode and ProofGeneral configuration moved to Pure/Interface;
wenzelm
parents: 6322
diff changeset
    12
  val tokentrans_mode: string -> (string * (string -> string * real)) list ->
d3ba5427d562 Isamode and ProofGeneral configuration moved to Pure/Interface;
wenzelm
parents: 6322
diff changeset
    13
    (string * string * (string -> string * real)) list
6322
7047300264c9 token translation: real;
wenzelm
parents: 5989
diff changeset
    14
end;
7047300264c9 token translation: real;
wenzelm
parents: 5989
diff changeset
    15
2697
60999ba189b7 Token translations for xterm and LaTeX output.
wenzelm
parents:
diff changeset
    16
signature TOKEN_TRANS =
60999ba189b7 Token translations for xterm and LaTeX output.
wenzelm
parents:
diff changeset
    17
sig
6322
7047300264c9 token translation: real;
wenzelm
parents: 5989
diff changeset
    18
  include TOKEN_TRANS0
11795
12a0fb3ac366 be more careful about token class markers;
wenzelm
parents: 11697
diff changeset
    19
  val standard_token_markers: string list
2707
3a1fe1c21b77 added color styles;
wenzelm
parents: 2697
diff changeset
    20
  val normal: string
3a1fe1c21b77 added color styles;
wenzelm
parents: 2697
diff changeset
    21
  val bold: string
3a1fe1c21b77 added color styles;
wenzelm
parents: 2697
diff changeset
    22
  val underline: string
3a1fe1c21b77 added color styles;
wenzelm
parents: 2697
diff changeset
    23
  val reverse: string
3a1fe1c21b77 added color styles;
wenzelm
parents: 2697
diff changeset
    24
  val black: string
3a1fe1c21b77 added color styles;
wenzelm
parents: 2697
diff changeset
    25
  val red: string
3a1fe1c21b77 added color styles;
wenzelm
parents: 2697
diff changeset
    26
  val green: string
3a1fe1c21b77 added color styles;
wenzelm
parents: 2697
diff changeset
    27
  val yellow: string
3a1fe1c21b77 added color styles;
wenzelm
parents: 2697
diff changeset
    28
  val blue: string
3a1fe1c21b77 added color styles;
wenzelm
parents: 2697
diff changeset
    29
  val purple: string
3a1fe1c21b77 added color styles;
wenzelm
parents: 2697
diff changeset
    30
  val cyan: string
3a1fe1c21b77 added color styles;
wenzelm
parents: 2697
diff changeset
    31
  val white: string
2710
3b26198fdaa5 improved xterm, xterm_color;
wenzelm
parents: 2707
diff changeset
    32
  val xterm_class: string ref
3b26198fdaa5 improved xterm, xterm_color;
wenzelm
parents: 2707
diff changeset
    33
  val xterm_tfree: string ref
3b26198fdaa5 improved xterm, xterm_color;
wenzelm
parents: 2707
diff changeset
    34
  val xterm_tvar: string ref
3b26198fdaa5 improved xterm, xterm_color;
wenzelm
parents: 2707
diff changeset
    35
  val xterm_free: string ref
3b26198fdaa5 improved xterm, xterm_color;
wenzelm
parents: 2707
diff changeset
    36
  val xterm_bound: string ref
3b26198fdaa5 improved xterm, xterm_color;
wenzelm
parents: 2707
diff changeset
    37
  val xterm_var: string ref
3b26198fdaa5 improved xterm, xterm_color;
wenzelm
parents: 2707
diff changeset
    38
  val xterm_color_class: string ref
3b26198fdaa5 improved xterm, xterm_color;
wenzelm
parents: 2707
diff changeset
    39
  val xterm_color_tfree: string ref
3b26198fdaa5 improved xterm, xterm_color;
wenzelm
parents: 2707
diff changeset
    40
  val xterm_color_tvar: string ref
3b26198fdaa5 improved xterm, xterm_color;
wenzelm
parents: 2707
diff changeset
    41
  val xterm_color_free: string ref
3b26198fdaa5 improved xterm, xterm_color;
wenzelm
parents: 2707
diff changeset
    42
  val xterm_color_bound: string ref
3b26198fdaa5 improved xterm, xterm_color;
wenzelm
parents: 2707
diff changeset
    43
  val xterm_color_var: string ref
6322
7047300264c9 token translation: real;
wenzelm
parents: 5989
diff changeset
    44
  val token_translation: (string * string * (string -> string * real)) list
2697
60999ba189b7 Token translations for xterm and LaTeX output.
wenzelm
parents:
diff changeset
    45
end;
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
structure TokenTrans: TOKEN_TRANS =
60999ba189b7 Token translations for xterm and LaTeX output.
wenzelm
parents:
diff changeset
    48
struct
60999ba189b7 Token translations for xterm and LaTeX output.
wenzelm
parents:
diff changeset
    49
5406
83e1e2dadcca added emacs mode;
wenzelm
parents: 2710
diff changeset
    50
2697
60999ba189b7 Token translations for xterm and LaTeX output.
wenzelm
parents:
diff changeset
    51
(** misc utils **)
60999ba189b7 Token translations for xterm and LaTeX output.
wenzelm
parents:
diff changeset
    52
6695
d3ba5427d562 Isamode and ProofGeneral configuration moved to Pure/Interface;
wenzelm
parents: 6322
diff changeset
    53
fun tokentrans_mode m trs = map (fn (s, f) => (m, s, f)) trs;
2697
60999ba189b7 Token translations for xterm and LaTeX output.
wenzelm
parents:
diff changeset
    54
6322
7047300264c9 token translation: real;
wenzelm
parents: 5989
diff changeset
    55
val standard_token_classes =
11697
8dd899efbd35 added "num" token;
wenzelm
parents: 6695
diff changeset
    56
  ["class", "tfree", "tvar", "free", "bound", "var", "num", "xnum", "xstr"];
2697
60999ba189b7 Token translations for xterm and LaTeX output.
wenzelm
parents:
diff changeset
    57
11795
12a0fb3ac366 be more careful about token class markers;
wenzelm
parents: 11697
diff changeset
    58
val standard_token_markers = map (fn s => "_" ^ s) standard_token_classes;
2697
60999ba189b7 Token translations for xterm and LaTeX output.
wenzelm
parents:
diff changeset
    59
60999ba189b7 Token translations for xterm and LaTeX output.
wenzelm
parents:
diff changeset
    60
60999ba189b7 Token translations for xterm and LaTeX output.
wenzelm
parents:
diff changeset
    61
(** xterm output **)
60999ba189b7 Token translations for xterm and LaTeX output.
wenzelm
parents:
diff changeset
    62
60999ba189b7 Token translations for xterm and LaTeX output.
wenzelm
parents:
diff changeset
    63
(* styles *)
60999ba189b7 Token translations for xterm and LaTeX output.
wenzelm
parents:
diff changeset
    64
60999ba189b7 Token translations for xterm and LaTeX output.
wenzelm
parents:
diff changeset
    65
val normal = "\^[[0m";
60999ba189b7 Token translations for xterm and LaTeX output.
wenzelm
parents:
diff changeset
    66
val bold = "\^[[1m";
60999ba189b7 Token translations for xterm and LaTeX output.
wenzelm
parents:
diff changeset
    67
val underline = "\^[[4m";
2707
3a1fe1c21b77 added color styles;
wenzelm
parents: 2697
diff changeset
    68
val reverse = "\^[[7m";
3a1fe1c21b77 added color styles;
wenzelm
parents: 2697
diff changeset
    69
2710
3b26198fdaa5 improved xterm, xterm_color;
wenzelm
parents: 2707
diff changeset
    70
val black = "\^[[30m";
3b26198fdaa5 improved xterm, xterm_color;
wenzelm
parents: 2707
diff changeset
    71
val red = "\^[[31m";
3b26198fdaa5 improved xterm, xterm_color;
wenzelm
parents: 2707
diff changeset
    72
val green = "\^[[32m";
2707
3a1fe1c21b77 added color styles;
wenzelm
parents: 2697
diff changeset
    73
val yellow = "\^[[33m";
2710
3b26198fdaa5 improved xterm, xterm_color;
wenzelm
parents: 2707
diff changeset
    74
val blue = "\^[[34m";
3b26198fdaa5 improved xterm, xterm_color;
wenzelm
parents: 2707
diff changeset
    75
val purple = "\^[[35m";
2707
3a1fe1c21b77 added color styles;
wenzelm
parents: 2697
diff changeset
    76
val cyan = "\^[[36m";
3a1fe1c21b77 added color styles;
wenzelm
parents: 2697
diff changeset
    77
val white = "\^[[37m";
2697
60999ba189b7 Token translations for xterm and LaTeX output.
wenzelm
parents:
diff changeset
    78
14880
7586233bd4bd Symbol.output;
wenzelm
parents: 12785
diff changeset
    79
fun style (ref s) x = Output.output_width x |> apfst (enclose s normal);
2710
3b26198fdaa5 improved xterm, xterm_color;
wenzelm
parents: 2707
diff changeset
    80
3b26198fdaa5 improved xterm, xterm_color;
wenzelm
parents: 2707
diff changeset
    81
3b26198fdaa5 improved xterm, xterm_color;
wenzelm
parents: 2707
diff changeset
    82
(* print modes "xterm" and "xterm_color" *)
2707
3a1fe1c21b77 added color styles;
wenzelm
parents: 2697
diff changeset
    83
2710
3b26198fdaa5 improved xterm, xterm_color;
wenzelm
parents: 2707
diff changeset
    84
val xterm_class = ref normal;
3b26198fdaa5 improved xterm, xterm_color;
wenzelm
parents: 2707
diff changeset
    85
val xterm_tfree = ref bold;
3b26198fdaa5 improved xterm, xterm_color;
wenzelm
parents: 2707
diff changeset
    86
val xterm_tvar = ref bold;
3b26198fdaa5 improved xterm, xterm_color;
wenzelm
parents: 2707
diff changeset
    87
val xterm_free = ref bold;
3b26198fdaa5 improved xterm, xterm_color;
wenzelm
parents: 2707
diff changeset
    88
val xterm_bound = ref underline;
3b26198fdaa5 improved xterm, xterm_color;
wenzelm
parents: 2707
diff changeset
    89
val xterm_var = ref bold;
2697
60999ba189b7 Token translations for xterm and LaTeX output.
wenzelm
parents:
diff changeset
    90
2710
3b26198fdaa5 improved xterm, xterm_color;
wenzelm
parents: 2707
diff changeset
    91
val xterm_color_class = ref red;
3b26198fdaa5 improved xterm, xterm_color;
wenzelm
parents: 2707
diff changeset
    92
val xterm_color_tfree = ref purple;
3b26198fdaa5 improved xterm, xterm_color;
wenzelm
parents: 2707
diff changeset
    93
val xterm_color_tvar = ref purple;
3b26198fdaa5 improved xterm, xterm_color;
wenzelm
parents: 2707
diff changeset
    94
val xterm_color_free = ref blue;
3b26198fdaa5 improved xterm, xterm_color;
wenzelm
parents: 2707
diff changeset
    95
val xterm_color_bound = ref green;
3b26198fdaa5 improved xterm, xterm_color;
wenzelm
parents: 2707
diff changeset
    96
val xterm_color_var = ref blue;
2697
60999ba189b7 Token translations for xterm and LaTeX output.
wenzelm
parents:
diff changeset
    97
60999ba189b7 Token translations for xterm and LaTeX output.
wenzelm
parents:
diff changeset
    98
val xterm_trans =
6695
d3ba5427d562 Isamode and ProofGeneral configuration moved to Pure/Interface;
wenzelm
parents: 6322
diff changeset
    99
 tokentrans_mode "xterm"
2710
3b26198fdaa5 improved xterm, xterm_color;
wenzelm
parents: 2707
diff changeset
   100
  [("class", style xterm_class),
3b26198fdaa5 improved xterm, xterm_color;
wenzelm
parents: 2707
diff changeset
   101
   ("tfree", style xterm_tfree),
3b26198fdaa5 improved xterm, xterm_color;
wenzelm
parents: 2707
diff changeset
   102
   ("tvar", style xterm_tvar),
3b26198fdaa5 improved xterm, xterm_color;
wenzelm
parents: 2707
diff changeset
   103
   ("free", style xterm_free),
3b26198fdaa5 improved xterm, xterm_color;
wenzelm
parents: 2707
diff changeset
   104
   ("bound", style xterm_bound),
3b26198fdaa5 improved xterm, xterm_color;
wenzelm
parents: 2707
diff changeset
   105
   ("var", style xterm_var)] @
6695
d3ba5427d562 Isamode and ProofGeneral configuration moved to Pure/Interface;
wenzelm
parents: 6322
diff changeset
   106
 tokentrans_mode "xterm_color"
2710
3b26198fdaa5 improved xterm, xterm_color;
wenzelm
parents: 2707
diff changeset
   107
  [("class", style xterm_color_class),
3b26198fdaa5 improved xterm, xterm_color;
wenzelm
parents: 2707
diff changeset
   108
   ("tfree", style xterm_color_tfree),
3b26198fdaa5 improved xterm, xterm_color;
wenzelm
parents: 2707
diff changeset
   109
   ("tvar", style xterm_color_tvar),
3b26198fdaa5 improved xterm, xterm_color;
wenzelm
parents: 2707
diff changeset
   110
   ("free", style xterm_color_free),
3b26198fdaa5 improved xterm, xterm_color;
wenzelm
parents: 2707
diff changeset
   111
   ("bound", style xterm_color_bound),
3b26198fdaa5 improved xterm, xterm_color;
wenzelm
parents: 2707
diff changeset
   112
   ("var", style xterm_color_var)];
2697
60999ba189b7 Token translations for xterm and LaTeX output.
wenzelm
parents:
diff changeset
   113
60999ba189b7 Token translations for xterm and LaTeX output.
wenzelm
parents:
diff changeset
   114
5406
83e1e2dadcca added emacs mode;
wenzelm
parents: 2710
diff changeset
   115
83e1e2dadcca added emacs mode;
wenzelm
parents: 2710
diff changeset
   116
(** standard token translations **)
2697
60999ba189b7 Token translations for xterm and LaTeX output.
wenzelm
parents:
diff changeset
   117
60999ba189b7 Token translations for xterm and LaTeX output.
wenzelm
parents:
diff changeset
   118
val token_translation =
14880
7586233bd4bd Symbol.output;
wenzelm
parents: 12785
diff changeset
   119
  map (fn s => ("", s, Output.output_width)) standard_token_classes @
6695
d3ba5427d562 Isamode and ProofGeneral configuration moved to Pure/Interface;
wenzelm
parents: 6322
diff changeset
   120
  xterm_trans;
2697
60999ba189b7 Token translations for xterm and LaTeX output.
wenzelm
parents:
diff changeset
   121
60999ba189b7 Token translations for xterm and LaTeX output.
wenzelm
parents:
diff changeset
   122
60999ba189b7 Token translations for xterm and LaTeX output.
wenzelm
parents:
diff changeset
   123
end;