2207
|
1 |
(* Title: Pure/Syntax/symbol_font.ML
|
|
2 |
ID: $Id$
|
|
3 |
Author: Markus Wenzel, TU Muenchen
|
|
4 |
|
|
5 |
The Isabelle symbol font.
|
|
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
|
2407
|
13 |
val write_charnames: string list -> string list (*normal backslashes*)
|
|
14 |
val write_charnames': string list -> string list (*escaped backslashes*)
|
2207
|
15 |
end;
|
|
16 |
|
2362
|
17 |
|
2207
|
18 |
structure SymbolFont : SYMBOL_FONT =
|
|
19 |
struct
|
|
20 |
|
2362
|
21 |
|
|
22 |
(** font encoding vector **)
|
|
23 |
|
|
24 |
(* tables *)
|
2207
|
25 |
|
2208
|
26 |
val enc_start = 161;
|
2207
|
27 |
val enc_end = 255;
|
|
28 |
|
|
29 |
val enc_vector =
|
|
30 |
[
|
2208
|
31 |
"Gamma", "Delta", "Theta", "Lambda", "Pi", "Sigma", "Phi",
|
2207
|
32 |
"Psi", "Omega", "alpha", "beta", "gamma", "delta", "epsilon", "zeta",
|
|
33 |
"eta", "theta", "kappa", "lambda", "mu", "nu", "xi", "pi",
|
2255
|
34 |
"rho", "sigma", "tau", "phi", "chi", "psi", "omega", "not",
|
|
35 |
"and", "or", "forall", "exists", "And", "lceil", "rceil", "lfloor",
|
|
36 |
"rfloor", "lparr", "rparr", "lbrakk", "rbrakk", "empty", "in", "subseteq",
|
|
37 |
"inter", "union", "Inter", "Union", "sqinter", "squnion", "Sqinter", "Squnion",
|
2207
|
38 |
"bottom", "doteq", "equiv", "noteq", "sqsubset", "sqsubseteq", "prec", "preceq",
|
|
39 |
"succ", "succeq", "sim", "simeq", "le", "ge", "leftarrow", "midarrow",
|
|
40 |
"rightarrow", "Leftarrow", "Midarrow", "Rightarrow", "rrightarrow", "mapsto", "leadsto", "up",
|
|
41 |
"down", "notin", "times", "oplus", "ominus", "otimes", "oslash", "natural",
|
2208
|
42 |
"infinity", "box", "diamond", "circ", "bullet", "parallel", "tick", "copyright"
|
2207
|
43 |
];
|
|
44 |
|
2362
|
45 |
val enc_rel = enc_vector ~~ (map chr (enc_start upto enc_end));
|
|
46 |
|
|
47 |
val enc_tab = Symtab.make enc_rel;
|
|
48 |
val dec_tab = Symtab.make (map swap enc_rel);
|
|
49 |
|
|
50 |
|
|
51 |
(* chars and names *)
|
|
52 |
|
|
53 |
fun char name = Symtab.lookup (enc_tab, name);
|
|
54 |
fun name char = Symtab.lookup (dec_tab, char);
|
|
55 |
|
2207
|
56 |
|
|
57 |
|
2362
|
58 |
(** input and output of symbols **)
|
|
59 |
|
|
60 |
(* read_charnames *)
|
|
61 |
|
|
62 |
local
|
|
63 |
open Scanner;
|
2207
|
64 |
|
2362
|
65 |
fun scan_symbol ("\\" :: "<" :: cs) =
|
|
66 |
let
|
|
67 |
val (name, cs') = (scan_id -- $$ ">" >> #1) cs handle LEXICAL_ERROR
|
|
68 |
=> error ("Malformed symbolic char specification: \"\\<" ^ implode cs ^ "\"");
|
|
69 |
val c = the (char name) handle OPTION _
|
|
70 |
=> error ("Unknown symbolic char name: " ^ quote name);
|
|
71 |
in (c, cs') end
|
|
72 |
| scan_symbol _ = raise LEXICAL_ERROR;
|
|
73 |
in
|
|
74 |
val read_charnames = #1 o repeat (scan_symbol || scan_one (K true));
|
|
75 |
end;
|
2207
|
76 |
|
2362
|
77 |
|
|
78 |
(* write_charnames *)
|
|
79 |
|
2407
|
80 |
fun write_char prfx ch =
|
2362
|
81 |
(case name ch of
|
|
82 |
None => ch
|
2407
|
83 |
| Some nm => prfx ^ "\\<" ^ nm ^ ">");
|
2362
|
84 |
|
2407
|
85 |
val write_charnames = map (write_char "");
|
|
86 |
val write_charnames' = map (write_char "\\");
|
2362
|
87 |
|
2207
|
88 |
|
|
89 |
end;
|