2207
|
1 |
(* Title: Pure/Syntax/symbol_font.ML
|
|
2 |
ID: $Id$
|
|
3 |
Author: Markus Wenzel, TU Muenchen
|
|
4 |
|
2943
|
5 |
The Isabelle symbol font.
|
2207
|
6 |
*)
|
|
7 |
|
|
8 |
signature SYMBOL_FONT =
|
|
9 |
sig
|
2208
|
10 |
val char: string -> string option
|
2362
|
11 |
val name: string -> string option
|
|
12 |
val read_charnames: string list -> string list
|
2913
|
13 |
val read_chnames: string -> string
|
|
14 |
val write_charnames: string list -> string list (*normal backslashes*)
|
|
15 |
val write_chnames: string -> string
|
|
16 |
val write_charnames': string list -> string list (*escaped backslashes*)
|
|
17 |
val write_chnames': string -> string
|
2207
|
18 |
end;
|
|
19 |
|
2362
|
20 |
|
2207
|
21 |
structure SymbolFont : SYMBOL_FONT =
|
|
22 |
struct
|
|
23 |
|
2362
|
24 |
|
|
25 |
(** font encoding vector **)
|
|
26 |
|
|
27 |
(* tables *)
|
2207
|
28 |
|
2208
|
29 |
val enc_start = 161;
|
2207
|
30 |
val enc_end = 255;
|
|
31 |
|
|
32 |
val enc_vector =
|
|
33 |
[
|
2942
|
34 |
(* GENERATED TEXT FOLLOWS - Do not edit! *)
|
2943
|
35 |
"Gamma",
|
|
36 |
"Delta",
|
|
37 |
"Theta",
|
|
38 |
"Lambda",
|
|
39 |
"Pi",
|
|
40 |
"Sigma",
|
|
41 |
"Phi",
|
|
42 |
"Psi",
|
|
43 |
"Omega",
|
|
44 |
"alpha",
|
|
45 |
"beta",
|
|
46 |
"gamma",
|
|
47 |
"delta",
|
|
48 |
"epsilon",
|
|
49 |
"zeta",
|
|
50 |
"eta",
|
|
51 |
"theta",
|
|
52 |
"kappa",
|
|
53 |
"lambda",
|
|
54 |
"mu",
|
|
55 |
"nu",
|
|
56 |
"xi",
|
|
57 |
"pi",
|
|
58 |
"rho",
|
|
59 |
"sigma",
|
|
60 |
"tau",
|
|
61 |
"phi",
|
|
62 |
"chi",
|
|
63 |
"psi",
|
|
64 |
"omega",
|
|
65 |
"not",
|
|
66 |
"and",
|
|
67 |
"or",
|
|
68 |
"forall",
|
|
69 |
"exists",
|
|
70 |
"And",
|
|
71 |
"lceil",
|
|
72 |
"rceil",
|
|
73 |
"lfloor",
|
|
74 |
"rfloor",
|
|
75 |
"turnstile",
|
|
76 |
"Turnstile",
|
|
77 |
"lbrakk",
|
|
78 |
"rbrakk",
|
|
79 |
"cdot",
|
|
80 |
"in",
|
|
81 |
"subseteq",
|
|
82 |
"inter",
|
|
83 |
"union",
|
|
84 |
"Inter",
|
|
85 |
"Union",
|
|
86 |
"sqinter",
|
|
87 |
"squnion",
|
|
88 |
"Sqinter",
|
|
89 |
"Squnion",
|
|
90 |
"bottom",
|
|
91 |
"doteq",
|
|
92 |
"equiv",
|
|
93 |
"noteq",
|
|
94 |
"sqsubset",
|
|
95 |
"sqsubseteq",
|
|
96 |
"prec",
|
|
97 |
"preceq",
|
|
98 |
"succ",
|
|
99 |
"approx",
|
|
100 |
"sim",
|
|
101 |
"simeq",
|
|
102 |
"le",
|
|
103 |
"Colon",
|
|
104 |
"leftarrow",
|
|
105 |
"midarrow",
|
|
106 |
"rightarrow",
|
|
107 |
"Leftarrow",
|
|
108 |
"Midarrow",
|
|
109 |
"Rightarrow",
|
|
110 |
"bow",
|
|
111 |
"mapsto",
|
|
112 |
"leadsto",
|
|
113 |
"up",
|
|
114 |
"down",
|
|
115 |
"notin",
|
|
116 |
"times",
|
|
117 |
"oplus",
|
|
118 |
"ominus",
|
|
119 |
"otimes",
|
|
120 |
"oslash",
|
|
121 |
"subset",
|
|
122 |
"infinity",
|
|
123 |
"box",
|
|
124 |
"diamond",
|
|
125 |
"circ",
|
|
126 |
"bullet",
|
|
127 |
"parallel",
|
|
128 |
"surd",
|
|
129 |
"copyright"
|
2942
|
130 |
(* END OF GENERATED TEXT *)
|
2207
|
131 |
];
|
|
132 |
|
2362
|
133 |
val enc_rel = enc_vector ~~ (map chr (enc_start upto enc_end));
|
|
134 |
|
|
135 |
val enc_tab = Symtab.make enc_rel;
|
|
136 |
val dec_tab = Symtab.make (map swap enc_rel);
|
|
137 |
|
|
138 |
|
|
139 |
(* chars and names *)
|
|
140 |
|
|
141 |
fun char name = Symtab.lookup (enc_tab, name);
|
2419
|
142 |
|
|
143 |
fun name char =
|
|
144 |
if ord char < enc_start then None
|
|
145 |
else Symtab.lookup (dec_tab, char);
|
2362
|
146 |
|
2207
|
147 |
|
|
148 |
|
2362
|
149 |
(** input and output of symbols **)
|
|
150 |
|
|
151 |
(* read_charnames *)
|
|
152 |
|
|
153 |
local
|
|
154 |
open Scanner;
|
2207
|
155 |
|
2362
|
156 |
fun scan_symbol ("\\" :: "<" :: cs) =
|
|
157 |
let
|
|
158 |
val (name, cs') = (scan_id -- $$ ">" >> #1) cs handle LEXICAL_ERROR
|
|
159 |
=> error ("Malformed symbolic char specification: \"\\<" ^ implode cs ^ "\"");
|
|
160 |
val c = the (char name) handle OPTION _
|
|
161 |
=> error ("Unknown symbolic char name: " ^ quote name);
|
|
162 |
in (c, cs') end
|
|
163 |
| scan_symbol _ = raise LEXICAL_ERROR;
|
|
164 |
in
|
2419
|
165 |
fun read_charnames chs =
|
|
166 |
if forall (not_equal "\\") chs then chs
|
|
167 |
else #1 (repeat (scan_symbol || scan_one (K true)) chs);
|
2913
|
168 |
|
|
169 |
val read_chnames = implode o read_charnames o explode;
|
2362
|
170 |
end;
|
2207
|
171 |
|
2362
|
172 |
|
|
173 |
(* write_charnames *)
|
|
174 |
|
2407
|
175 |
fun write_char prfx ch =
|
2362
|
176 |
(case name ch of
|
|
177 |
None => ch
|
2407
|
178 |
| Some nm => prfx ^ "\\<" ^ nm ^ ">");
|
2362
|
179 |
|
2419
|
180 |
fun write_chars prfx chs =
|
|
181 |
if forall (fn ch => ord ch < enc_start) chs then chs
|
|
182 |
else map (write_char prfx) chs;
|
|
183 |
|
|
184 |
val write_charnames = write_chars "";
|
|
185 |
val write_charnames' = write_chars "\\";
|
2362
|
186 |
|
2913
|
187 |
val write_chnames = implode o write_charnames o explode;
|
|
188 |
val write_chnames' = implode o write_charnames' o explode;
|
2207
|
189 |
|
|
190 |
end;
|