src/Pure/General/symbol.ML
author wenzelm
Fri, 05 May 2000 22:02:46 +0200
changeset 8806 a202293db3f6
parent 8663 38d7ec8ef683
child 8998 56c44eee46ad
permissions -rw-r--r--
GPLed;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6118
caa439435666 fixed titles;
wenzelm
parents: 6116
diff changeset
     1
(*  Title:      Pure/General/symbol.ML
6116
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
     2
    ID:         $Id$
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
     3
    Author:     Markus Wenzel, TU Muenchen
8806
wenzelm
parents: 8663
diff changeset
     4
    License:    GPL (GNU GENERAL PUBLIC LICENSE)
6116
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
     5
8806
wenzelm
parents: 8663
diff changeset
     6
Generalized characters, independent of encoding.
6116
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
     7
*)
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
     8
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
     9
signature SYMBOL =
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
    10
sig
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
    11
  type symbol
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
    12
  val space: symbol
6857
6e6eb8d92377 added sync marker;
wenzelm
parents: 6692
diff changeset
    13
  val sync: symbol
6e6eb8d92377 added sync marker;
wenzelm
parents: 6692
diff changeset
    14
  val is_sync: symbol -> bool
6e6eb8d92377 added sync marker;
wenzelm
parents: 6692
diff changeset
    15
  val not_sync: symbol -> bool
6116
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
    16
  val eof: symbol
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
    17
  val is_eof: symbol -> bool
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
    18
  val not_eof: symbol -> bool
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
    19
  val stopper: symbol * (symbol -> bool)
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
    20
  val is_ascii: symbol -> bool
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
    21
  val is_letter: symbol -> bool
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
    22
  val is_digit: symbol -> bool
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
    23
  val is_quasi_letter: symbol -> bool
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
    24
  val is_letdig: symbol -> bool
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
    25
  val is_blank: symbol -> bool
8230
6f8aa407bcf9 is_symbolic;
wenzelm
parents: 6857
diff changeset
    26
  val is_symbolic: symbol -> bool
6116
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
    27
  val is_printable: symbol -> bool
6272
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
    28
  val length: symbol list -> int
6116
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
    29
  val beginning: symbol list -> string
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
    30
  val scan: string list -> symbol * string list
