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