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