src/Pure/General/symbol.ML
author wenzelm
Mon, 26 Apr 2004 14:58:54 +0200
changeset 14678 662b181cae05
parent 14632 805fa01ac233
child 14728 df34201f1a15
permissions -rw-r--r--
clarification of ascii vs. symbolic entities;
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
14678
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
     6
Generalized characters with and infinite amount of named symbols.
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
10953
ea024d025463 added spaces;
wenzelm
parents: 10923
diff changeset
    13
  val spaces: int -> symbol
14678
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
    14
  val is_char: symbol -> bool
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
    15
  val is_symbolic: symbol -> bool
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
    16
  val is_printable: symbol -> bool
6116
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
    17
  val eof: symbol
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
    18
  val is_eof: symbol -> bool
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
    19
  val not_eof: symbol -> bool
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
    20
  val stopper: symbol * (symbol -> bool)
14678
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
    21
  val sync: symbol
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
    22
  val is_sync: symbol -> bool
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
    23
  val not_sync: symbol -> bool
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
    24
  val malformed: symbol
6116
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
    25
  val is_ascii: symbol -> bool
14678
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
    26
  val is_ascii_letter: symbol -> bool
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
    27
  val is_ascii_digit: symbol -> bool
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
    28
  val is_ascii_quasi: symbol -> bool
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
    29
  val is_ascii_blank: symbol -> bool
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
    30
  datatype kind = Letter | Digit | Quasi | Blank | Other
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
    31
  val kind: symbol -> kind
6116
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
    32
  val is_letter: symbol -> bool
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
    33
  val is_digit: symbol -> bool
12904
c208d71702d1 added is_quasi;
wenzelm
parents: 12116
diff changeset
    34
  val is_quasi: symbol -> bool
14678
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
    35
  val is_blank: symbol -> bool
6116
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
    36
  val is_quasi_letter: symbol -> bool
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
    37
  val is_letdig: symbol -> bool
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
    38
  val beginning: symbol list -> string
