src/Pure/Syntax/lexicon.ML
author wenzelm
Sat, 07 Dec 2024 23:50:18 +0100
changeset 81558 b57996a0688c
parent 81225 2157039256d3
child 81596 af21a61dadad
permissions -rw-r--r--
clarified term positions and markup: syntax = true means this is via concrete syntax; clarified text color rendering;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
     1
(*  Title:      Pure/Syntax/lexicon.ML
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
     2
    Author:     Tobias Nipkow and Markus Wenzel, TU Muenchen
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     3
4703
a50ab39756db adapted to symbols, scan;
wenzelm
parents: 4587
diff changeset
     4
Lexer for the inner Isabelle syntax (terms and types).
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
     5
*)
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     6
42290
b1f544c84040 discontinued special treatment of structure Lexicon;
wenzelm
parents: 42264
diff changeset
     7
signature LEXICON =
4247
9bba9251bb4d added implode_xstr: string list -> string, explode_xstr: string -> string list;
wenzelm
parents: 3828
diff changeset
     8
sig
42476
d0bc1268ef09 clarified auxiliary structure Lexicon.Syntax;
wenzelm
parents: 42290
diff changeset
     9
  structure Syntax:
d0bc1268ef09 clarified auxiliary structure Lexicon.Syntax;
wenzelm
parents: 42290
diff changeset
    10
  sig
d0bc1268ef09 clarified auxiliary structure Lexicon.Syntax;
wenzelm
parents: 42290
diff changeset
    11
    val const: string -> term
d0bc1268ef09 clarified auxiliary structure Lexicon.Syntax;
wenzelm
parents: 42290
diff changeset
    12
    val free: string -> term
d0bc1268ef09 clarified auxiliary structure Lexicon.Syntax;
wenzelm
parents: 42290
diff changeset
    13
    val var: indexname -> term
d0bc1268ef09 clarified auxiliary structure Lexicon.Syntax;
wenzelm
parents: 42290
diff changeset
    14
  end
67426
6311cf9dc943 clarified signature;
wenzelm
parents: 67425
diff changeset
    15
  val scan_id: Symbol_Pos.T list scanner
6311cf9dc943 clarified signature;
wenzelm
parents: 67425
diff changeset
    16
  val scan_longid: Symbol_Pos.T list scanner
6311cf9dc943 clarified signature;
wenzelm
parents: 67425
diff changeset
    17
  val scan_tid: Symbol_Pos.T list scanner
6311cf9dc943 clarified signature;
wenzelm
parents: 67425
diff changeset
    18
  val scan_hex: Symbol_Pos.T list scanner
6311cf9dc943 clarified signature;
wenzelm
parents: 67425
diff changeset
    19
  val scan_bin: Symbol_Pos.T list scanner
6311cf9dc943 clarified signature;
wenzelm
parents: 67425
diff changeset
    20
  val scan_var: Symbol_Pos.T list scanner
6311cf9dc943 clarified signature;
wenzelm
parents: 67425
diff changeset
    21
  val scan_tvar: Symbol_Pos.T list scanner
50239
fb579401dc26 tuned signature;
wenzelm
parents: 50238
diff changeset
    22
  val is_tid: string -> bool
27800
df444ddeff56 datatype token: maintain range, tuned representation;
wenzelm
parents: 27773
diff changeset
    23
  datatype token_kind =
67548
c0f1667c1943 clarified signature;
wenzelm
parents: 67539
diff changeset
    24
    Literal | Ident | Long_Ident | Var | Type_Ident | Type_Var | Num | Float | Str |
69042
6e9df530b441 discontinued old-style inner comments;
wenzelm
parents: 67556
diff changeset
    25
    String | Cartouche | Space | Comment of Comment.kind | Dummy | EOF
67554
c2151a6bfd57 more abstract type;
wenzelm
parents: 67552
diff changeset
    26
  eqtype token
67412
wenzelm
parents: 67388
diff changeset
    27
  val kind_of_token: token -> token_kind
27806
ece79c0597fe pos_of_token: Position.T;
wenzelm
parents: 27800
diff changeset
    28
  val str_of_token: token -> string
81006
6d7dcb91ba5d more operations;
wenzelm
parents: 80979
diff changeset
    29
  val range_of_token: token -> Position.range
27806
ece79c0597fe pos_of_token: Position.T;
wenzelm
parents: 27800
diff changeset
    30
  val pos_of_token: token -> Position.T
67551
4a087b9a29c5 clarified signature;
wenzelm
parents: 67550
diff changeset
    31
  val end_pos_of_token: token -> Position.T
67555
c550e38dd131 more efficient tokens_match_ord based on token_kind_index;
wenzelm
parents: 67554
diff changeset
    32
  val is_proper: token -> bool
c550e38dd131 more efficient tokens_match_ord based on token_kind_index;
wenzelm
parents: 67554
diff changeset
    33
  val dummy: token
80964
f9230aabcc2a clarified use of Lexicon.dummy;
wenzelm
parents: 80952
diff changeset
    34
  val is_dummy: token -> bool
67552
679253fef277 clarified signature;
wenzelm
parents: 67551
diff changeset
    35
  val literal: string -> token
679253fef277 clarified signature;
wenzelm
parents: 67551
diff changeset
    36
  val is_literal: token -> bool
80978
5e2b1588c5cb minor performance tuning: proper table for parsetree list;
wenzelm
parents: 80964
diff changeset
    37
  val token_ord: token ord
81006
6d7dcb91ba5d more operations;
wenzelm
parents: 80979
diff changeset
    38
  val token_content_ord: token ord
80979
e38c65002f44 clarified signature;
wenzelm
parents: 80978
diff changeset
    39
  val token_type_ord: token ord
27800
df444ddeff56 datatype token: maintain range, tuned representation;
wenzelm
parents: 27773
diff changeset
    40
  val mk_eof: Position.T -> token
df444ddeff56 datatype token: maintain range, tuned representation;
wenzelm
parents: 27773
diff changeset
    41
  val eof: token
df444ddeff56 datatype token: maintain range, tuned representation;
wenzelm
parents: 27773
diff changeset
    42
  val is_eof: token -> bool
df444ddeff56 datatype token: maintain range, tuned representation;
wenzelm
parents: 27773
diff changeset
    43
  val stopper: token Scan.stopper
237
a7d3e712767a MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
wenzelm
parents: 164
diff changeset
    44
  val terminals: string list
a7d3e712767a MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
wenzelm
parents: 164
diff changeset
    45
  val is_terminal: string -> bool
67556
wenzelm
parents: 67555
diff changeset
    46
  val get_terminal: string -> token option
73163
624c2b98860a suppress markup for literal tokens with block control symbols, for better PIDE/HTML output (see also d15fe10593ff);
wenzelm
parents: 70586
diff changeset
    47
  val literal_markup: string -> Markup.T list
624c2b98860a suppress markup for literal tokens with block control symbols, for better PIDE/HTML output (see also d15fe10593ff);
wenzelm
parents: 70586
diff changeset
    48
  val reports_of_token: token -> Position.report list
39510
d9f5f01faa1b Syntax.read_asts error: report token ranges within message -- no side-effect here;
wenzelm
parents: 39507
diff changeset
    49
  val reported_token_range: Proof.context -> token -> string
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
    50
  val valued_token: token -> bool
55108
0b7a0c1fdf7e inner syntax token language allows regular quoted strings;
wenzelm
parents: 55107
diff changeset
    51
  val implode_string: Symbol.symbol list -> string
0b7a0c1fdf7e inner syntax token language allows regular quoted strings;
wenzelm
parents: 55107
diff changeset
    52
  val explode_string: string * Position.T -> Symbol_Pos.T list
0b7a0c1fdf7e inner syntax token language allows regular quoted strings;
wenzelm
parents: 55107
diff changeset
    53
  val implode_str: Symbol.symbol list -> string
0b7a0c1fdf7e inner syntax token language allows regular quoted strings;
wenzelm
parents: 55107
diff changeset
    54
  val explode_str: string * Position.T -> Symbol_Pos.T list
30573
49899f26fbd1 de-camelized Symbol_Pos;
wenzelm
parents: 29565
diff changeset
    55
  val tokenize: Scan.lexicon -> bool -> Symbol_Pos.T list -> token list
42290
b1f544c84040 discontinued special treatment of structure Lexicon;
wenzelm
parents: 42264
diff changeset
    56
  val read_indexname: string -> indexname
b1f544c84040 discontinued special treatment of structure Lexicon;
wenzelm
parents: 42264
diff changeset
    57
  val read_var: string -> term
b1f544c84040 discontinued special treatment of structure Lexicon;
wenzelm
parents: 42264
diff changeset
    58
  val read_variable: string -> indexname option
b1f544c84040 discontinued special treatment of structure Lexicon;
wenzelm
parents: 42264
diff changeset
    59
  val read_nat: string -> int option
b1f544c84040 discontinued special treatment of structure Lexicon;
wenzelm
parents: 42264
diff changeset
    60
  val read_int: string -> int option
58421
37cbbd8eb460 discontinued old "xnum" token category;
wenzelm
parents: 58410
diff changeset
    61
  val read_num: string -> {radix: int, leading_zeros: int, value: int}
42290
b1f544c84040 discontinued special treatment of structure Lexicon;
wenzelm
parents: 42264
diff changeset
    62
  val read_float: string -> {mant: int, exp: int}
81225
2157039256d3 clarified markers for syntax consts: avoid overlap with logical consts;
wenzelm
parents: 81209
diff changeset
    63
  val mark_syntax: string -> string