6640
d2e8342bf5c3 rearranged order of modules;
wenzelm
parents: 6320
diff changeset
    31
  val scanner: string -> (symbol list -> 'a * symbol list) -> symbol list -> 'a
6116
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
    32
  val source: bool -> (string, 'a) Source.source ->
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
    33
    (symbol, (string, 'a) Source.source) Source.source
6272
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
    34
  val explode: string -> symbol list
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
    35
  val input: string -> string
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
    36
  val add_mode: string -> (string -> string * real) -> unit
6692
05c56f41e661 avoid string constants;
wenzelm
parents: 6640
diff changeset
    37
  val isabelle_fontN: string
05c56f41e661 avoid string constants;
wenzelm
parents: 6640
diff changeset
    38
  val symbolsN: string
05c56f41e661 avoid string constants;
wenzelm
parents: 6640
diff changeset
    39
  val xsymbolsN: string
6272
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
    40
  val output: string -> string
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
    41
  val output_width: string -> string * real
6116
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
    42
end;
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
    43
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
    44
structure Symbol: SYMBOL =
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
    45
struct
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
    46
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
    47
6272
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
    48
(** generalized characters **)
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
    49
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
    50
(*symbols, which are considered the smallest entities of any Isabelle
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
    51
  string, may be of the following form:
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
    52
    (a) ASCII symbols: a
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
    53
    (b) printable symbols: \<ident>
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
    54
    (c) control symbols: \<^ident>
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
    55
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
    56
  input may include non-ASCII characters according to isabelle-0 encoding;
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
    57
  output is subject to the print_mode variable (default: verbatim);
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
    58
*)
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
    59
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
    60
type symbol = string;
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
    61
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
    62
val space = " ";
6857
6e6eb8d92377 added sync marker;
wenzelm
parents: 6692
diff changeset
    63
val sync = "\\<^sync>";
6272
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
    64
val eof = "";
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
    65
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
    66
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
    67
(* kinds *)
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
    68
6857
6e6eb8d92377 added sync marker;
wenzelm
parents: 6692
diff changeset
    69
fun is_sync s = s = sync;
6e6eb8d92377 added sync marker;
wenzelm
parents: 6692
diff changeset
    70
fun not_sync s = s <> sync;
6e6eb8d92377 added sync marker;
wenzelm
parents: 6692
diff changeset
    71
6272
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
    72
fun is_eof s = s = eof;
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
    73
fun not_eof s = s <> eof;
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
    74
val stopper = (eof, is_eof);
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
    75
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
    76
fun is_ascii s = size s = 1 andalso ord s < 128;
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
    77
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
    78
fun is_letter s =
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
    79
  size s = 1 andalso
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
    80
   (ord "A" <= ord s andalso ord s <= ord "Z" orelse
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
    81
    ord "a" <= ord s andalso ord s <= ord "z");
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
    82
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
    83
fun is_digit s =
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
    84
  size s = 1 andalso ord "0" <= ord s andalso ord s <= ord "9";
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
    85
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
    86
fun is_quasi_letter "_" = true
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
    87
  | is_quasi_letter "'" = true
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
    88
  | is_quasi_letter s = is_letter s;
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
    89
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
    90
val is_blank =
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
    91
  fn " " => true | "\t" => true | "\n" => true | "\^L" => true
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
    92
    | "\160" => true | "\\<spacespace>" => true
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
    93
    | _ => false;
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
    94
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
    95
val is_letdig = is_quasi_letter orf is_digit;
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
    96
8230
6f8aa407bcf9 is_symbolic;
wenzelm
parents: 6857
diff changeset
    97
fun is_symbolic s =
6f8aa407bcf9 is_symbolic;
wenzelm
parents: 6857
diff changeset
    98
  size s > 2 andalso nth_elem_string (2, s) <> "^";
6f8aa407bcf9 is_symbolic;
wenzelm
parents: 6857
diff changeset
    99
6272
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
   100
fun is_printable s =
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
   101
  size s = 1 andalso ord space <= ord s andalso ord s <= ord "~" orelse
8230
6f8aa407bcf9 is_symbolic;
wenzelm
parents: 6857
diff changeset
   102
  is_symbolic s;
6f8aa407bcf9 is_symbolic;
wenzelm
parents: 6857
diff changeset
   103
6272
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
   104
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
   105
fun sym_length ss = foldl (fn (n, s) => if is_printable s then n + 1 else n) (0, ss);
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
   106
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
   107
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
   108
(* beginning *)
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
   109
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
   110
val smash_blanks = map (fn s => if is_blank s then space else s);
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
   111
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
   112
fun beginning raw_ss =
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
   113
  let
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
   114
    val (all_ss, _) = take_suffix is_blank raw_ss;
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
   115
    val dots = if length all_ss > 10 then " ..." else "";
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
   116
    val (ss, _) = take_suffix is_blank (take (10, all_ss));
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
   117
  in implode (smash_blanks ss) ^ dots end;
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
   118
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
   119
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
   120
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
   121
(** isabelle-0 encoding table **)
6116
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   122
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   123
val enc_start = 160;
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   124
val enc_end = 255;
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   125
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   126
val enc_vector =
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   127
[
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   128
(* GENERATED TEXT FOLLOWS - Do not edit! *)
6166
a56aaad7ff2d renamed space2 to spacespace
oheimb
parents: 6118
diff changeset
   129
  "\\<spacespace>",
6116
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   130
  "\\<Gamma>",
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   131
  "\\<Delta>",
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   132
  "\\<Theta>",
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   133
  "\\<Lambda>",
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   134
  "\\<Pi>",
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   135
  "\\<Sigma>",
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   136
  "\\<Phi>",
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   137
  "\\<Psi>",
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   138
  "\\<Omega>",
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   139
  "\\<alpha>",
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   140
  "\\<beta>",
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   141
  "\\<gamma>",
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   142
  "\\<delta>",
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   143
  "\\<epsilon>",
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   144
  "\\<zeta>",
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   145
  "\\<eta>",
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   146
  "\\<theta>",
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   147
  "\\<kappa>",
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   148
  "\\<lambda>",
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   149
  "\\<mu>",
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   150
  "\\<nu>",
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   151
  "\\<xi>",
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   152
  "\\<pi>",
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   153
  "\\<rho>",
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   154
  "\\<sigma>",
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   155
  "\\<tau>",
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   156
  "\\<phi>",
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   157
  "\\<chi>",
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   158
  "\\<psi>",
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   159
  "\\<omega>",
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   160
  "\\<not>",
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   161
  "\\<and>",
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   162
  "\\<or>",
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   163
  "\\<forall>",
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   164
  "\\<exists>",
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   165
  "\\<And>",
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   166
  "\\<lceil>",
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   167
  "\\<rceil>",
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   168
  "\\<lfloor>",
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   169
  "\\<rfloor>",
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   170
  "\\<turnstile>",
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   171
  "\\<Turnstile>",
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   172
  "\\<lbrakk>",
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   173
  "\\<rbrakk>",
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   174
  "\\<cdot>",
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   175
  "\\<in>",
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   176
  "\\<subseteq>",
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   177
  "\\<inter>",
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   178
  "\\<union>",
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   179
  "\\<Inter>",
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   180
  "\\<Union>",
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   181
  "\\<sqinter>",
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   182
  "\\<squnion>",
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   183
  "\\<Sqinter>",
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   184
  "\\<Squnion>",
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   185
  "\\<bottom>",
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   186
  "\\<doteq>",
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   187
  "\\<equiv>",
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   188
  "\\<noteq>",
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   189
  "\\<sqsubset>",
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   190
  "\\<sqsubseteq>",
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   191
  "\\<prec>",
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   192
  "\\<preceq>",
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   193
  "\\<succ>",
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   194
  "\\<approx>",
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   195
  "\\<sim>",
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   196
  "\\<simeq>",
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   197
  "\\<le>",
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   198
  "\\<Colon>",
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   199
  "\\<leftarrow>",
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   200
  "\\<midarrow>",
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   201
  "\\<rightarrow>",
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   202
  "\\<Leftarrow>",
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   203
  "\\<Midarrow>",
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   204
  "\\<Rightarrow>",
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   205
  "\\<bow>",
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   206
  "\\<mapsto>",
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   207
  "\\<leadsto>",
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   208
  "\\<up>",
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   209
  "\\<down>",
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   210
  "\\<notin>",
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   211
  "\\<times>",
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   212
  "\\<oplus>",
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   213
  "\\<ominus>",
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   214
  "\\<otimes>",
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   215
  "\\<oslash>",
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   216
  "\\<subset>",
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   217
  "\\<infinity>",
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   218
  "\\<box>",
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   219
  "\\<diamond>",
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   220
  "\\<circ>",
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   221
  "\\<bullet>",
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   222
  "\\<parallel>",
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   223
  "\\<surd>",
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   224
  "\\<copyright>"
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   225
(* END OF GENERATED TEXT *)
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   226
];
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   227
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   228
val enc_rel = enc_vector ~~ map chr (enc_start upto enc_end);
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   229
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   230
val char_tab = Symtab.make enc_rel;
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   231
val symbol_tab = Symtab.make (map swap enc_rel);
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   232
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   233
fun lookup_symbol c =
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   234
  if ord c < enc_start then None
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   235
  else Symtab.lookup (symbol_tab, c);
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   236
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   237
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   238
(* encode / decode *)
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   239
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   240
fun char s = if_none (Symtab.lookup (char_tab, s)) s;
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   241
fun symbol c = if_none (lookup_symbol c) c;
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   242
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   243
fun symbol' c =
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   244
  (case lookup_symbol c of
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   245
    None => c
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   246
  | Some s => "\\" ^ s);
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   247
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   248
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   249
6640
d2e8342bf5c3 rearranged order of modules;
wenzelm
parents: 6320
diff changeset
   250
(** scanning though symbols **)
d2e8342bf5c3 rearranged order of modules;
wenzelm
parents: 6320
diff changeset
   251
d2e8342bf5c3 rearranged order of modules;
wenzelm
parents: 6320
diff changeset
   252
fun scanner msg scan chs =
d2e8342bf5c3 rearranged order of modules;
wenzelm
parents: 6320
diff changeset
   253
  let
d2e8342bf5c3 rearranged order of modules;
wenzelm
parents: 6320
diff changeset
   254
    fun err_msg cs = msg ^ ": " ^ beginning cs;
d2e8342bf5c3 rearranged order of modules;
wenzelm
parents: 6320
diff changeset
   255
    val fin_scan = Scan.error (Scan.finite stopper (!! (fn (cs, _) => err_msg cs) scan));
d2e8342bf5c3 rearranged order of modules;
wenzelm
parents: 6320
diff changeset
   256
  in
d2e8342bf5c3 rearranged order of modules;
wenzelm
parents: 6320
diff changeset
   257
    (case fin_scan chs of
d2e8342bf5c3 rearranged order of modules;
wenzelm
parents: 6320
diff changeset
   258
      (result, []) => result
d2e8342bf5c3 rearranged order of modules;
wenzelm
parents: 6320
diff changeset
   259
    | (_, rest) => error (err_msg rest))
d2e8342bf5c3 rearranged order of modules;
wenzelm
parents: 6320
diff changeset
   260
  end;
d2e8342bf5c3 rearranged order of modules;
wenzelm
parents: 6320
diff changeset
   261
d2e8342bf5c3 rearranged order of modules;
wenzelm
parents: 6320
diff changeset
   262
d2e8342bf5c3 rearranged order of modules;
wenzelm
parents: 6320
diff changeset
   263
6272
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
   264
(** symbol input **)
6116
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   265
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   266
(* scan *)
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   267
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   268
val scan_id = Scan.one is_letter ^^ (Scan.any is_letdig >> implode);
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   269
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   270
val scan =
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   271
  ($$ "\\" --| Scan.optional ($$ "\\") "") ^^ $$ "<" ^^
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   272
    !! (fn (cs, _) => "Malformed symbolic character specification: \\" ^ "<" ^ beginning cs)
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   273
      (Scan.optional ($$ "^") "" ^^ scan_id ^^ $$ ">") ||
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   274
  Scan.one not_eof;
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   275
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   276
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   277
(* source *)
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   278
8663
38d7ec8ef683 tuned recover;
wenzelm
parents: 8230
diff changeset
   279
val recover = Scan.any ((not o is_blank) andf not_eof);
6116
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   280
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   281
fun source do_recover src =
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   282
  Source.source stopper (Scan.bulk scan) (if do_recover then Some recover else None) src;
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   283
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   284
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   285
(* explode *)
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   286
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   287
fun no_syms [] = true
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   288
  | no_syms ("\\" :: "<" :: _) = false
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   289
  | no_syms (c :: cs) = ord c < enc_start andalso no_syms cs;
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   290
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   291
fun sym_explode str =
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   292
  let val chs = explode str in
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   293
    if no_syms chs then chs     (*tune trivial case*)
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   294
    else map symbol (the (Scan.read stopper (Scan.repeat scan) chs))
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   295
  end;
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   296
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   297
6272
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
   298
(* input *)
6116
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   299
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   300
fun input str =
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   301
  let val chs = explode str in
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   302
    if forall (fn c => ord c < enc_start) chs then str
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   303
    else implode (map symbol' chs)
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   304
  end;
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   305
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   306
6272
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
   307
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
   308
(** symbol output **)
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
   309
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
   310
(* default_output *)
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
   311
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
   312
fun string_size s = (s, real (size s));
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
   313
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
   314
fun default_output s =
6320
4df282137880 tuned using nth_elem_string, exists_string;
wenzelm
parents: 6272
diff changeset
   315
  if not (exists_string (equal "\\") s) then string_size s
4df282137880 tuned using nth_elem_string, exists_string;
wenzelm
parents: 6272
diff changeset
   316
  else string_size (implode (map (fn "\\" => "\\\\" | c => c) (explode s)));	(*sic!*)
6272
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
   317
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
   318
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
   319
(* isabelle_font_output *)
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
   320
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
   321
fun isabelle_font_output s =
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
   322
  let val cs = sym_explode s
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
   323
  in (implode (map char cs), real (sym_length cs)) end;
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
   324
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
   325
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
   326
(* maintain modes *)
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
   327
6692
05c56f41e661 avoid string constants;
wenzelm
parents: 6640
diff changeset
   328
val isabelle_fontN = "isabelle_font";
05c56f41e661 avoid string constants;
wenzelm
parents: 6640
diff changeset
   329
val symbolsN = "symbols";
05c56f41e661 avoid string constants;
wenzelm
parents: 6640
diff changeset
   330
val xsymbolsN = "xsymbols";
05c56f41e661 avoid string constants;
wenzelm
parents: 6640
diff changeset
   331
05c56f41e661 avoid string constants;
wenzelm
parents: 6640
diff changeset
   332
val modes = ref (Symtab.make [(isabelle_fontN, isabelle_font_output)]);
6272
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
   333
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
   334
fun lookup_mode name = Symtab.lookup (! modes, name);
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
   335
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
   336
fun add_mode name f =
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
   337
 (if is_none (lookup_mode name) then ()
6320
4df282137880 tuned using nth_elem_string, exists_string;
wenzelm
parents: 6272
diff changeset
   338
  else warning ("Redeclaration of symbol print mode " ^ quote name);
6272
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
   339
  modes := Symtab.update ((name, f), ! modes));
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
   340
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
   341
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
   342
(* mode output *)
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
   343
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
   344
fun output_width s =
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
   345
  (case get_first lookup_mode (! print_mode) of
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
   346
    None => default_output s
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
   347
  | Some f => f s);
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
   348
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
   349
val output = #1 o output_width;
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
   350
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
   351
6116
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   352
(*final declarations of this structure!*)
6272
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
   353
val length = sym_length;
6116
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   354
val explode = sym_explode;
6272
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
   355
6116
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   356
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   357
end;