14678
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
    39
  val scanner: string -> (string list -> 'a * string list) -> symbol list -> 'a
13730
09aeb7346d3f default_output now escapes \'s more carefully.
berghofe
parents: 13559
diff changeset
    40
  val scan_id: string list -> string * string list
6116
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
    41
  val scan: string list -> symbol * string list
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
    42
  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
    43
    (symbol, (string, 'a) Source.source) Source.source
6272
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
    44
  val explode: string -> symbol list
14678
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
    45
  val strip_blanks: string -> string
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
    46
  val bump_init: string -> string
12904
c208d71702d1 added is_quasi;
wenzelm
parents: 12116
diff changeset
    47
  val bump_string: string -> string
14678
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
    48
  val length: symbol list -> int
10953
ea024d025463 added spaces;
wenzelm
parents: 10923
diff changeset
    49
  val default_indent: string * int -> string
ea024d025463 added spaces;
wenzelm
parents: 10923
diff changeset
    50
  val add_mode: string -> (string -> string * real) * (string * int -> string) -> unit
6692
05c56f41e661 avoid string constants;
wenzelm
parents: 6640
diff changeset
    51
  val symbolsN: string
05c56f41e661 avoid string constants;
wenzelm
parents: 6640
diff changeset
    52
  val xsymbolsN: string
10923
e34948f18541 export plain_output;
wenzelm
parents: 10747
diff changeset
    53
  val plain_output: string -> string
6272
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
    54
  val output: string -> string
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
    55
  val output_width: string -> string * real
10953
ea024d025463 added spaces;
wenzelm
parents: 10923
diff changeset
    56
  val indent: string * int -> string
6116
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
    57
end;
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
    58
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
    59
structure Symbol: SYMBOL =
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
    60
struct
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
    61
14678
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
    62
(** type symbol **)
6272
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
    63
14678
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
    64
(*Symbols, which are considered the smallest entities of any Isabelle
6272
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
    65
  string, may be of the following form:
14678
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
    66
6272
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
    67
    (a) ASCII symbols: a
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
    68
    (b) printable symbols: \<ident>
14557
31ae4a47267c * cleaner distinction between control symbols "\<^...>" and "\<^raw...>" in
schirmer
parents: 14361
diff changeset
    69
    (c) control symbols: \<^ident>
14561
c53396af770e * raw control symbols are of the form \<^raw:...> now.
schirmer
parents: 14559
diff changeset
    70
    (d) raw control symbols: \<^raw:...>, where "..." may be any printable
14557
31ae4a47267c * cleaner distinction between control symbols "\<^...>" and "\<^raw...>" in
schirmer
parents: 14361
diff changeset
    71
        character excluding ">"
6272
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
    72
14678
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
    73
  Output is subject to the print_mode variable (default: verbatim),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
    74
  actual interpretation in display is up to front-end tools.
14561
c53396af770e * raw control symbols are of the form \<^raw:...> now.
schirmer
parents: 14559
diff changeset
    75
14678
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
    76
  Symbols (b),(c) and (d) may optionally start with "\\" instead of
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
    77
  just "\" for compatibility with ML string literals (e.g. used in
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
    78
  old-style theory files and ML proof scripts).  To be on the safe
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
    79
  side, the default output of these symbols will also start with the
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
    80
  double "\\".
6272
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
    81
*)
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
    82
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
    83
type symbol = string;
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
    84
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
    85
val space = " ";
10953
ea024d025463 added spaces;
wenzelm
parents: 10923
diff changeset
    86
fun spaces k = Library.replicate_string k space;
14678
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
    87
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
    88
fun is_char s = size s = 1;
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
    89
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
    90
fun is_symbolic s =
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
    91
  String.isPrefix "\\<" s andalso not (String.isPrefix "\\<^" s);
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
    92
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
    93
fun is_printable s =
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
    94
  if is_char s then ord space <= ord s andalso ord s <= ord "~"
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
    95
  else not (String.isPrefix "\\<^" s);
6272
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
    96
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
    97
14678
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
    98
(* input source control *)
6272
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
    99
14678
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   100
val eof = "";
6272
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
   101
fun is_eof s = s = eof;
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
   102
fun not_eof s = s <> eof;
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
   103
val stopper = (eof, is_eof);
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
   104
14678
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   105
val sync = "\\<^sync>";
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   106
fun is_sync s = s = sync;
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   107
fun not_sync s = s <> sync;
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   108
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   109
val malformed = "\\<^malformed>";
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   110
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   111
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   112
(* ascii symbols *)
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   113
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   114
fun is_ascii s = is_char s andalso ord s < 128;
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   115
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   116
fun is_ascii_letter s =
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   117
  is_char s andalso
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   118
   (ord "A" <= ord s andalso ord s <= ord "Z" orelse
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   119
    ord "a" <= ord s andalso ord s <= ord "z");
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   120
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   121
fun is_ascii_digit s =
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   122
  is_char s andalso ord "0" <= ord s andalso ord s <= ord "9";
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   123
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   124
fun is_ascii_quasi "_" = true
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   125
  | is_ascii_quasi "'" = true
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   126
  | is_ascii_quasi _ = false;
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   127
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   128
val is_ascii_blank =
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   129
  fn " " => true | "\t" => true | "\r" => true | "\n" => true | "\^L" => true
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   130
    | _ => false;
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   131
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   132
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   133
(* standard symbol kinds *)
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   134
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   135
datatype kind = Letter | Digit | Quasi | Blank | Other;
6272
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
   136
14171
0cab06e3bbd0 Extended the notion of letter and digit, such that now one may use greek,
skalberg
parents: 13730
diff changeset
   137
local
14678
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   138
  val symbol_kinds = Symtab.make
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   139
   [("\\<A>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   140
    ("\\<B>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   141
    ("\\<C>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   142
    ("\\<D>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   143
    ("\\<E>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   144
    ("\\<F>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   145
    ("\\<G>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   146
    ("\\<H>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   147
    ("\\<I>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   148
    ("\\<J>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   149
    ("\\<K>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   150
    ("\\<L>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   151
    ("\\<M>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   152
    ("\\<N>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   153
    ("\\<O>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   154
    ("\\<P>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   155
    ("\\<Q>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   156
    ("\\<R>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   157
    ("\\<S>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   158
    ("\\<T>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   159
    ("\\<U>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   160
    ("\\<V>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   161
    ("\\<W>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   162
    ("\\<X>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   163
    ("\\<Y>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   164
    ("\\<Z>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   165
    ("\\<a>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   166
    ("\\<b>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   167
    ("\\<c>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   168
    ("\\<d>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   169
    ("\\<e>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   170
    ("\\<f>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   171
    ("\\<g>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   172
    ("\\<h>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   173
    ("\\<i>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   174
    ("\\<j>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   175
    ("\\<k>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   176
    ("\\<l>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   177
    ("\\<m>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   178
    ("\\<n>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   179
    ("\\<o>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   180
    ("\\<p>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   181
    ("\\<q>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   182
    ("\\<r>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   183
    ("\\<s>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   184
    ("\\<t>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   185
    ("\\<u>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   186
    ("\\<v>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   187
    ("\\<w>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   188
    ("\\<x>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   189
    ("\\<y>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   190
    ("\\<z>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   191
    ("\\<AA>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   192
    ("\\<BB>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   193
    ("\\<CC>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   194
    ("\\<DD>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   195
    ("\\<EE>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   196
    ("\\<FF>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   197
    ("\\<GG>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   198
    ("\\<HH>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   199
    ("\\<II>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   200
    ("\\<JJ>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   201
    ("\\<KK>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   202
    ("\\<LL>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   203
    ("\\<MM>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   204
    ("\\<NN>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   205
    ("\\<OO>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   206
    ("\\<PP>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   207
    ("\\<QQ>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   208
    ("\\<RR>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   209
    ("\\<SS>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   210
    ("\\<TT>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   211
    ("\\<UU>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   212
    ("\\<VV>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   213
    ("\\<WW>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   214
    ("\\<XX>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   215
    ("\\<YY>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   216
    ("\\<ZZ>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   217
    ("\\<aa>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   218
    ("\\<bb>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   219
    ("\\<cc>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   220
    ("\\<dd>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   221
    ("\\<ee>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   222
    ("\\<ff>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   223
    ("\\<gg>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   224
    ("\\<hh>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   225
    ("\\<ii>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   226
    ("\\<jj>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   227
    ("\\<kk>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   228
    ("\\<ll>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   229
    ("\\<mm>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   230
    ("\\<nn>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   231
    ("\\<oo>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   232
    ("\\<pp>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   233
    ("\\<qq>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   234
    ("\\<rr>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   235
    ("\\<ss>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   236
    ("\\<tt>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   237
    ("\\<uu>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   238
    ("\\<vv>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   239
    ("\\<ww>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   240
    ("\\<xx>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   241
    ("\\<yy>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   242
    ("\\<zz>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   243
    ("\\<alpha>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   244
    ("\\<beta>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   245
    ("\\<gamma>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   246
    ("\\<delta>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   247
    ("\\<epsilon>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   248
    ("\\<zeta>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   249
    ("\\<eta>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   250
    ("\\<theta>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   251
    ("\\<iota>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   252
    ("\\<kappa>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   253
    ("\\<lambda>", Other),      (*sic!*)
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   254
    ("\\<mu>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   255
    ("\\<nu>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   256
    ("\\<xi>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   257
    ("\\<pi>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   258
    ("\\<rho>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   259
    ("\\<sigma>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   260
    ("\\<tau>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   261
    ("\\<upsilon>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   262
    ("\\<phi>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   263
    ("\\<psi>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   264
    ("\\<omega>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   265
    ("\\<Gamma>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   266
    ("\\<Delta>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   267
    ("\\<Theta>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   268
    ("\\<Lambda>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   269
    ("\\<Xi>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   270
    ("\\<Pi>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   271
    ("\\<Sigma>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   272
    ("\\<Upsilon>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   273
    ("\\<Phi>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   274
    ("\\<Psi>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   275
    ("\\<Omega>", Letter),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   276
    ("\\<^isub>", Quasi),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   277
    ("\\<^isup>", Quasi),
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   278
    ("\\<spacespace>", Blank)];
14171
0cab06e3bbd0 Extended the notion of letter and digit, such that now one may use greek,
skalberg
parents: 13730
diff changeset
   279
in
14678
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   280
  fun kind s =
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   281
    if is_ascii_letter s then Letter
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   282
    else if is_ascii_digit s then Digit
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   283
    else if is_ascii_quasi s then Quasi
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   284
    else if is_ascii_blank s then Blank
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   285
    else if is_char s then Other
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   286
    else if_none (Symtab.lookup (symbol_kinds, s)) Other;
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   287
end;
14173
a3690aeb79d4 Removed the extended digits again.
skalberg
parents: 14171
diff changeset
   288
14678
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   289
fun is_letter s = kind s = Letter;
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   290
fun is_digit s = kind s = Digit;
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   291
fun is_quasi s = kind s = Quasi;
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   292
fun is_blank s = kind s = Blank;
6272
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
   293
14678
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   294
fun is_quasi_letter s = let val k = kind s in k = Letter orelse k = Quasi end;
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   295
fun is_letdig s = let val k = kind s in k = Letter orelse k = Digit orelse k = Quasi end;
11010
2c6559297be3 added strip_blanks;
wenzelm
parents: 10953
diff changeset
   296
6272
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
   297
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
   298
14678
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   299
(** symbol input **)
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   300
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   301
(* scanning through symbols *)
6272
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
   302
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
   303
fun beginning raw_ss =
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
   304
  let
14678
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   305
    val (all_ss, _) = Library.take_suffix is_blank raw_ss;
6272
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
   306
    val dots = if length all_ss > 10 then " ..." else "";
14678
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   307
    val (ss, _) = Library.take_suffix is_blank (Library.take (10, all_ss));
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   308
  in implode (map (fn s => if is_blank s then space else s) ss) ^ dots end;
6640
d2e8342bf5c3 rearranged order of modules;
wenzelm
parents: 6320
diff changeset
   309
d2e8342bf5c3 rearranged order of modules;
wenzelm
parents: 6320
diff changeset
   310
fun scanner msg scan chs =
d2e8342bf5c3 rearranged order of modules;
wenzelm
parents: 6320
diff changeset
   311
  let
d2e8342bf5c3 rearranged order of modules;
wenzelm
parents: 6320
diff changeset
   312
    fun err_msg cs = msg ^ ": " ^ beginning cs;
d2e8342bf5c3 rearranged order of modules;
wenzelm
parents: 6320
diff changeset
   313
    val fin_scan = Scan.error (Scan.finite stopper (!! (fn (cs, _) => err_msg cs) scan));
d2e8342bf5c3 rearranged order of modules;
wenzelm
parents: 6320
diff changeset
   314
  in
d2e8342bf5c3 rearranged order of modules;
wenzelm
parents: 6320
diff changeset
   315
    (case fin_scan chs of
d2e8342bf5c3 rearranged order of modules;
wenzelm
parents: 6320
diff changeset
   316
      (result, []) => result
d2e8342bf5c3 rearranged order of modules;
wenzelm
parents: 6320
diff changeset
   317
    | (_, rest) => error (err_msg rest))
d2e8342bf5c3 rearranged order of modules;
wenzelm
parents: 6320
diff changeset
   318
  end;
d2e8342bf5c3 rearranged order of modules;
wenzelm
parents: 6320
diff changeset
   319
d2e8342bf5c3 rearranged order of modules;
wenzelm
parents: 6320
diff changeset
   320
6116
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   321
(* scan *)
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   322
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   323
val scan_id = Scan.one is_letter ^^ (Scan.any is_letdig >> implode);
14678
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   324
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   325
local
14561
c53396af770e * raw control symbols are of the form \<^raw:...> now.
schirmer
parents: 14559
diff changeset
   326
14678
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   327
val scan_encoded_newline =
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   328
  $$ "\r" -- $$ "\n" >> K "\n" ||
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   329
  $$ "\r" >> K "\n" ||
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   330
  Scan.optional ($$ "\\") "" -- $$ "\\"  -- $$ "<"  -- $$ "^" -- $$ "n"
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   331
    -- $$ "e" -- $$ "w" -- $$ "l" -- $$ "i" -- $$ "n" -- $$ "e" -- $$ ">" >> K "\n";
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   332
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   333
fun raw_body c = ord space <= ord c andalso ord c <= ord "~" andalso c <> ">";
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   334
val scan_raw = $$ "r" ^^ $$ "a" ^^ $$ "w" ^^ $$ ":" ^^ (Scan.any raw_body >> implode);
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   335
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   336
in
6116
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   337
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   338
val scan =
14678
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   339
  scan_encoded_newline ||
14561
c53396af770e * raw control symbols are of the form \<^raw:...> now.
schirmer
parents: 14559
diff changeset
   340
  ($$ "\\" --| Scan.optional ($$ "\\") "") ^^ $$ "<" ^^
6116
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   341
    !! (fn (cs, _) => "Malformed symbolic character specification: \\" ^ "<" ^ beginning cs)
14678
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   342
       (($$ "^" ^^ (scan_raw || scan_id) || scan_id) ^^ $$ ">") ||
6116
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   343
  Scan.one not_eof;
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   344
14678
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   345
end;
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   346
14562
980da32f4617 proper handling of lines terminated by CRLF or CR;
wenzelm
parents: 14561
diff changeset
   347
6116
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   348
(* source *)
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   349
10747
794cd4d768b5 scan: malformed result;
wenzelm
parents: 10738
diff changeset
   350
val recover = Scan.any ((not o is_blank) andf not_eof) >> K [malformed];
6116
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   351
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   352
fun source do_recover src =
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   353
  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
   354
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   355
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   356
(* explode *)
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   357
14562
980da32f4617 proper handling of lines terminated by CRLF or CR;
wenzelm
parents: 14561
diff changeset
   358
fun no_explode [] = true
980da32f4617 proper handling of lines terminated by CRLF or CR;
wenzelm
parents: 14561
diff changeset
   359
  | no_explode ("\\" :: "<" :: _) = false
980da32f4617 proper handling of lines terminated by CRLF or CR;
wenzelm
parents: 14561
diff changeset
   360
  | no_explode ("\r" :: _) = false
980da32f4617 proper handling of lines terminated by CRLF or CR;
wenzelm
parents: 14561
diff changeset
   361
  | no_explode (_ :: cs) = no_explode cs;
6116
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   362
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   363
fun sym_explode str =
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   364
  let val chs = explode str in
14562
980da32f4617 proper handling of lines terminated by CRLF or CR;
wenzelm
parents: 14561
diff changeset
   365
    if no_explode chs then chs
12116
4027b15377a5 got rid of obsolete input filtering;
wenzelm
parents: 11010
diff changeset
   366
    else the (Scan.read stopper (Scan.repeat scan) chs)
6116
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   367
  end;
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   368
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   369
14678
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   370
(* blanks *)
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   371
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   372
fun strip_blanks s =
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   373
  sym_explode s
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   374
  |> Library.take_prefix is_blank |> #2
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   375
  |> Library.take_suffix is_blank |> #1
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   376
  |> implode;
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   377
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   378
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   379
(* bump string -- treat as base 26 or base 1 numbers *)
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   380
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   381
fun ends_symbolic (_ :: "\\<^isup>" :: _) = true
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   382
  | ends_symbolic (_ :: "\\<^isub>" :: _) = true
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   383
  | ends_symbolic (s :: _) = is_symbolic s
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   384
  | ends_symbolic [] = false;
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   385
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   386
fun bump_init str =
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   387
  if ends_symbolic (rev (sym_explode str)) then str ^ "'"
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   388
  else str ^ "a";
12904
c208d71702d1 added is_quasi;
wenzelm
parents: 12116
diff changeset
   389
c208d71702d1 added is_quasi;
wenzelm
parents: 12116
diff changeset
   390
fun bump_string str =
c208d71702d1 added is_quasi;
wenzelm
parents: 12116
diff changeset
   391
  let
c208d71702d1 added is_quasi;
wenzelm
parents: 12116
diff changeset
   392
    fun bump [] = ["a"]
c208d71702d1 added is_quasi;
wenzelm
parents: 12116
diff changeset
   393
      | bump ("z" :: ss) = "a" :: bump ss
c208d71702d1 added is_quasi;
wenzelm
parents: 12116
diff changeset
   394
      | bump (s :: ss) =
14678
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   395
          if is_char s andalso ord "a" <= ord s andalso ord s < ord "z"
12904
c208d71702d1 added is_quasi;
wenzelm
parents: 12116
diff changeset
   396
          then chr (ord s + 1) :: ss
c208d71702d1 added is_quasi;
wenzelm
parents: 12116
diff changeset
   397
          else "a" :: s :: ss;
14678
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   398
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   399
    val (ss, qs) = apfst rev (Library.take_suffix is_quasi (sym_explode str));
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   400
    val ss' = if ends_symbolic ss then "'" :: ss else bump ss;
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   401
  in implode (rev ss' @ qs) end;
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   402
12904
c208d71702d1 added is_quasi;
wenzelm
parents: 12116
diff changeset
   403
6272
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
   404
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
   405
(** symbol output **)
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
   406
14678
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   407
fun sym_len s =
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   408
  if not (is_printable s) then 0
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   409
  else if String.isPrefix "\\<long" s then 2
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   410
  else if String.isPrefix "\\<Long" s then 2
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   411
  else if s = "\\<spacespace>" then 2
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   412
  else 1;
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   413
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   414
fun sym_length ss = foldl (fn (n, s) => sym_len s + n) (0, ss);
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   415
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   416
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   417
(* default output *)
6272
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
   418
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
   419
fun string_size s = (s, real (size s));
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
   420
14678
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   421
fun sym_escape s = if is_char s then s else "\\" ^ s;
13730
09aeb7346d3f default_output now escapes \'s more carefully.
berghofe
parents: 13559
diff changeset
   422
14561
c53396af770e * raw control symbols are of the form \<^raw:...> now.
schirmer
parents: 14559
diff changeset
   423
fun default_output s =
c53396af770e * raw control symbols are of the form \<^raw:...> now.
schirmer
parents: 14559
diff changeset
   424
  if not (exists_string (equal "\\") s) then string_size s
c53396af770e * raw control symbols are of the form \<^raw:...> now.
schirmer
parents: 14559
diff changeset
   425
  else string_size (implode (map sym_escape (sym_explode s)));
6272
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
   426
10953
ea024d025463 added spaces;
wenzelm
parents: 10923
diff changeset
   427
fun default_indent (_: string, k) = spaces k;
6272
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
   428
10953
ea024d025463 added spaces;
wenzelm
parents: 10923
diff changeset
   429
14678
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   430
(* print modes *)
6272
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
   431
6692
05c56f41e661 avoid string constants;
wenzelm
parents: 6640
diff changeset
   432
val symbolsN = "symbols";
05c56f41e661 avoid string constants;
wenzelm
parents: 6640
diff changeset
   433
val xsymbolsN = "xsymbols";
05c56f41e661 avoid string constants;
wenzelm
parents: 6640
diff changeset
   434
12116
4027b15377a5 got rid of obsolete input filtering;
wenzelm
parents: 11010
diff changeset
   435
val modes =
4027b15377a5 got rid of obsolete input filtering;
wenzelm
parents: 11010
diff changeset
   436
  ref (Symtab.empty: ((string -> string * real) * (string * int -> string)) Symtab.table);
6272
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
   437
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
   438
fun lookup_mode name = Symtab.lookup (! modes, name);
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
   439
10953
ea024d025463 added spaces;
wenzelm
parents: 10923
diff changeset
   440
fun add_mode name m =
6272
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
   441
 (if is_none (lookup_mode name) then ()
6320
4df282137880 tuned using nth_elem_string, exists_string;
wenzelm
parents: 6272
diff changeset
   442
  else warning ("Redeclaration of symbol print mode " ^ quote name);
10953
ea024d025463 added spaces;
wenzelm
parents: 10923
diff changeset
   443
  modes := Symtab.update ((name, m), ! modes));
ea024d025463 added spaces;
wenzelm
parents: 10923
diff changeset
   444
ea024d025463 added spaces;
wenzelm
parents: 10923
diff changeset
   445
fun get_mode () =
ea024d025463 added spaces;
wenzelm
parents: 10923
diff changeset
   446
  if_none (get_first lookup_mode (! print_mode)) (default_output, default_indent);
6272
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
   447
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
   448
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
   449
(* mode output *)
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
   450
10953
ea024d025463 added spaces;
wenzelm
parents: 10923
diff changeset
   451
fun output_width x = #1 (get_mode ()) x;
6272
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
   452
val output = #1 o output_width;
14561
c53396af770e * raw control symbols are of the form \<^raw:...> now.
schirmer
parents: 14559
diff changeset
   453
val plain_output = #1 o default_output;
14678
662b181cae05 clarification of ascii vs. symbolic entities;
wenzelm
parents: 14632
diff changeset
   454
10953
ea024d025463 added spaces;
wenzelm
parents: 10923
diff changeset
   455
fun indent x = #2 (get_mode ()) x;
ea024d025463 added spaces;
wenzelm
parents: 10923
diff changeset
   456
6272
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
   457
6116
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   458
(*final declarations of this structure!*)
6272
52d99d68d3be added output_width;
wenzelm
parents: 6225
diff changeset
   459
val length = sym_length;
6116
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   460
val explode = sym_explode;
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   461
8ba2f25610f7 files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff changeset
   462
end;