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