2157039256d3 clarified markers for syntax consts: avoid overlap with logical consts;
wenzelm
parents: 81209
diff changeset
    64
  val mark_binder: string -> string
2157039256d3 clarified markers for syntax consts: avoid overlap with logical consts;
wenzelm
parents: 81209
diff changeset
    65
  val mark_indexed: string -> string
81209
20d7631b37d7 more operations;
wenzelm
parents: 81006
diff changeset
    66
  val mark_class: string -> string val unmark_class: string -> string val is_class: string -> bool
20d7631b37d7 more operations;
wenzelm
parents: 81006
diff changeset
    67
  val mark_type: string -> string val unmark_type: string -> string val is_type: string -> bool
20d7631b37d7 more operations;
wenzelm
parents: 81006
diff changeset
    68
  val mark_const: string -> string val unmark_const: string -> string val is_const: string -> bool
20d7631b37d7 more operations;
wenzelm
parents: 81006
diff changeset
    69
  val mark_fixed: string -> string val unmark_fixed: string -> string val is_fixed: string -> bool
42290
b1f544c84040 discontinued special treatment of structure Lexicon;
wenzelm
parents: 42264
diff changeset
    70
  val unmark:
b1f544c84040 discontinued special treatment of structure Lexicon;
wenzelm
parents: 42264
diff changeset
    71
   {case_class: string -> 'a,
b1f544c84040 discontinued special treatment of structure Lexicon;
wenzelm
parents: 42264
diff changeset
    72
    case_type: string -> 'a,
b1f544c84040 discontinued special treatment of structure Lexicon;
wenzelm
parents: 42264
diff changeset
    73
    case_const: string -> 'a,
b1f544c84040 discontinued special treatment of structure Lexicon;
wenzelm
parents: 42264
diff changeset
    74
    case_fixed: string -> 'a,
b1f544c84040 discontinued special treatment of structure Lexicon;
wenzelm
parents: 42264
diff changeset
    75
    case_default: string -> 'a} -> string -> 'a
b1f544c84040 discontinued special treatment of structure Lexicon;
wenzelm
parents: 42264
diff changeset
    76
  val is_marked: string -> bool
b1f544c84040 discontinued special treatment of structure Lexicon;
wenzelm
parents: 42264
diff changeset
    77
  val dummy_type: term
b1f544c84040 discontinued special treatment of structure Lexicon;
wenzelm
parents: 42264
diff changeset
    78
  val fun_type: term
4247
9bba9251bb4d added implode_xstr: string list -> string, explode_xstr: string -> string list;
wenzelm
parents: 3828
diff changeset
    79
end;
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    80
14679
6ed90bd68eda added is_ascii_identifier;
wenzelm
parents: 13808
diff changeset
    81
structure Lexicon: LEXICON =
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    82
struct
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    83
69344
f87fdd8d2baf tuned spelling;
wenzelm
parents: 69320
diff changeset
    84
(** syntactic terms **)
42476
d0bc1268ef09 clarified auxiliary structure Lexicon.Syntax;
wenzelm
parents: 42290
diff changeset
    85
d0bc1268ef09 clarified auxiliary structure Lexicon.Syntax;
wenzelm
parents: 42290
diff changeset
    86
structure Syntax =
d0bc1268ef09 clarified auxiliary structure Lexicon.Syntax;
wenzelm
parents: 42290
diff changeset
    87
struct
d0bc1268ef09 clarified auxiliary structure Lexicon.Syntax;
wenzelm
parents: 42290
diff changeset
    88
d0bc1268ef09 clarified auxiliary structure Lexicon.Syntax;
wenzelm
parents: 42290
diff changeset
    89
fun const c = Const (c, dummyT);
d0bc1268ef09 clarified auxiliary structure Lexicon.Syntax;
wenzelm
parents: 42290
diff changeset
    90
fun free x = Free (x, dummyT);
d0bc1268ef09 clarified auxiliary structure Lexicon.Syntax;
wenzelm
parents: 42290
diff changeset
    91
fun var xi = Var (xi, dummyT);
d0bc1268ef09 clarified auxiliary structure Lexicon.Syntax;
wenzelm
parents: 42290
diff changeset
    92
d0bc1268ef09 clarified auxiliary structure Lexicon.Syntax;
wenzelm
parents: 42290
diff changeset
    93
end;
d0bc1268ef09 clarified auxiliary structure Lexicon.Syntax;
wenzelm
parents: 42290
diff changeset
    94
d0bc1268ef09 clarified auxiliary structure Lexicon.Syntax;
wenzelm
parents: 42290
diff changeset
    95
d0bc1268ef09 clarified auxiliary structure Lexicon.Syntax;
wenzelm
parents: 42290
diff changeset
    96
4703
a50ab39756db adapted to symbols, scan;
wenzelm
parents: 4587
diff changeset
    97
(** basic scanners **)
a50ab39756db adapted to symbols, scan;
wenzelm
parents: 4587
diff changeset
    98
30573
49899f26fbd1 de-camelized Symbol_Pos;
wenzelm
parents: 29565
diff changeset
    99
open Basic_Symbol_Pos;
27773
a52166b228b9 improved position handling due to SymbolPos.T;
wenzelm
parents: 27121
diff changeset
   100
55105
75815b3b38a1 tuned -- more direct err_prefix;
wenzelm
parents: 55035
diff changeset
   101
val err_prefix = "Inner lexical error: ";
75815b3b38a1 tuned -- more direct err_prefix;
wenzelm
parents: 55035
diff changeset
   102
75815b3b38a1 tuned -- more direct err_prefix;
wenzelm
parents: 55035
diff changeset
   103
fun !!! msg = Symbol_Pos.!!! (fn () => err_prefix ^ msg);
27773
a52166b228b9 improved position handling due to SymbolPos.T;
wenzelm
parents: 27121
diff changeset
   104
50239
fb579401dc26 tuned signature;
wenzelm
parents: 50238
diff changeset
   105
val scan_id = Symbol_Pos.scan_ident;
61476
1884c40f1539 tuned signature;
wenzelm
parents: 59196
diff changeset
   106
val scan_longid = scan_id @@@ Scan.repeats1 ($$$ "." @@@ scan_id);
27773
a52166b228b9 improved position handling due to SymbolPos.T;
wenzelm
parents: 27121
diff changeset
   107
val scan_tid = $$$ "'" @@@ scan_id;
4703
a50ab39756db adapted to symbols, scan;
wenzelm
parents: 4587
diff changeset
   108
40525
14a2e686bdac eliminated slightly odd pervasive Symbol_Pos.symbol;
wenzelm
parents: 40290
diff changeset
   109
val scan_hex = $$$ "0" @@@ $$$ "x" @@@ Scan.many1 (Symbol.is_ascii_hex o Symbol_Pos.symbol);
27773
a52166b228b9 improved position handling due to SymbolPos.T;
wenzelm
parents: 27121
diff changeset
   110
val scan_bin = $$$ "0" @@@ $$$ "b" @@@ Scan.many1 (fn (s, _) => s = "0" orelse s = "1");
62782
057e8dbe4326 clarified modules;
wenzelm
parents: 62751
diff changeset
   111
val scan_num = scan_hex || scan_bin || Symbol_Pos.scan_nat;
4703
a50ab39756db adapted to symbols, scan;
wenzelm
parents: 4587
diff changeset
   112
62782
057e8dbe4326 clarified modules;
wenzelm
parents: 62751
diff changeset
   113
val scan_id_nat = scan_id @@@ Scan.optional ($$$ "." @@@ Symbol_Pos.scan_nat) [];
27773
a52166b228b9 improved position handling due to SymbolPos.T;
wenzelm
parents: 27121
diff changeset
   114
val scan_var = $$$ "?" @@@ scan_id_nat;
a52166b228b9 improved position handling due to SymbolPos.T;
wenzelm
parents: 27121
diff changeset
   115
val scan_tvar = $$$ "?" @@@ $$$ "'" @@@ scan_id_nat;
4703
a50ab39756db adapted to symbols, scan;
wenzelm
parents: 4587
diff changeset
   116
50239
fb579401dc26 tuned signature;
wenzelm
parents: 50238
diff changeset
   117
fun is_tid s =
fb579401dc26 tuned signature;
wenzelm
parents: 50238
diff changeset
   118
  (case try (unprefix "'") s of
fb579401dc26 tuned signature;
wenzelm
parents: 50238
diff changeset
   119
    SOME s' => Symbol_Pos.is_identifier s'
fb579401dc26 tuned signature;
wenzelm
parents: 50238
diff changeset
   120
  | NONE => false);
fb579401dc26 tuned signature;
wenzelm
parents: 50238
diff changeset
   121
4703
a50ab39756db adapted to symbols, scan;
wenzelm
parents: 4587
diff changeset
   122
a50ab39756db adapted to symbols, scan;
wenzelm
parents: 4587
diff changeset
   123
67555
c550e38dd131 more efficient tokens_match_ord based on token_kind_index;
wenzelm
parents: 67554
diff changeset
   124
(** tokens **)
c550e38dd131 more efficient tokens_match_ord based on token_kind_index;
wenzelm
parents: 67554
diff changeset
   125
c550e38dd131 more efficient tokens_match_ord based on token_kind_index;
wenzelm
parents: 67554
diff changeset
   126
(* datatype token_kind *)
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   127
27800
df444ddeff56 datatype token: maintain range, tuned representation;
wenzelm
parents: 27773
diff changeset
   128
datatype token_kind =
67548
c0f1667c1943 clarified signature;
wenzelm
parents: 67539
diff changeset
   129
  Literal | Ident | Long_Ident | Var | Type_Ident | Type_Var | Num | Float | Str |
69042
6e9df530b441 discontinued old-style inner comments;
wenzelm
parents: 67556
diff changeset
   130
  String | Cartouche | Space | Comment of Comment.kind | Dummy | EOF;
27800
df444ddeff56 datatype token: maintain range, tuned representation;
wenzelm
parents: 27773
diff changeset
   131
67555
c550e38dd131 more efficient tokens_match_ord based on token_kind_index;
wenzelm
parents: 67554
diff changeset
   132
val token_kinds =
c550e38dd131 more efficient tokens_match_ord based on token_kind_index;
wenzelm
parents: 67554
diff changeset
   133
  Vector.fromList
c550e38dd131 more efficient tokens_match_ord based on token_kind_index;
wenzelm
parents: 67554
diff changeset
   134
   [Literal, Ident, Long_Ident, Var, Type_Ident, Type_Var, Num, Float, Str,
69042
6e9df530b441 discontinued old-style inner comments;
wenzelm
parents: 67556
diff changeset
   135
    String, Cartouche, Space, Comment Comment.Comment, Comment Comment.Cancel,
6e9df530b441 discontinued old-style inner comments;
wenzelm
parents: 67556
diff changeset
   136
    Comment Comment.Latex, Dummy, EOF];
67539
1b8aad1909b7 tuned data structure and operations;
wenzelm
parents: 67532
diff changeset
   137
77846
5ba68d3bd741 more operations, following Isabelle/ML conventions;
wenzelm
parents: 73198
diff changeset
   138
val token_kind = Vector.nth token_kinds;
67555
c550e38dd131 more efficient tokens_match_ord based on token_kind_index;
wenzelm
parents: 67554
diff changeset
   139
fun token_kind_index k = #1 (the (Vector.findi (fn (_, k') => k = k') token_kinds));
67539
1b8aad1909b7 tuned data structure and operations;
wenzelm
parents: 67532
diff changeset
   140
1b8aad1909b7 tuned data structure and operations;
wenzelm
parents: 67532
diff changeset
   141
67555
c550e38dd131 more efficient tokens_match_ord based on token_kind_index;
wenzelm
parents: 67554
diff changeset
   142
(* datatype token *)
27800
df444ddeff56 datatype token: maintain range, tuned representation;
wenzelm
parents: 27773
diff changeset
   143
67555
c550e38dd131 more efficient tokens_match_ord based on token_kind_index;
wenzelm
parents: 67554
diff changeset
   144
datatype token = Token of int * string * Position.range;
c550e38dd131 more efficient tokens_match_ord based on token_kind_index;
wenzelm
parents: 67554
diff changeset
   145
c550e38dd131 more efficient tokens_match_ord based on token_kind_index;
wenzelm
parents: 67554
diff changeset
   146
fun index_of_token (Token (i, _, _)) = i;
c550e38dd131 more efficient tokens_match_ord based on token_kind_index;
wenzelm
parents: 67554
diff changeset
   147
val kind_of_token = index_of_token #> token_kind;
27806
ece79c0597fe pos_of_token: Position.T;
wenzelm
parents: 27800
diff changeset
   148
fun str_of_token (Token (_, s, _)) = s;
81006
6d7dcb91ba5d more operations;
wenzelm
parents: 80979
diff changeset
   149
fun range_of_token (Token (_, _, r)) = r;
6d7dcb91ba5d more operations;
wenzelm
parents: 80979
diff changeset
   150
val pos_of_token = #1 o range_of_token;
6d7dcb91ba5d more operations;
wenzelm
parents: 80979
diff changeset
   151
val end_pos_of_token = #1 o range_of_token;
27806
ece79c0597fe pos_of_token: Position.T;
wenzelm
parents: 27800
diff changeset
   152
67425
7d4a088dbc0e clarified modules: uniform notion of formal comments;
wenzelm
parents: 67413
diff changeset
   153
val is_proper = kind_of_token #> (fn Space => false | Comment _ => false | _ => true);
27887
9f3fd48cf673 token_kind: add Space, Comment;
wenzelm
parents: 27806
diff changeset
   154
80964
f9230aabcc2a clarified use of Lexicon.dummy;
wenzelm
parents: 80952
diff changeset
   155
val dummy_index = token_kind_index Dummy;
f9230aabcc2a clarified use of Lexicon.dummy;
wenzelm
parents: 80952
diff changeset
   156
val dummy = Token (dummy_index, "", Position.no_range);
f9230aabcc2a clarified use of Lexicon.dummy;
wenzelm
parents: 80952
diff changeset
   157
fun is_dummy tok = index_of_token tok = dummy_index;
67555
c550e38dd131 more efficient tokens_match_ord based on token_kind_index;
wenzelm
parents: 67554
diff changeset
   158
c550e38dd131 more efficient tokens_match_ord based on token_kind_index;
wenzelm
parents: 67554
diff changeset
   159
c550e38dd131 more efficient tokens_match_ord based on token_kind_index;
wenzelm
parents: 67554
diff changeset
   160
(* literals *)
c550e38dd131 more efficient tokens_match_ord based on token_kind_index;
wenzelm
parents: 67554
diff changeset
   161
c550e38dd131 more efficient tokens_match_ord based on token_kind_index;
wenzelm
parents: 67554
diff changeset
   162
val literal_index = token_kind_index Literal;
c550e38dd131 more efficient tokens_match_ord based on token_kind_index;
wenzelm
parents: 67554
diff changeset
   163
fun literal s = Token (literal_index, s, Position.no_range);
c550e38dd131 more efficient tokens_match_ord based on token_kind_index;
wenzelm
parents: 67554
diff changeset
   164
fun is_literal tok = index_of_token tok = literal_index;
c550e38dd131 more efficient tokens_match_ord based on token_kind_index;
wenzelm
parents: 67554
diff changeset
   165
80978
5e2b1588c5cb minor performance tuning: proper table for parsetree list;
wenzelm
parents: 80964
diff changeset
   166
5e2b1588c5cb minor performance tuning: proper table for parsetree list;
wenzelm
parents: 80964
diff changeset
   167
(* order *)
5e2b1588c5cb minor performance tuning: proper table for parsetree list;
wenzelm
parents: 80964
diff changeset
   168
5e2b1588c5cb minor performance tuning: proper table for parsetree list;
wenzelm
parents: 80964
diff changeset
   169
fun token_ord (Token (i, s, r), Token (i', s', r')) =
5e2b1588c5cb minor performance tuning: proper table for parsetree list;
wenzelm
parents: 80964
diff changeset
   170
  (case int_ord (i, i') of
5e2b1588c5cb minor performance tuning: proper table for parsetree list;
wenzelm
parents: 80964
diff changeset
   171
    EQUAL =>
5e2b1588c5cb minor performance tuning: proper table for parsetree list;
wenzelm
parents: 80964
diff changeset
   172
      (case fast_string_ord (s, s') of
5e2b1588c5cb minor performance tuning: proper table for parsetree list;
wenzelm
parents: 80964
diff changeset
   173
        EQUAL => Position.range_ord (r, r')
5e2b1588c5cb minor performance tuning: proper table for parsetree list;
wenzelm
parents: 80964
diff changeset
   174
      | ord => ord)
5e2b1588c5cb minor performance tuning: proper table for parsetree list;
wenzelm
parents: 80964
diff changeset
   175
  | ord => ord);
5e2b1588c5cb minor performance tuning: proper table for parsetree list;
wenzelm
parents: 80964
diff changeset
   176
81006
6d7dcb91ba5d more operations;
wenzelm
parents: 80979
diff changeset
   177
fun token_content_ord (Token (i, s, _), Token (i', s', _)) =
6d7dcb91ba5d more operations;
wenzelm
parents: 80979
diff changeset
   178
  (case int_ord (i, i') of
6d7dcb91ba5d more operations;
wenzelm
parents: 80979
diff changeset
   179
    EQUAL => fast_string_ord (s, s')
6d7dcb91ba5d more operations;
wenzelm
parents: 80979
diff changeset
   180
  | ord => ord);
6d7dcb91ba5d more operations;
wenzelm
parents: 80979
diff changeset
   181
80979
e38c65002f44 clarified signature;
wenzelm
parents: 80978
diff changeset
   182
fun token_type_ord toks =
67555
c550e38dd131 more efficient tokens_match_ord based on token_kind_index;
wenzelm
parents: 67554
diff changeset
   183
  let val is = apply2 index_of_token toks in
c550e38dd131 more efficient tokens_match_ord based on token_kind_index;
wenzelm
parents: 67554
diff changeset
   184
    (case int_ord is of
c550e38dd131 more efficient tokens_match_ord based on token_kind_index;
wenzelm
parents: 67554
diff changeset
   185
      EQUAL => if #1 is = literal_index then fast_string_ord (apply2 str_of_token toks) else EQUAL
c550e38dd131 more efficient tokens_match_ord based on token_kind_index;
wenzelm
parents: 67554
diff changeset
   186
    | ord => ord)
c550e38dd131 more efficient tokens_match_ord based on token_kind_index;
wenzelm
parents: 67554
diff changeset
   187
  end;
67550
3b666615e3ce explicit dummy token;
wenzelm
parents: 67549
diff changeset
   188
27800
df444ddeff56 datatype token: maintain range, tuned representation;
wenzelm
parents: 27773
diff changeset
   189
df444ddeff56 datatype token: maintain range, tuned representation;
wenzelm
parents: 27773
diff changeset
   190
(* stopper *)
df444ddeff56 datatype token: maintain range, tuned representation;
wenzelm
parents: 27773
diff changeset
   191
67555
c550e38dd131 more efficient tokens_match_ord based on token_kind_index;
wenzelm
parents: 67554
diff changeset
   192
val eof_index = token_kind_index EOF;
c550e38dd131 more efficient tokens_match_ord based on token_kind_index;
wenzelm
parents: 67554
diff changeset
   193
fun mk_eof pos = Token (eof_index, "", (pos, Position.none));
27800
df444ddeff56 datatype token: maintain range, tuned representation;
wenzelm
parents: 27773
diff changeset
   194
val eof = mk_eof Position.none;
df444ddeff56 datatype token: maintain range, tuned representation;
wenzelm
parents: 27773
diff changeset
   195
67555
c550e38dd131 more efficient tokens_match_ord based on token_kind_index;
wenzelm
parents: 67554
diff changeset
   196
fun is_eof tok = index_of_token tok = eof_index;
27800
df444ddeff56 datatype token: maintain range, tuned representation;
wenzelm
parents: 27773
diff changeset
   197
val stopper = Scan.stopper (K eof) is_eof;
df444ddeff56 datatype token: maintain range, tuned representation;
wenzelm
parents: 27773
diff changeset
   198
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   199
67556
wenzelm
parents: 67555
diff changeset
   200
(* terminal symbols *)
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   201
67556
wenzelm
parents: 67555
diff changeset
   202
val terminal_symbols =
wenzelm
parents: 67555
diff changeset
   203
  [("id", Ident),
wenzelm
parents: 67555
diff changeset
   204
   ("longid", Long_Ident),
wenzelm
parents: 67555
diff changeset
   205
   ("var", Var),
wenzelm
parents: 67555
diff changeset
   206
   ("tid", Type_Ident),
wenzelm
parents: 67555
diff changeset
   207
   ("tvar", Type_Var),
wenzelm
parents: 67555
diff changeset
   208
   ("num_token", Num),
wenzelm
parents: 67555
diff changeset
   209
   ("float_token", Float),
wenzelm
parents: 67555
diff changeset
   210
   ("str_token", Str),
wenzelm
parents: 67555
diff changeset
   211
   ("string_token", String),
wenzelm
parents: 67555
diff changeset
   212
   ("cartouche", Cartouche)]
wenzelm
parents: 67555
diff changeset
   213
  |> map (apsnd token_kind_index)
wenzelm
parents: 67555
diff changeset
   214
  |> Symtab.make;
29156
89f76a58a378 renamed terminal category "float" to "float_token", to avoid name
wenzelm
parents: 28904
diff changeset
   215
67556
wenzelm
parents: 67555
diff changeset
   216
val terminals = Symtab.keys terminal_symbols;
wenzelm
parents: 67555
diff changeset
   217
val is_terminal = Symtab.defined terminal_symbols;
wenzelm
parents: 67555
diff changeset
   218
fun get_terminal s =
wenzelm
parents: 67555
diff changeset
   219
  (case Symtab.lookup terminal_symbols s of
wenzelm
parents: 67555
diff changeset
   220
    SOME i => SOME (Token (i, s, Position.no_range))
wenzelm
parents: 67555
diff changeset
   221
  | NONE => NONE);
237
a7d3e712767a MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
wenzelm
parents: 164
diff changeset
   222
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   223
27887
9f3fd48cf673 token_kind: add Space, Comment;
wenzelm
parents: 27806
diff changeset
   224
(* markup *)
9f3fd48cf673 token_kind: add Space, Comment;
wenzelm
parents: 27806
diff changeset
   225
49821
d15fe10593ff clarified output token markup (see also bc22daeed49e);
wenzelm
parents: 48992
diff changeset
   226
fun literal_markup s =
73163
624c2b98860a suppress markup for literal tokens with block control symbols, for better PIDE/HTML output (see also d15fe10593ff);
wenzelm
parents: 70586
diff changeset
   227
  let val syms = Symbol.explode s in
73198
a9eaf8c3b728 tuned signature (e.g. see HTML.control_block in Isabelle/Scala);
wenzelm
parents: 73163
diff changeset
   228
    if Symbol.has_control_block syms then []
73163
624c2b98860a suppress markup for literal tokens with block control symbols, for better PIDE/HTML output (see also d15fe10593ff);
wenzelm
parents: 70586
diff changeset
   229
    else if Symbol.is_ascii_identifier s orelse exists Symbol.is_letter syms
624c2b98860a suppress markup for literal tokens with block control symbols, for better PIDE/HTML output (see also d15fe10593ff);
wenzelm
parents: 70586
diff changeset
   230
    then [Markup.literal]
624c2b98860a suppress markup for literal tokens with block control symbols, for better PIDE/HTML output (see also d15fe10593ff);
wenzelm
parents: 70586
diff changeset
   231
    else [Markup.delimiter]
624c2b98860a suppress markup for literal tokens with block control symbols, for better PIDE/HTML output (see also d15fe10593ff);
wenzelm
parents: 70586
diff changeset
   232
  end;
49821
d15fe10593ff clarified output token markup (see also bc22daeed49e);
wenzelm
parents: 48992
diff changeset
   233
27887
9f3fd48cf673 token_kind: add Space, Comment;
wenzelm
parents: 27806
diff changeset
   234
val token_kind_markup =
73163
624c2b98860a suppress markup for literal tokens with block control symbols, for better PIDE/HTML output (see also d15fe10593ff);
wenzelm
parents: 70586
diff changeset
   235
 fn Type_Ident => [Markup.tfree]
624c2b98860a suppress markup for literal tokens with block control symbols, for better PIDE/HTML output (see also d15fe10593ff);
wenzelm
parents: 70586
diff changeset
   236
  | Type_Var => [Markup.tvar]
624c2b98860a suppress markup for literal tokens with block control symbols, for better PIDE/HTML output (see also d15fe10593ff);
wenzelm
parents: 70586
diff changeset
   237
  | Num => [Markup.numeral]
624c2b98860a suppress markup for literal tokens with block control symbols, for better PIDE/HTML output (see also d15fe10593ff);
wenzelm
parents: 70586
diff changeset
   238
  | Float => [Markup.numeral]
624c2b98860a suppress markup for literal tokens with block control symbols, for better PIDE/HTML output (see also d15fe10593ff);
wenzelm
parents: 70586
diff changeset
   239
  | Str => [Markup.inner_string]
624c2b98860a suppress markup for literal tokens with block control symbols, for better PIDE/HTML output (see also d15fe10593ff);
wenzelm
parents: 70586
diff changeset
   240
  | String => [Markup.inner_string]
624c2b98860a suppress markup for literal tokens with block control symbols, for better PIDE/HTML output (see also d15fe10593ff);
wenzelm
parents: 70586
diff changeset
   241
  | Cartouche => [Markup.inner_cartouche]
624c2b98860a suppress markup for literal tokens with block control symbols, for better PIDE/HTML output (see also d15fe10593ff);
wenzelm
parents: 70586
diff changeset
   242
  | Comment _ => [Markup.comment1]
624c2b98860a suppress markup for literal tokens with block control symbols, for better PIDE/HTML output (see also d15fe10593ff);
wenzelm
parents: 70586
diff changeset
   243
  | _ => [];
27887
9f3fd48cf673 token_kind: add Space, Comment;
wenzelm
parents: 27806
diff changeset
   244
73163
624c2b98860a suppress markup for literal tokens with block control symbols, for better PIDE/HTML output (see also d15fe10593ff);
wenzelm
parents: 70586
diff changeset
   245
fun reports_of_token tok =
67555
c550e38dd131 more efficient tokens_match_ord based on token_kind_index;
wenzelm
parents: 67554
diff changeset
   246
  let
73163
624c2b98860a suppress markup for literal tokens with block control symbols, for better PIDE/HTML output (see also d15fe10593ff);
wenzelm
parents: 70586
diff changeset
   247
    val pos = pos_of_token tok;
624c2b98860a suppress markup for literal tokens with block control symbols, for better PIDE/HTML output (see also d15fe10593ff);
wenzelm
parents: 70586
diff changeset
   248
    val markups =
67555
c550e38dd131 more efficient tokens_match_ord based on token_kind_index;
wenzelm
parents: 67554
diff changeset
   249
      if is_literal tok then literal_markup (str_of_token tok)
c550e38dd131 more efficient tokens_match_ord based on token_kind_index;
wenzelm
parents: 67554
diff changeset
   250
      else token_kind_markup (kind_of_token tok);
73163
624c2b98860a suppress markup for literal tokens with block control symbols, for better PIDE/HTML output (see also d15fe10593ff);
wenzelm
parents: 70586
diff changeset
   251
  in map (pair pos) markups end;
27887
9f3fd48cf673 token_kind: add Space, Comment;
wenzelm
parents: 27806
diff changeset
   252
39510
d9f5f01faa1b Syntax.read_asts error: report token ranges within message -- no side-effect here;
wenzelm
parents: 39507
diff changeset
   253
fun reported_token_range ctxt tok =
39168
e3ac771235f7 report token range after inner parse error -- often provides important clues about misunderstanding concerning lexical phase;
wenzelm
parents: 38474
diff changeset
   254
  if is_proper tok
50201
c26369c9eda6 Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
wenzelm
parents: 49821
diff changeset
   255
  then Context_Position.reported_text ctxt (pos_of_token tok) Markup.token_range ""
39510
d9f5f01faa1b Syntax.read_asts error: report token ranges within message -- no side-effect here;
wenzelm
parents: 39507
diff changeset
   256
  else "";
39168
e3ac771235f7 report token range after inner parse error -- often provides important clues about misunderstanding concerning lexical phase;
wenzelm
parents: 38474
diff changeset
   257
27887
9f3fd48cf673 token_kind: add Space, Comment;
wenzelm
parents: 27806
diff changeset
   258
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   259
(* valued_token *)
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   260
67555
c550e38dd131 more efficient tokens_match_ord based on token_kind_index;
wenzelm
parents: 67554
diff changeset
   261
fun valued_token tok =
c550e38dd131 more efficient tokens_match_ord based on token_kind_index;
wenzelm
parents: 67554
diff changeset
   262
  not (is_literal tok orelse is_eof tok);
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   263
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   264
55108
0b7a0c1fdf7e inner syntax token language allows regular quoted strings;
wenzelm
parents: 55107
diff changeset
   265
0b7a0c1fdf7e inner syntax token language allows regular quoted strings;
wenzelm
parents: 55107
diff changeset
   266
(** string literals **)
0b7a0c1fdf7e inner syntax token language allows regular quoted strings;
wenzelm
parents: 55107
diff changeset
   267
0b7a0c1fdf7e inner syntax token language allows regular quoted strings;
wenzelm
parents: 55107
diff changeset
   268
fun explode_literal scan_body (str, pos) =
0b7a0c1fdf7e inner syntax token language allows regular quoted strings;
wenzelm
parents: 55107
diff changeset
   269
  (case Scan.read Symbol_Pos.stopper scan_body (Symbol_Pos.explode (str, pos)) of
0b7a0c1fdf7e inner syntax token language allows regular quoted strings;
wenzelm
parents: 55107
diff changeset
   270
    SOME ss => ss
0b7a0c1fdf7e inner syntax token language allows regular quoted strings;
wenzelm
parents: 55107
diff changeset
   271
  | _ => error (err_prefix ^ "malformed string literal " ^ quote str ^ Position.here pos));
0b7a0c1fdf7e inner syntax token language allows regular quoted strings;
wenzelm
parents: 55107
diff changeset
   272
0b7a0c1fdf7e inner syntax token language allows regular quoted strings;
wenzelm
parents: 55107
diff changeset
   273
0b7a0c1fdf7e inner syntax token language allows regular quoted strings;
wenzelm
parents: 55107
diff changeset
   274
(* string *)
0b7a0c1fdf7e inner syntax token language allows regular quoted strings;
wenzelm
parents: 55107
diff changeset
   275
0b7a0c1fdf7e inner syntax token language allows regular quoted strings;
wenzelm
parents: 55107
diff changeset
   276
val scan_string = Scan.trace (Symbol_Pos.scan_string_qq err_prefix) >> #2;
0b7a0c1fdf7e inner syntax token language allows regular quoted strings;
wenzelm
parents: 55107
diff changeset
   277
val scan_string_body = Symbol_Pos.scan_string_qq err_prefix >> (#1 o #2);
0b7a0c1fdf7e inner syntax token language allows regular quoted strings;
wenzelm
parents: 55107
diff changeset
   278
0b7a0c1fdf7e inner syntax token language allows regular quoted strings;
wenzelm
parents: 55107
diff changeset
   279
fun implode_string ss = quote (implode (map (fn "\"" => "\\\"" | s => s) ss));
0b7a0c1fdf7e inner syntax token language allows regular quoted strings;
wenzelm
parents: 55107
diff changeset
   280
val explode_string = explode_literal scan_string_body;
0b7a0c1fdf7e inner syntax token language allows regular quoted strings;
wenzelm
parents: 55107
diff changeset
   281
0b7a0c1fdf7e inner syntax token language allows regular quoted strings;
wenzelm
parents: 55107
diff changeset
   282
0b7a0c1fdf7e inner syntax token language allows regular quoted strings;
wenzelm
parents: 55107
diff changeset
   283
(* str *)
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   284
14730
59ab60c6fcc6 support nested comments;
wenzelm
parents: 14679
diff changeset
   285
val scan_chr =
55107
1a29ea173bf9 tuned signature;
wenzelm
parents: 55106
diff changeset
   286
  $$ "\\" |-- $$$ "'" ||
40525
14a2e686bdac eliminated slightly odd pervasive Symbol_Pos.symbol;
wenzelm
parents: 40290
diff changeset
   287
  Scan.one
58854
b979c781c2db discontinued obsolete \<^sync> marker;
wenzelm
parents: 58421
diff changeset
   288
    ((fn s => s <> "\\" andalso s <> "'" andalso Symbol.not_eof s) o
40525
14a2e686bdac eliminated slightly odd pervasive Symbol_Pos.symbol;
wenzelm
parents: 40290
diff changeset
   289
      Symbol_Pos.symbol) >> single ||
55107
1a29ea173bf9 tuned signature;
wenzelm
parents: 55106
diff changeset
   290
  $$$ "'" --| Scan.ahead (~$$ "'");
14730
59ab60c6fcc6 support nested comments;
wenzelm
parents: 14679
diff changeset
   291
59ab60c6fcc6 support nested comments;
wenzelm
parents: 14679
diff changeset
   292
val scan_str =
55106
080c0006e917 tuned error messages, more accurate position;
wenzelm
parents: 55105
diff changeset
   293
  Scan.ahead ($$ "'" -- $$ "'") |--
080c0006e917 tuned error messages, more accurate position;
wenzelm
parents: 55105
diff changeset
   294
    !!! "unclosed string literal"
61476
1884c40f1539 tuned signature;
wenzelm
parents: 59196
diff changeset
   295
      ($$$ "'" @@@ $$$ "'" @@@ Scan.repeats scan_chr @@@ $$$ "'" @@@ $$$ "'");
27800
df444ddeff56 datatype token: maintain range, tuned representation;
wenzelm
parents: 27773
diff changeset
   296
df444ddeff56 datatype token: maintain range, tuned representation;
wenzelm
parents: 27773
diff changeset
   297
val scan_str_body =
55107
1a29ea173bf9 tuned signature;
wenzelm
parents: 55106
diff changeset
   298
  Scan.ahead ($$ "'" |-- $$ "'") |--
55106
080c0006e917 tuned error messages, more accurate position;
wenzelm
parents: 55105
diff changeset
   299
    !!! "unclosed string literal"
61476
1884c40f1539 tuned signature;
wenzelm
parents: 59196
diff changeset
   300
      ($$ "'" |-- $$ "'" |-- Scan.repeats scan_chr --| $$ "'" --| $$ "'");
14730
59ab60c6fcc6 support nested comments;
wenzelm
parents: 14679
diff changeset
   301
55108
0b7a0c1fdf7e inner syntax token language allows regular quoted strings;
wenzelm
parents: 55107
diff changeset
   302
fun implode_str ss = enclose "''" "''" (implode (map (fn "'" => "\\'" | s => s) ss));
0b7a0c1fdf7e inner syntax token language allows regular quoted strings;
wenzelm
parents: 55107
diff changeset
   303
val explode_str = explode_literal scan_str_body;
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   304
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   305
27806
ece79c0597fe pos_of_token: Position.T;
wenzelm
parents: 27800
diff changeset
   306
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   307
(** tokenize **)
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   308
67412
wenzelm
parents: 67388
diff changeset
   309
val token_leq = op <= o apply2 str_of_token;
67555
c550e38dd131 more efficient tokens_match_ord based on token_kind_index;
wenzelm
parents: 67554
diff changeset
   310
c550e38dd131 more efficient tokens_match_ord based on token_kind_index;
wenzelm
parents: 67554
diff changeset
   311
fun token kind =
c550e38dd131 more efficient tokens_match_ord based on token_kind_index;
wenzelm
parents: 67554
diff changeset
   312
  let val i = token_kind_index kind
c550e38dd131 more efficient tokens_match_ord based on token_kind_index;
wenzelm
parents: 67554
diff changeset
   313
  in fn ss => Token (i, Symbol_Pos.content ss, Symbol_Pos.range ss) end;
27800
df444ddeff56 datatype token: maintain range, tuned representation;
wenzelm
parents: 27773
diff changeset
   314
df444ddeff56 datatype token: maintain range, tuned representation;
wenzelm
parents: 27773
diff changeset
   315
fun tokenize lex xids syms =
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   316
  let
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   317
    val scan_xid =
55962
fbd0e768bc8f special identifier "__" (i.e. empty name with internal suffix) serves as wild-card for completion;
wenzelm
parents: 55624
diff changeset
   318
      (if xids then $$$ "_" @@@ scan_id || scan_id else scan_id) ||
fbd0e768bc8f special identifier "__" (i.e. empty name with internal suffix) serves as wild-card for completion;
wenzelm
parents: 55624
diff changeset
   319
      $$$ "_" @@@ $$$ "_";
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   320
550
353eea6ec232 replaced id, var, tid, tvar by idT, varT, tidT, tvarT;
wenzelm
parents: 376
diff changeset
   321
    val scan_val =
67548
c0f1667c1943 clarified signature;
wenzelm
parents: 67539
diff changeset
   322
      scan_tvar >> token Type_Var ||
c0f1667c1943 clarified signature;
wenzelm
parents: 67539
diff changeset
   323
      scan_var >> token Var ||
c0f1667c1943 clarified signature;
wenzelm
parents: 67539
diff changeset
   324
      scan_tid >> token Type_Ident ||
c0f1667c1943 clarified signature;
wenzelm
parents: 67539
diff changeset
   325
      Symbol_Pos.scan_float >> token Float ||
c0f1667c1943 clarified signature;
wenzelm
parents: 67539
diff changeset
   326
      scan_num >> token Num ||
c0f1667c1943 clarified signature;
wenzelm
parents: 67539
diff changeset
   327
      scan_longid >> token Long_Ident ||
c0f1667c1943 clarified signature;
wenzelm
parents: 67539
diff changeset
   328
      scan_xid >> token Ident;
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   329
27800
df444ddeff56 datatype token: maintain range, tuned representation;
wenzelm
parents: 27773
diff changeset
   330
    val scan_lit = Scan.literal lex >> token Literal;
550
353eea6ec232 replaced id, var, tid, tvar by idT, varT, tidT, tvarT;
wenzelm
parents: 376
diff changeset
   331
67555
c550e38dd131 more efficient tokens_match_ord based on token_kind_index;
wenzelm
parents: 67554
diff changeset
   332
    val scan =
55105
75815b3b38a1 tuned -- more direct err_prefix;
wenzelm
parents: 55035
diff changeset
   333
      Symbol_Pos.scan_cartouche err_prefix >> token Cartouche ||
69891
def3ec9cdb7e document markers are formal comments, and may thus occur anywhere in the command-span;
wenzelm
parents: 69344
diff changeset
   334
      Comment.scan_inner >> (fn (kind, ss) => token (Comment kind) ss) ||
27887
9f3fd48cf673 token_kind: add Space, Comment;
wenzelm
parents: 27806
diff changeset
   335
      Scan.max token_leq scan_lit scan_val ||
67548
c0f1667c1943 clarified signature;
wenzelm
parents: 67539
diff changeset
   336
      scan_string >> token String ||
c0f1667c1943 clarified signature;
wenzelm
parents: 67539
diff changeset
   337
      scan_str >> token Str ||
40525
14a2e686bdac eliminated slightly odd pervasive Symbol_Pos.symbol;
wenzelm
parents: 40290
diff changeset
   338
      Scan.many1 (Symbol.is_blank o Symbol_Pos.symbol) >> token Space;
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   339
  in
67555
c550e38dd131 more efficient tokens_match_ord based on token_kind_index;
wenzelm
parents: 67554
diff changeset
   340
    (case Scan.error (Scan.finite Symbol_Pos.stopper (Scan.repeat scan)) syms of
27887
9f3fd48cf673 token_kind: add Space, Comment;
wenzelm
parents: 27806
diff changeset
   341
      (toks, []) => toks
55108
0b7a0c1fdf7e inner syntax token language allows regular quoted strings;
wenzelm
parents: 55107
diff changeset
   342
    | (_, ss) =>
55624
d52409077135 tuned messages;
wenzelm
parents: 55108
diff changeset
   343
        error ("Inner lexical error" ^ Position.here (#1 (Symbol_Pos.range ss)) ^
d52409077135 tuned messages;
wenzelm
parents: 55108
diff changeset
   344
          Markup.markup Markup.no_report ("\nat " ^ quote (Symbol_Pos.content ss))))
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   345
  end;
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   346
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   347
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   348
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   349
(** scan variables **)
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   350
15991
670f8e4b5a98 added read_variable: optional question mark on input;
wenzelm
parents: 15965
diff changeset
   351
(* scan_indexname *)
670f8e4b5a98 added read_variable: optional question mark on input;
wenzelm
parents: 15965
diff changeset
   352
670f8e4b5a98 added read_variable: optional question mark on input;
wenzelm
parents: 15965
diff changeset
   353
local
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   354
27773
a52166b228b9 improved position handling due to SymbolPos.T;
wenzelm
parents: 27121
diff changeset
   355
val scan_vname =
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   356
  let
15991
670f8e4b5a98 added read_variable: optional question mark on input;
wenzelm
parents: 15965
diff changeset
   357
    fun nat n [] = n
64275
ac2abc987cf9 accomodate Poly/ML repository version, which treats singleton strings as boxed;
wenzelm
parents: 62819
diff changeset
   358
      | nat n (c :: cs) = nat (n * 10 + (ord c - Char.ord #"0")) cs;
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   359
15991
670f8e4b5a98 added read_variable: optional question mark on input;
wenzelm
parents: 15965
diff changeset
   360
    fun idxname cs ds = (implode (rev cs), nat 0 ds);
670f8e4b5a98 added read_variable: optional question mark on input;
wenzelm
parents: 15965
diff changeset
   361
    fun chop_idx [] ds = idxname [] ds
62529
8b7bdfc09f3b clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents: 61476
diff changeset
   362
      | chop_idx (cs as (_ :: "\<^sub>" :: _)) ds = idxname cs ds
15991
670f8e4b5a98 added read_variable: optional question mark on input;
wenzelm
parents: 15965
diff changeset
   363
      | chop_idx (c :: cs) ds =
670f8e4b5a98 added read_variable: optional question mark on input;
wenzelm
parents: 15965
diff changeset
   364
          if Symbol.is_digit c then chop_idx cs (c :: ds)
670f8e4b5a98 added read_variable: optional question mark on input;
wenzelm
parents: 15965
diff changeset
   365
          else idxname (c :: cs) ds;
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   366
50239
fb579401dc26 tuned signature;
wenzelm
parents: 50238
diff changeset
   367
    val scan =
fb579401dc26 tuned signature;
wenzelm
parents: 50238
diff changeset
   368
      (scan_id >> map Symbol_Pos.symbol) --
62782
057e8dbe4326 clarified modules;
wenzelm
parents: 62751
diff changeset
   369
      Scan.optional ($$ "." |-- Symbol_Pos.scan_nat >> (nat 0 o map Symbol_Pos.symbol)) ~1;
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   370
  in
27773
a52166b228b9 improved position handling due to SymbolPos.T;
wenzelm
parents: 27121
diff changeset
   371
    scan >>
a52166b228b9 improved position handling due to SymbolPos.T;
wenzelm
parents: 27121
diff changeset
   372
      (fn (cs, ~1) => chop_idx (rev cs) []
a52166b228b9 improved position handling due to SymbolPos.T;
wenzelm
parents: 27121
diff changeset
   373
        | (cs, i) => (implode cs, i))
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   374
  end;
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   375
15991
670f8e4b5a98 added read_variable: optional question mark on input;
wenzelm
parents: 15965
diff changeset
   376
in
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   377
55107
1a29ea173bf9 tuned signature;
wenzelm
parents: 55106
diff changeset
   378
val scan_indexname = $$ "'" |-- scan_vname >> (fn (x, i) => ("'" ^ x, i)) || scan_vname;
15443
07f78cc82a73 indexname function now parses type variables as well; changed input
berghofe
parents: 14981
diff changeset
   379
15991
670f8e4b5a98 added read_variable: optional question mark on input;
wenzelm
parents: 15965
diff changeset
   380
end;
670f8e4b5a98 added read_variable: optional question mark on input;
wenzelm
parents: 15965
diff changeset
   381
670f8e4b5a98 added read_variable: optional question mark on input;
wenzelm
parents: 15965
diff changeset
   382
670f8e4b5a98 added read_variable: optional question mark on input;
wenzelm
parents: 15965
diff changeset
   383
(* indexname *)
670f8e4b5a98 added read_variable: optional question mark on input;
wenzelm
parents: 15965
diff changeset
   384
20313
bf9101cc4385 renamed Syntax.indexname to Syntax.read_indexname;
wenzelm
parents: 20165
diff changeset
   385
fun read_indexname s =
62751
24e2b098bf44 tuned signature;
wenzelm
parents: 62663
diff changeset
   386
  (case Scan.read Symbol_Pos.stopper scan_indexname (Symbol_Pos.explode0 s) of
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15443
diff changeset
   387
    SOME xi => xi
20313
bf9101cc4385 renamed Syntax.indexname to Syntax.read_indexname;
wenzelm
parents: 20165
diff changeset
   388
  | _ => error ("Lexical error in variable name: " ^ quote s));
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   389
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   390
4703
a50ab39756db adapted to symbols, scan;
wenzelm
parents: 4587
diff changeset
   391
(* read_var *)
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   392
4703
a50ab39756db adapted to symbols, scan;
wenzelm
parents: 4587
diff changeset
   393
fun read_var str =
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   394
  let
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   395
    val scan =
55107
1a29ea173bf9 tuned signature;
wenzelm
parents: 55106
diff changeset
   396
      $$ "?" |-- scan_indexname --| Scan.ahead (Scan.one Symbol_Pos.is_eof)
42476
d0bc1268ef09 clarified auxiliary structure Lexicon.Syntax;
wenzelm
parents: 42290
diff changeset
   397
        >> Syntax.var ||
58854
b979c781c2db discontinued obsolete \<^sync> marker;
wenzelm
parents: 58421
diff changeset
   398
      Scan.many (Symbol.not_eof o Symbol_Pos.symbol)
42476
d0bc1268ef09 clarified auxiliary structure Lexicon.Syntax;
wenzelm
parents: 42290
diff changeset
   399
        >> (Syntax.free o implode o map Symbol_Pos.symbol);
62751
24e2b098bf44 tuned signature;
wenzelm
parents: 62663
diff changeset
   400
  in the (Scan.read Symbol_Pos.stopper scan (Symbol_Pos.explode0 str)) end;
15991
670f8e4b5a98 added read_variable: optional question mark on input;
wenzelm
parents: 15965
diff changeset
   401
670f8e4b5a98 added read_variable: optional question mark on input;
wenzelm
parents: 15965
diff changeset
   402
670f8e4b5a98 added read_variable: optional question mark on input;
wenzelm
parents: 15965
diff changeset
   403
(* read_variable *)
670f8e4b5a98 added read_variable: optional question mark on input;
wenzelm
parents: 15965
diff changeset
   404
670f8e4b5a98 added read_variable: optional question mark on input;
wenzelm
parents: 15965
diff changeset
   405
fun read_variable str =
55107
1a29ea173bf9 tuned signature;
wenzelm
parents: 55106
diff changeset
   406
  let val scan = $$ "?" |-- scan_indexname || scan_indexname
62751
24e2b098bf44 tuned signature;
wenzelm
parents: 62663
diff changeset
   407
  in Scan.read Symbol_Pos.stopper scan (Symbol_Pos.explode0 str) end;
4587
6bce9ef27d7e added read_var;
wenzelm
parents: 4247
diff changeset
   408
6bce9ef27d7e added read_var;
wenzelm
parents: 4247
diff changeset
   409
20313
bf9101cc4385 renamed Syntax.indexname to Syntax.read_indexname;
wenzelm
parents: 20165
diff changeset
   410
(* read numbers *)
bf9101cc4385 renamed Syntax.indexname to Syntax.read_indexname;
wenzelm
parents: 20165
diff changeset
   411
bf9101cc4385 renamed Syntax.indexname to Syntax.read_indexname;
wenzelm
parents: 20165
diff changeset
   412
local
bf9101cc4385 renamed Syntax.indexname to Syntax.read_indexname;
wenzelm
parents: 20165
diff changeset
   413
bf9101cc4385 renamed Syntax.indexname to Syntax.read_indexname;
wenzelm
parents: 20165
diff changeset
   414
fun nat cs =
40525
14a2e686bdac eliminated slightly odd pervasive Symbol_Pos.symbol;
wenzelm
parents: 40290
diff changeset
   415
  Option.map (#1 o Library.read_int o map Symbol_Pos.symbol)
62782
057e8dbe4326 clarified modules;
wenzelm
parents: 62751
diff changeset
   416
    (Scan.read Symbol_Pos.stopper Symbol_Pos.scan_nat cs);
5860
ed11c9890852 added read_nat;
wenzelm
parents: 5513
diff changeset
   417
20313
bf9101cc4385 renamed Syntax.indexname to Syntax.read_indexname;
wenzelm
parents: 20165
diff changeset
   418
in
bf9101cc4385 renamed Syntax.indexname to Syntax.read_indexname;
wenzelm
parents: 20165
diff changeset
   419
62751
24e2b098bf44 tuned signature;
wenzelm
parents: 62663
diff changeset
   420
fun read_nat s = nat (Symbol_Pos.explode0 s);
20313
bf9101cc4385 renamed Syntax.indexname to Syntax.read_indexname;
wenzelm
parents: 20165
diff changeset
   421
bf9101cc4385 renamed Syntax.indexname to Syntax.read_indexname;
wenzelm
parents: 20165
diff changeset
   422
fun read_int s =
62751
24e2b098bf44 tuned signature;
wenzelm
parents: 62663
diff changeset
   423
  (case Symbol_Pos.explode0 s of
27773
a52166b228b9 improved position handling due to SymbolPos.T;
wenzelm
parents: 27121
diff changeset
   424
    ("-", _) :: cs => Option.map ~ (nat cs)
20313
bf9101cc4385 renamed Syntax.indexname to Syntax.read_indexname;
wenzelm
parents: 20165
diff changeset
   425
  | cs => nat cs);
bf9101cc4385 renamed Syntax.indexname to Syntax.read_indexname;
wenzelm
parents: 20165
diff changeset
   426
bf9101cc4385 renamed Syntax.indexname to Syntax.read_indexname;
wenzelm
parents: 20165
diff changeset
   427
end;
5860
ed11c9890852 added read_nat;
wenzelm
parents: 5513
diff changeset
   428
ed11c9890852 added read_nat;
wenzelm
parents: 5513
diff changeset
   429
58421
37cbbd8eb460 discontinued old "xnum" token category;
wenzelm
parents: 58410
diff changeset
   430
(* read_num: hex/bin/decimal *)
9326
1625c1f172b3 added read_xnum;
wenzelm
parents: 9289
diff changeset
   431
15991
670f8e4b5a98 added read_variable: optional question mark on input;
wenzelm
parents: 15965
diff changeset
   432
local
670f8e4b5a98 added read_variable: optional question mark on input;
wenzelm
parents: 15965
diff changeset
   433
64275
ac2abc987cf9 accomodate Poly/ML repository version, which treats singleton strings as boxed;
wenzelm
parents: 62819
diff changeset
   434
val ten = Char.ord #"0" + 10;
ac2abc987cf9 accomodate Poly/ML repository version, which treats singleton strings as boxed;
wenzelm
parents: 62819
diff changeset
   435
val a = Char.ord #"a";
ac2abc987cf9 accomodate Poly/ML repository version, which treats singleton strings as boxed;
wenzelm
parents: 62819
diff changeset
   436
val A = Char.ord #"A";
35428
bd7d6f65976e more systematic mark/unmark operations;
wenzelm
parents: 35262
diff changeset
   437
val _ = a > A orelse raise Fail "Bad ASCII";
20096
7058714024b3 uniform treatment of num/xnum;
wenzelm
parents: 20091
diff changeset
   438
7058714024b3 uniform treatment of num/xnum;
wenzelm
parents: 20091
diff changeset
   439
fun remap_hex c =
7058714024b3 uniform treatment of num/xnum;
wenzelm
parents: 20091
diff changeset
   440
  let val x = ord c in
7058714024b3 uniform treatment of num/xnum;
wenzelm
parents: 20091
diff changeset
   441
    if x >= a then chr (x - a + ten)
7058714024b3 uniform treatment of num/xnum;
wenzelm
parents: 20091
diff changeset
   442
    else if x >= A then chr (x - A + ten)
7058714024b3 uniform treatment of num/xnum;
wenzelm
parents: 20091
diff changeset
   443
    else c
7058714024b3 uniform treatment of num/xnum;
wenzelm
parents: 20091
diff changeset
   444
  end;
15991
670f8e4b5a98 added read_variable: optional question mark on input;
wenzelm
parents: 15965
diff changeset
   445
21781
8314ebb5364d read_xnum: return leading_zeros, radix;
wenzelm
parents: 21774
diff changeset
   446
fun leading_zeros ["0"] = 0
8314ebb5364d read_xnum: return leading_zeros, radix;
wenzelm
parents: 21774
diff changeset
   447
  | leading_zeros ("0" :: cs) = 1 + leading_zeros cs
8314ebb5364d read_xnum: return leading_zeros, radix;
wenzelm
parents: 21774
diff changeset
   448
  | leading_zeros _ = 0;
8314ebb5364d read_xnum: return leading_zeros, radix;
wenzelm
parents: 21774
diff changeset
   449
15991
670f8e4b5a98 added read_variable: optional question mark on input;
wenzelm
parents: 15965
diff changeset
   450
in
15965
f422f8283491 Use of IntInf.int instead of int in most numeric simprocs; avoids
paulson
parents: 15570
diff changeset
   451
58421
37cbbd8eb460 discontinued old "xnum" token category;
wenzelm
parents: 58410
diff changeset
   452
fun read_num str =
9326
1625c1f172b3 added read_xnum;
wenzelm
parents: 9289
diff changeset
   453
  let
58421
37cbbd8eb460 discontinued old "xnum" token category;
wenzelm
parents: 58410
diff changeset
   454
    val (radix, digs) =
37cbbd8eb460 discontinued old "xnum" token category;
wenzelm
parents: 58410
diff changeset
   455
      (case Symbol.explode str of
37cbbd8eb460 discontinued old "xnum" token category;
wenzelm
parents: 58410
diff changeset
   456
        "0" :: "x" :: cs => (16, map remap_hex cs)
37cbbd8eb460 discontinued old "xnum" token category;
wenzelm
parents: 58410
diff changeset
   457
      | "0" :: "b" :: cs => (2, cs)
37cbbd8eb460 discontinued old "xnum" token category;
wenzelm
parents: 58410
diff changeset
   458
      | cs => (10, cs));
29156
89f76a58a378 renamed terminal category "float" to "float_token", to avoid name
wenzelm
parents: 28904
diff changeset
   459
  in
89f76a58a378 renamed terminal category "float" to "float_token", to avoid name
wenzelm
parents: 28904
diff changeset
   460
   {radix = radix,
89f76a58a378 renamed terminal category "float" to "float_token", to avoid name
wenzelm
parents: 28904
diff changeset
   461
    leading_zeros = leading_zeros digs,
58421
37cbbd8eb460 discontinued old "xnum" token category;
wenzelm
parents: 58410
diff changeset
   462
    value = #1 (Library.read_radix_int radix digs)}
29156
89f76a58a378 renamed terminal category "float" to "float_token", to avoid name
wenzelm
parents: 28904
diff changeset
   463
  end;
9326
1625c1f172b3 added read_xnum;
wenzelm
parents: 9289
diff changeset
   464
15991
670f8e4b5a98 added read_variable: optional question mark on input;
wenzelm
parents: 15965
diff changeset
   465
end;
670f8e4b5a98 added read_variable: optional question mark on input;
wenzelm
parents: 15965
diff changeset
   466
28904
3ef9489eeef5 New lexical item "float".
nipkow
parents: 28413
diff changeset
   467
fun read_float str =
3ef9489eeef5 New lexical item "float".
nipkow
parents: 28413
diff changeset
   468
  let
58421
37cbbd8eb460 discontinued old "xnum" token category;
wenzelm
parents: 58410
diff changeset
   469
    val cs = Symbol.explode str;
29156
89f76a58a378 renamed terminal category "float" to "float_token", to avoid name
wenzelm
parents: 28904
diff changeset
   470
    val (intpart, fracpart) =
67522
9e712280cc37 clarified take/drop/chop prefix/suffix;
wenzelm
parents: 67440
diff changeset
   471
      (case chop_prefix Symbol.is_digit cs of
29156
89f76a58a378 renamed terminal category "float" to "float_token", to avoid name
wenzelm
parents: 28904
diff changeset
   472
        (intpart, "." :: fracpart) => (intpart, fracpart)
89f76a58a378 renamed terminal category "float" to "float_token", to avoid name
wenzelm
parents: 28904
diff changeset
   473
      | _ => raise Fail "read_float");
89f76a58a378 renamed terminal category "float" to "float_token", to avoid name
wenzelm
parents: 28904
diff changeset
   474
  in
58421
37cbbd8eb460 discontinued old "xnum" token category;
wenzelm
parents: 58410
diff changeset
   475
   {mant = #1 (Library.read_int (intpart @ fracpart)),
29156
89f76a58a378 renamed terminal category "float" to "float_token", to avoid name
wenzelm
parents: 28904
diff changeset
   476
    exp = length fracpart}
42046
6341c23baf10 added Lexicon.encode_position, Lexicon.decode_position;
wenzelm
parents: 40525
diff changeset
   477
  end;
6341c23baf10 added Lexicon.encode_position, Lexicon.decode_position;
wenzelm
parents: 40525
diff changeset
   478
42290
b1f544c84040 discontinued special treatment of structure Lexicon;
wenzelm
parents: 42264
diff changeset
   479
81225
2157039256d3 clarified markers for syntax consts: avoid overlap with logical consts;
wenzelm
parents: 81209
diff changeset
   480
2157039256d3 clarified markers for syntax consts: avoid overlap with logical consts;
wenzelm
parents: 81209
diff changeset
   481
(** marked names **)
42290
b1f544c84040 discontinued special treatment of structure Lexicon;
wenzelm
parents: 42264
diff changeset
   482
81209
20d7631b37d7 more operations;
wenzelm
parents: 81006
diff changeset
   483
fun marker s = (prefix s, unprefix s, String.isPrefix s);
42290
b1f544c84040 discontinued special treatment of structure Lexicon;
wenzelm
parents: 42264
diff changeset
   484
81225
2157039256d3 clarified markers for syntax consts: avoid overlap with logical consts;
wenzelm
parents: 81209
diff changeset
   485
2157039256d3 clarified markers for syntax consts: avoid overlap with logical consts;
wenzelm
parents: 81209
diff changeset
   486
(* syntax consts *)
2157039256d3 clarified markers for syntax consts: avoid overlap with logical consts;
wenzelm
parents: 81209
diff changeset
   487
2157039256d3 clarified markers for syntax consts: avoid overlap with logical consts;
wenzelm
parents: 81209
diff changeset
   488
val (mark_syntax, _, _) = marker "\<^syntax>";
2157039256d3 clarified markers for syntax consts: avoid overlap with logical consts;
wenzelm
parents: 81209
diff changeset
   489
val (mark_binder, _, _) = marker "\<^binder>";
2157039256d3 clarified markers for syntax consts: avoid overlap with logical consts;
wenzelm
parents: 81209
diff changeset
   490
val (mark_indexed, _, _) = marker "\<^indexed>";
2157039256d3 clarified markers for syntax consts: avoid overlap with logical consts;
wenzelm
parents: 81209
diff changeset
   491
2157039256d3 clarified markers for syntax consts: avoid overlap with logical consts;
wenzelm
parents: 81209
diff changeset
   492
2157039256d3 clarified markers for syntax consts: avoid overlap with logical consts;
wenzelm
parents: 81209
diff changeset
   493
(* logical entities *)
2157039256d3 clarified markers for syntax consts: avoid overlap with logical consts;
wenzelm
parents: 81209
diff changeset
   494
81209
20d7631b37d7 more operations;
wenzelm
parents: 81006
diff changeset
   495
val (mark_class, unmark_class, is_class) = marker "\<^class>";
20d7631b37d7 more operations;
wenzelm
parents: 81006
diff changeset
   496
val (mark_type, unmark_type, is_type) = marker "\<^type>";
20d7631b37d7 more operations;
wenzelm
parents: 81006
diff changeset
   497
val (mark_const, unmark_const, is_const) = marker "\<^const>";
20d7631b37d7 more operations;
wenzelm
parents: 81006
diff changeset
   498
val (mark_fixed, unmark_fixed, is_fixed) = marker "\<^fixed>";
42290
b1f544c84040 discontinued special treatment of structure Lexicon;
wenzelm
parents: 42264
diff changeset
   499
b1f544c84040 discontinued special treatment of structure Lexicon;
wenzelm
parents: 42264
diff changeset
   500
fun unmark {case_class, case_type, case_const, case_fixed, case_default} s =
b1f544c84040 discontinued special treatment of structure Lexicon;
wenzelm
parents: 42264
diff changeset
   501
  (case try unmark_class s of
b1f544c84040 discontinued special treatment of structure Lexicon;
wenzelm
parents: 42264
diff changeset
   502
    SOME c => case_class c
b1f544c84040 discontinued special treatment of structure Lexicon;
wenzelm
parents: 42264
diff changeset
   503
  | NONE =>
b1f544c84040 discontinued special treatment of structure Lexicon;
wenzelm
parents: 42264
diff changeset
   504
      (case try unmark_type s of
b1f544c84040 discontinued special treatment of structure Lexicon;
wenzelm
parents: 42264
diff changeset
   505
        SOME c => case_type c
b1f544c84040 discontinued special treatment of structure Lexicon;
wenzelm
parents: 42264
diff changeset
   506
      | NONE =>
b1f544c84040 discontinued special treatment of structure Lexicon;
wenzelm
parents: 42264
diff changeset
   507
          (case try unmark_const s of
b1f544c84040 discontinued special treatment of structure Lexicon;
wenzelm
parents: 42264
diff changeset
   508
            SOME c => case_const c
b1f544c84040 discontinued special treatment of structure Lexicon;
wenzelm
parents: 42264
diff changeset
   509
          | NONE =>
b1f544c84040 discontinued special treatment of structure Lexicon;
wenzelm
parents: 42264
diff changeset
   510
              (case try unmark_fixed s of
b1f544c84040 discontinued special treatment of structure Lexicon;
wenzelm
parents: 42264
diff changeset
   511
                SOME c => case_fixed c
b1f544c84040 discontinued special treatment of structure Lexicon;
wenzelm
parents: 42264
diff changeset
   512
              | NONE => case_default s))));
b1f544c84040 discontinued special treatment of structure Lexicon;
wenzelm
parents: 42264
diff changeset
   513
b1f544c84040 discontinued special treatment of structure Lexicon;
wenzelm
parents: 42264
diff changeset
   514
val is_marked =
b1f544c84040 discontinued special treatment of structure Lexicon;
wenzelm
parents: 42264
diff changeset
   515
  unmark {case_class = K true, case_type = K true, case_const = K true,
b1f544c84040 discontinued special treatment of structure Lexicon;
wenzelm
parents: 42264
diff changeset
   516
    case_fixed = K true, case_default = K false};
b1f544c84040 discontinued special treatment of structure Lexicon;
wenzelm
parents: 42264
diff changeset
   517
42476
d0bc1268ef09 clarified auxiliary structure Lexicon.Syntax;
wenzelm
parents: 42290
diff changeset
   518
val dummy_type = Syntax.const (mark_type "dummy");
d0bc1268ef09 clarified auxiliary structure Lexicon.Syntax;
wenzelm
parents: 42290
diff changeset
   519
val fun_type = Syntax.const (mark_type "fun");
42290
b1f544c84040 discontinued special treatment of structure Lexicon;
wenzelm
parents: 42264
diff changeset
   520
59196
73a6403637b3 more toplevel pretty printing;
wenzelm
parents: 58854
diff changeset
   521
73a6403637b3 more toplevel pretty printing;
wenzelm
parents: 58854
diff changeset
   522
(* toplevel pretty printing *)
73a6403637b3 more toplevel pretty printing;
wenzelm
parents: 58854
diff changeset
   523
62663
bea354f6ff21 clarified modules;
wenzelm
parents: 62529
diff changeset
   524
val _ =
62819
d3ff367a16a0 careful export of type-dependent functions, without losing their special status;
wenzelm
parents: 62782
diff changeset
   525
  ML_system_pp (fn _ => fn _ =>
80809
4a64fc4d1cde clarified signature: type ML_Pretty.pretty coincides with PolyML.pretty;
wenzelm
parents: 77846
diff changeset
   526
    Pretty.to_ML o Pretty.str_list "{" "}" o map quote o Scan.dest_lexicon);
59196
73a6403637b3 more toplevel pretty printing;
wenzelm
parents: 58854
diff changeset
   527
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   528
end;