author | wenzelm |
Fri, 07 Mar 1997 15:32:16 +0100 | |
changeset 2769 | 77903c147673 |
parent 2676 | 585cd2311a98 |
child 2913 | ce271fa4d8e2 |
permissions | -rw-r--r-- |
2207 | 1 |
(* Title: Pure/Syntax/symbol_font.ML |
2 |
ID: $Id$ |
|
3 |
Author: Markus Wenzel, TU Muenchen |
|
4 |
||
2676 | 5 |
The Isabelle symbol font. Please keep enc_vector consistent with |
6 |
lib/scripts/symbolinput.pl! |
|
2207 | 7 |
*) |
8 |
||
9 |
signature SYMBOL_FONT = |
|
10 |
sig |
|
2208 | 11 |
val char: string -> string option |
2362 | 12 |
val name: string -> string option |
13 |
val read_charnames: string list -> string list |
|
2407 | 14 |
val write_charnames: string list -> string list (*normal backslashes*) |
15 |
val write_charnames': string list -> string list (*escaped backslashes*) |
|
2207 | 16 |
end; |
17 |
||
2362 | 18 |
|
2207 | 19 |
structure SymbolFont : SYMBOL_FONT = |
20 |
struct |
|
21 |
||
2362 | 22 |
|
23 |
(** font encoding vector **) |
|
24 |
||
25 |
(* tables *) |
|
2207 | 26 |
|
2208 | 27 |
val enc_start = 161; |
2207 | 28 |
val enc_end = 255; |
29 |
||
30 |
val enc_vector = |
|
31 |
[ |
|
2208 | 32 |
"Gamma", "Delta", "Theta", "Lambda", "Pi", "Sigma", "Phi", |
2207 | 33 |
"Psi", "Omega", "alpha", "beta", "gamma", "delta", "epsilon", "zeta", |
34 |
"eta", "theta", "kappa", "lambda", "mu", "nu", "xi", "pi", |
|
2255 | 35 |
"rho", "sigma", "tau", "phi", "chi", "psi", "omega", "not", |
36 |
"and", "or", "forall", "exists", "And", "lceil", "rceil", "lfloor", |
|
2769
77903c147673
removed lparr, rparr, empty, succeq, ge, rrightarrow;
wenzelm
parents:
2676
diff
changeset
|
37 |
"rfloor", "turnstile", "Turnstile", "lbrakk", "rbrakk", "cdot", "in", "subseteq", |
2255 | 38 |
"inter", "union", "Inter", "Union", "sqinter", "squnion", "Sqinter", "Squnion", |
2207 | 39 |
"bottom", "doteq", "equiv", "noteq", "sqsubset", "sqsubseteq", "prec", "preceq", |
2769
77903c147673
removed lparr, rparr, empty, succeq, ge, rrightarrow;
wenzelm
parents:
2676
diff
changeset
|
40 |
"succ", "approx", "sim", "simeq", "le", "Colon", "leftarrow", "midarrow", |
77903c147673
removed lparr, rparr, empty, succeq, ge, rrightarrow;
wenzelm
parents:
2676
diff
changeset
|
41 |
"rightarrow", "Leftarrow", "Midarrow", "Rightarrow", "bow", "mapsto", "leadsto", "up", |
2676 | 42 |
"down", "notin", "times", "oplus", "ominus", "otimes", "oslash", "subset", |
2769
77903c147673
removed lparr, rparr, empty, succeq, ge, rrightarrow;
wenzelm
parents:
2676
diff
changeset
|
43 |
"infinity", "box", "diamond", "circ", "bullet", "parallel", "surd", "copyright" |
2207 | 44 |
]; |
45 |
||
2362 | 46 |
val enc_rel = enc_vector ~~ (map chr (enc_start upto enc_end)); |
47 |
||
48 |
val enc_tab = Symtab.make enc_rel; |
|
49 |
val dec_tab = Symtab.make (map swap enc_rel); |
|
50 |
||
51 |
||
52 |
(* chars and names *) |
|
53 |
||
54 |
fun char name = Symtab.lookup (enc_tab, name); |
|
2419 | 55 |
|
56 |
fun name char = |
|
57 |
if ord char < enc_start then None |
|
58 |
else Symtab.lookup (dec_tab, char); |
|
2362 | 59 |
|
2207 | 60 |
|
61 |
||
2362 | 62 |
(** input and output of symbols **) |
63 |
||
64 |
(* read_charnames *) |
|
65 |
||
66 |
local |
|
67 |
open Scanner; |
|
2207 | 68 |
|
2362 | 69 |
fun scan_symbol ("\\" :: "<" :: cs) = |
70 |
let |
|
71 |
val (name, cs') = (scan_id -- $$ ">" >> #1) cs handle LEXICAL_ERROR |
|
72 |
=> error ("Malformed symbolic char specification: \"\\<" ^ implode cs ^ "\""); |
|
73 |
val c = the (char name) handle OPTION _ |
|
74 |
=> error ("Unknown symbolic char name: " ^ quote name); |
|
75 |
in (c, cs') end |
|
76 |
| scan_symbol _ = raise LEXICAL_ERROR; |
|
77 |
in |
|
2419 | 78 |
fun read_charnames chs = |
79 |
if forall (not_equal "\\") chs then chs |
|
80 |
else #1 (repeat (scan_symbol || scan_one (K true)) chs); |
|
2362 | 81 |
end; |
2207 | 82 |
|
2362 | 83 |
|
84 |
(* write_charnames *) |
|
85 |
||
2407 | 86 |
fun write_char prfx ch = |
2362 | 87 |
(case name ch of |
88 |
None => ch |
|
2407 | 89 |
| Some nm => prfx ^ "\\<" ^ nm ^ ">"); |
2362 | 90 |
|
2419 | 91 |
fun write_chars prfx chs = |
92 |
if forall (fn ch => ord ch < enc_start) chs then chs |
|
93 |
else map (write_char prfx) chs; |
|
94 |
||
95 |
val write_charnames = write_chars ""; |
|
96 |
val write_charnames' = write_chars "\\"; |
|
2362 | 97 |
|
2207 | 98 |
|
99 |
end; |