src/Pure/Syntax/lexicon.ML
author wenzelm
Fri, 05 Oct 2001 21:48:04 +0200
changeset 11697 8dd899efbd35
parent 9326 1625c1f172b3
child 12785 27debaf2112d
permissions -rw-r--r--
added "num" token;
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
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     2
    ID:         $Id$
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
     3
    Author:     Tobias Nipkow and Markus Wenzel, TU Muenchen
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     4
4703
a50ab39756db adapted to symbols, scan;
wenzelm
parents: 4587
diff changeset
     5
Lexer for the inner Isabelle syntax (terms and types).
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
     6
*)
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     7
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     8
signature LEXICON0 =
4247
9bba9251bb4d added implode_xstr: string list -> string, explode_xstr: string -> string list;
wenzelm
parents: 3828
diff changeset
     9
sig
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    10
  val is_identifier: string -> bool
4247
9bba9251bb4d added implode_xstr: string list -> string, explode_xstr: string -> string list;
wenzelm
parents: 3828
diff changeset
    11
  val implode_xstr: string list -> string
9bba9251bb4d added implode_xstr: string list -> string, explode_xstr: string -> string list;
wenzelm
parents: 3828
diff changeset
    12
  val explode_xstr: string -> string list
4703
a50ab39756db adapted to symbols, scan;
wenzelm
parents: 4587
diff changeset
    13
  val scan_id: string list -> string * string list
a50ab39756db adapted to symbols, scan;
wenzelm
parents: 4587
diff changeset
    14
  val scan_longid: string list -> string * string list
a50ab39756db adapted to symbols, scan;
wenzelm
parents: 4587
diff changeset
    15
  val scan_var: string list -> string * string list
a50ab39756db adapted to symbols, scan;
wenzelm
parents: 4587
diff changeset
    16
  val scan_tid: string list -> string * string list
4902
8fbccead3695 added scan_tvar;
wenzelm
parents: 4703
diff changeset
    17
  val scan_tvar: string list -> string * string list
4703
a50ab39756db adapted to symbols, scan;
wenzelm
parents: 4587
diff changeset
    18
  val scan_nat: string list -> string * string list
a50ab39756db adapted to symbols, scan;
wenzelm
parents: 4587
diff changeset
    19
  val scan_int: string list -> string * string list
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
    20
  val string_of_vname: indexname -> string
2583
690835a06cf2 added string_of_vname' (treats neg. index as free);
wenzelm
parents: 2363
diff changeset
    21
  val string_of_vname': indexname -> string
4703
a50ab39756db adapted to symbols, scan;
wenzelm
parents: 4587
diff changeset
    22
  val indexname: string list -> indexname
a50ab39756db adapted to symbols, scan;
wenzelm
parents: 4587
diff changeset
    23
  val read_var: string -> term
550
353eea6ec232 replaced id, var, tid, tvar by idT, varT, tidT, tvarT;
wenzelm
parents: 376
diff changeset
    24
  val const: string -> term
353eea6ec232 replaced id, var, tid, tvar by idT, varT, tidT, tvarT;
wenzelm
parents: 376
diff changeset
    25
  val free: string -> term
353eea6ec232 replaced id, var, tid, tvar by idT, varT, tidT, tvarT;
wenzelm
parents: 376
diff changeset
    26
  val var: indexname -> term
9289
be6e79d1aae0 added internal, dest_internal;
wenzelm
parents: 7784
diff changeset
    27
  val internal: string -> string
be6e79d1aae0 added internal, dest_internal;
wenzelm
parents: 7784
diff changeset
    28
  val dest_internal: string -> string
5260
1835a591d3a7 binding / skolem vars;
wenzelm
parents: 5112
diff changeset
    29
  val skolem: string -> string
5286
cfb74a99182c dest_binding, dest_skolem;
wenzelm
parents: 5260
diff changeset
    30
  val dest_skolem: string -> string
5860
ed11c9890852 added read_nat;
wenzelm
parents: 5513
diff changeset
    31
  val read_nat: string -> int option
9326
1625c1f172b3 added read_xnum;
wenzelm
parents: 9289
diff changeset
    32
  val read_xnum: string -> int
7784
228283fa5de4 read_idents;
wenzelm
parents: 7472
diff changeset
    33
  val read_idents: string -> string list
4247
9bba9251bb4d added implode_xstr: string list -> string, explode_xstr: string -> string list;
wenzelm
parents: 3828
diff changeset
    34
end;
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    35
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    36
signature LEXICON =
4247
9bba9251bb4d added implode_xstr: string list -> string, explode_xstr: string -> string list;
wenzelm
parents: 3828
diff changeset
    37
sig
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
    38
  include LEXICON0
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
    39
  val is_xid: string -> bool
330
2fda15dd1e0f changed the way a grammar is generated to allow the new parser to work;
clasohm
parents: 237
diff changeset
    40
  val is_tid: string -> bool
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
    41
  datatype token =
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
    42
    Token of string |
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
    43
    IdentSy of string |
3828
f6a7ca242dc2 added longid;
wenzelm
parents: 2583
diff changeset
    44
    LongIdentSy of string |
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
    45
    VarSy of string |
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
    46
    TFreeSy of string |
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
    47
    TVarSy of string |
550
353eea6ec232 replaced id, var, tid, tvar by idT, varT, tidT, tvarT;
wenzelm
parents: 376
diff changeset
    48
    NumSy of string |
11697
8dd899efbd35 added "num" token;
wenzelm
parents: 9326
diff changeset
    49
    XNumSy of string |
550
353eea6ec232 replaced id, var, tid, tvar by idT, varT, tidT, tvarT;
wenzelm
parents: 376
diff changeset
    50
    StrSy of string |
237
a7d3e712767a MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
wenzelm
parents: 164
diff changeset
    51
    EndToken
550
353eea6ec232 replaced id, var, tid, tvar by idT, varT, tidT, tvarT;
wenzelm
parents: 376
diff changeset
    52
  val idT: typ
3828
f6a7ca242dc2 added longid;
wenzelm
parents: 2583
diff changeset
    53
  val longidT: typ
550
353eea6ec232 replaced id, var, tid, tvar by idT, varT, tidT, tvarT;
wenzelm
parents: 376
diff changeset
    54
  val varT: typ
353eea6ec232 replaced id, var, tid, tvar by idT, varT, tidT, tvarT;
wenzelm
parents: 376
diff changeset
    55
  val tidT: typ
353eea6ec232 replaced id, var, tid, tvar by idT, varT, tidT, tvarT;
wenzelm
parents: 376
diff changeset
    56
  val tvarT: typ
237
a7d3e712767a MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
wenzelm
parents: 164
diff changeset
    57
  val terminals: string list
a7d3e712767a MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
wenzelm
parents: 164
diff changeset
    58
  val is_terminal: string -> bool
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
    59
  val str_of_token: token -> string
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
    60
  val display_token: token -> string
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
    61
  val matching_tokens: token * token -> bool
330
2fda15dd1e0f changed the way a grammar is generated to allow the new parser to work;
clasohm
parents: 237
diff changeset
    62
  val token_assoc: (token option * 'a list) list * token -> 'a list
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
    63
  val valued_token: token -> bool
237
a7d3e712767a MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
wenzelm
parents: 164
diff changeset
    64
  val predef_term: string -> token option
4703
a50ab39756db adapted to symbols, scan;
wenzelm
parents: 4587
diff changeset
    65
  val tokenize: Scan.lexicon -> bool -> string list -> token list
4247
9bba9251bb4d added implode_xstr: string list -> string, explode_xstr: string -> string list;
wenzelm
parents: 3828
diff changeset
    66
end;
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    67
1507
f600215b6ea7 Elimination of fully-functorial style.
paulson
parents: 1143
diff changeset
    68
structure Lexicon : LEXICON =
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    69
struct
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    70
4247
9bba9251bb4d added implode_xstr: string list -> string, explode_xstr: string -> string list;
wenzelm
parents: 3828
diff changeset
    71
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
    72
(** is_identifier etc. **)
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
    73
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
    74
fun is_ident [] = false
4703
a50ab39756db adapted to symbols, scan;
wenzelm
parents: 4587
diff changeset
    75
  | is_ident (c :: cs) = Symbol.is_letter c andalso forall Symbol.is_letdig cs;
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
    76
4703
a50ab39756db adapted to symbols, scan;
wenzelm
parents: 4587
diff changeset
    77
val is_identifier = is_ident o Symbol.explode;
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
    78
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
    79
fun is_xid s =
4703
a50ab39756db adapted to symbols, scan;
wenzelm
parents: 4587
diff changeset
    80
  (case Symbol.explode s of
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
    81
    "_" :: cs => is_ident cs
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
    82
  | cs => is_ident cs);
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
    83
330
2fda15dd1e0f changed the way a grammar is generated to allow the new parser to work;
clasohm
parents: 237
diff changeset
    84
fun is_tid s =
4703
a50ab39756db adapted to symbols, scan;
wenzelm
parents: 4587
diff changeset
    85
  (case Symbol.explode s of
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
    86
    "'" :: cs => is_ident cs
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
    87
  | _ => false);
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
    88
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    89
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    90
4703
a50ab39756db adapted to symbols, scan;
wenzelm
parents: 4587
diff changeset
    91
(** basic scanners **)
a50ab39756db adapted to symbols, scan;
wenzelm
parents: 4587
diff changeset
    92
a50ab39756db adapted to symbols, scan;
wenzelm
parents: 4587
diff changeset
    93
val scan_letter_letdigs = Scan.one Symbol.is_letter -- Scan.any Symbol.is_letdig >> op ::;
a50ab39756db adapted to symbols, scan;
wenzelm
parents: 4587
diff changeset
    94
val scan_digits1 = Scan.any1 Symbol.is_digit;
a50ab39756db adapted to symbols, scan;
wenzelm
parents: 4587
diff changeset
    95
a50ab39756db adapted to symbols, scan;
wenzelm
parents: 4587
diff changeset
    96
val scan_id = scan_letter_letdigs >> implode;
a50ab39756db adapted to symbols, scan;
wenzelm
parents: 4587
diff changeset
    97
val scan_longid = scan_id ^^ (Scan.repeat1 ($$ "." ^^ scan_id) >> implode);
a50ab39756db adapted to symbols, scan;
wenzelm
parents: 4587
diff changeset
    98
val scan_tid = $$ "'" ^^ scan_id;
a50ab39756db adapted to symbols, scan;
wenzelm
parents: 4587
diff changeset
    99
a50ab39756db adapted to symbols, scan;
wenzelm
parents: 4587
diff changeset
   100
val scan_nat = scan_digits1 >> implode;
5513
3896c7894a57 Unary minus is now #- and not #~
paulson
parents: 5286
diff changeset
   101
val scan_int = $$ "-" ^^ scan_nat || scan_nat;
4703
a50ab39756db adapted to symbols, scan;
wenzelm
parents: 4587
diff changeset
   102
a50ab39756db adapted to symbols, scan;
wenzelm
parents: 4587
diff changeset
   103
val scan_id_nat = scan_id ^^ Scan.optional ($$ "." ^^ scan_nat) "";
a50ab39756db adapted to symbols, scan;
wenzelm
parents: 4587
diff changeset
   104
val scan_var = $$ "?" ^^ scan_id_nat;
4902
8fbccead3695 added scan_tvar;
wenzelm
parents: 4703
diff changeset
   105
val scan_tvar = $$ "?" ^^ $$ "'" ^^ scan_id_nat;
4703
a50ab39756db adapted to symbols, scan;
wenzelm
parents: 4587
diff changeset
   106
a50ab39756db adapted to symbols, scan;
wenzelm
parents: 4587
diff changeset
   107
a50ab39756db adapted to symbols, scan;
wenzelm
parents: 4587
diff changeset
   108
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   109
(** string_of_vname **)
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   110
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   111
fun string_of_vname (x, i) =
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   112
  let
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   113
    val si = string_of_int i;
6962
399643633529 more specific exn;
wenzelm
parents: 5868
diff changeset
   114
    val dot = if_none (try (Symbol.is_digit o last_elem o Symbol.explode) x) true;
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   115
  in
4703
a50ab39756db adapted to symbols, scan;
wenzelm
parents: 4587
diff changeset
   116
    if dot then "?" ^ x ^ "." ^ si
a50ab39756db adapted to symbols, scan;
wenzelm
parents: 4587
diff changeset
   117
    else if i = 0 then "?" ^ x
a50ab39756db adapted to symbols, scan;
wenzelm
parents: 4587
diff changeset
   118
    else "?" ^ x ^ si
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   119
  end;
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   120
4703
a50ab39756db adapted to symbols, scan;
wenzelm
parents: 4587
diff changeset
   121
fun string_of_vname' (x, ~1) = x
a50ab39756db adapted to symbols, scan;
wenzelm
parents: 4587
diff changeset
   122
  | string_of_vname' xi = string_of_vname xi;
2583
690835a06cf2 added string_of_vname' (treats neg. index as free);
wenzelm
parents: 2363
diff changeset
   123
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   124
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   125
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   126
(** datatype token **)
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   127
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   128
datatype token =
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   129
  Token of string |
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   130
  IdentSy of string |
3828
f6a7ca242dc2 added longid;
wenzelm
parents: 2583
diff changeset
   131
  LongIdentSy of string |
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   132
  VarSy of string |
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   133
  TFreeSy of string |
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   134
  TVarSy of string |
550
353eea6ec232 replaced id, var, tid, tvar by idT, varT, tidT, tvarT;
wenzelm
parents: 376
diff changeset
   135
  NumSy of string |
11697
8dd899efbd35 added "num" token;
wenzelm
parents: 9326
diff changeset
   136
  XNumSy of string |
550
353eea6ec232 replaced id, var, tid, tvar by idT, varT, tidT, tvarT;
wenzelm
parents: 376
diff changeset
   137
  StrSy of string |
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   138
  EndToken;
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   139
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   140
237
a7d3e712767a MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
wenzelm
parents: 164
diff changeset
   141
(* terminal arguments *)
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   142
550
353eea6ec232 replaced id, var, tid, tvar by idT, varT, tidT, tvarT;
wenzelm
parents: 376
diff changeset
   143
val idT = Type ("id", []);
3828
f6a7ca242dc2 added longid;
wenzelm
parents: 2583
diff changeset
   144
val longidT = Type ("longid", []);
550
353eea6ec232 replaced id, var, tid, tvar by idT, varT, tidT, tvarT;
wenzelm
parents: 376
diff changeset
   145
val varT = Type ("var", []);
353eea6ec232 replaced id, var, tid, tvar by idT, varT, tidT, tvarT;
wenzelm
parents: 376
diff changeset
   146
val tidT = Type ("tid", []);
353eea6ec232 replaced id, var, tid, tvar by idT, varT, tidT, tvarT;
wenzelm
parents: 376
diff changeset
   147
val tvarT = Type ("tvar", []);
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   148
11697
8dd899efbd35 added "num" token;
wenzelm
parents: 9326
diff changeset
   149
val terminals = ["id", "longid", "var", "tid", "tvar", "num", "xnum", "xstr"];
237
a7d3e712767a MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
wenzelm
parents: 164
diff changeset
   150
a7d3e712767a MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
wenzelm
parents: 164
diff changeset
   151
fun is_terminal s = s mem terminals;
a7d3e712767a MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
wenzelm
parents: 164
diff changeset
   152
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   153
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   154
(* str_of_token *)
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   155
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   156
fun str_of_token (Token s) = s
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   157
  | str_of_token (IdentSy s) = s
3828
f6a7ca242dc2 added longid;
wenzelm
parents: 2583
diff changeset
   158
  | str_of_token (LongIdentSy s) = s
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   159
  | str_of_token (VarSy s) = s
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   160
  | str_of_token (TFreeSy s) = s
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   161
  | str_of_token (TVarSy s) = s
550
353eea6ec232 replaced id, var, tid, tvar by idT, varT, tidT, tvarT;
wenzelm
parents: 376
diff changeset
   162
  | str_of_token (NumSy s) = s
11697
8dd899efbd35 added "num" token;
wenzelm
parents: 9326
diff changeset
   163
  | str_of_token (XNumSy s) = s
550
353eea6ec232 replaced id, var, tid, tvar by idT, varT, tidT, tvarT;
wenzelm
parents: 376
diff changeset
   164
  | str_of_token (StrSy s) = s
376
d3d01131470f extended signature SCANNER by some basic scanners and type lexicon;
wenzelm
parents: 330
diff changeset
   165
  | str_of_token EndToken = "EOF";
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   166
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   167
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   168
(* display_token *)
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   169
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   170
fun display_token (Token s) = quote s
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   171
  | display_token (IdentSy s) = "id(" ^ s ^ ")"
3828
f6a7ca242dc2 added longid;
wenzelm
parents: 2583
diff changeset
   172
  | display_token (LongIdentSy s) = "longid(" ^ s ^ ")"
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   173
  | display_token (VarSy s) = "var(" ^ s ^ ")"
330
2fda15dd1e0f changed the way a grammar is generated to allow the new parser to work;
clasohm
parents: 237
diff changeset
   174
  | display_token (TFreeSy s) = "tid(" ^ s ^ ")"
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   175
  | display_token (TVarSy s) = "tvar(" ^ s ^ ")"
11697
8dd899efbd35 added "num" token;
wenzelm
parents: 9326
diff changeset
   176
  | display_token (NumSy s) = "num(" ^ s ^ ")"
8dd899efbd35 added "num" token;
wenzelm
parents: 9326
diff changeset
   177
  | display_token (XNumSy s) = "xnum(" ^ s ^ ")"
550
353eea6ec232 replaced id, var, tid, tvar by idT, varT, tidT, tvarT;
wenzelm
parents: 376
diff changeset
   178
  | display_token (StrSy s) = "xstr(" ^ s ^ ")"
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   179
  | display_token EndToken = "";
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   180
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   181
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   182
(* matching_tokens *)
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   183
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   184
fun matching_tokens (Token x, Token y) = (x = y)
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   185
  | matching_tokens (IdentSy _, IdentSy _) = true
3828
f6a7ca242dc2 added longid;
wenzelm
parents: 2583
diff changeset
   186
  | matching_tokens (LongIdentSy _, LongIdentSy _) = true
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   187
  | matching_tokens (VarSy _, VarSy _) = true
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   188
  | matching_tokens (TFreeSy _, TFreeSy _) = true
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   189
  | matching_tokens (TVarSy _, TVarSy _) = true
550
353eea6ec232 replaced id, var, tid, tvar by idT, varT, tidT, tvarT;
wenzelm
parents: 376
diff changeset
   190
  | matching_tokens (NumSy _, NumSy _) = true
11697
8dd899efbd35 added "num" token;
wenzelm
parents: 9326
diff changeset
   191
  | matching_tokens (XNumSy _, XNumSy _) = true
550
353eea6ec232 replaced id, var, tid, tvar by idT, varT, tidT, tvarT;
wenzelm
parents: 376
diff changeset
   192
  | matching_tokens (StrSy _, StrSy _) = true
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   193
  | matching_tokens (EndToken, EndToken) = true
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   194
  | matching_tokens _ = false;
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   195
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   196
376
d3d01131470f extended signature SCANNER by some basic scanners and type lexicon;
wenzelm
parents: 330
diff changeset
   197
(* token_assoc *)
d3d01131470f extended signature SCANNER by some basic scanners and type lexicon;
wenzelm
parents: 330
diff changeset
   198
330
2fda15dd1e0f changed the way a grammar is generated to allow the new parser to work;
clasohm
parents: 237
diff changeset
   199
fun token_assoc (list, key) =
376
d3d01131470f extended signature SCANNER by some basic scanners and type lexicon;
wenzelm
parents: 330
diff changeset
   200
  let
d3d01131470f extended signature SCANNER by some basic scanners and type lexicon;
wenzelm
parents: 330
diff changeset
   201
    fun assoc [] = []
d3d01131470f extended signature SCANNER by some basic scanners and type lexicon;
wenzelm
parents: 330
diff changeset
   202
      | assoc ((keyi, xi) :: pairs) =
d3d01131470f extended signature SCANNER by some basic scanners and type lexicon;
wenzelm
parents: 330
diff changeset
   203
          if is_none keyi orelse matching_tokens (the keyi, key) then
d3d01131470f extended signature SCANNER by some basic scanners and type lexicon;
wenzelm
parents: 330
diff changeset
   204
            assoc pairs @ xi
d3d01131470f extended signature SCANNER by some basic scanners and type lexicon;
wenzelm
parents: 330
diff changeset
   205
          else assoc pairs;
330
2fda15dd1e0f changed the way a grammar is generated to allow the new parser to work;
clasohm
parents: 237
diff changeset
   206
  in assoc list end;
2fda15dd1e0f changed the way a grammar is generated to allow the new parser to work;
clasohm
parents: 237
diff changeset
   207
2fda15dd1e0f changed the way a grammar is generated to allow the new parser to work;
clasohm
parents: 237
diff changeset
   208
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   209
(* valued_token *)
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   210
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   211
fun valued_token (Token _) = false
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   212
  | valued_token (IdentSy _) = true
3828
f6a7ca242dc2 added longid;
wenzelm
parents: 2583
diff changeset
   213
  | valued_token (LongIdentSy _) = true
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   214
  | valued_token (VarSy _) = true
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   215
  | valued_token (TFreeSy _) = true
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   216
  | valued_token (TVarSy _) = true
550
353eea6ec232 replaced id, var, tid, tvar by idT, varT, tidT, tvarT;
wenzelm
parents: 376
diff changeset
   217
  | valued_token (NumSy _) = true
11697
8dd899efbd35 added "num" token;
wenzelm
parents: 9326
diff changeset
   218
  | valued_token (XNumSy _) = true
550
353eea6ec232 replaced id, var, tid, tvar by idT, varT, tidT, tvarT;
wenzelm
parents: 376
diff changeset
   219
  | valued_token (StrSy _) = true
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   220
  | valued_token EndToken = false;
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   221
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   222
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   223
(* predef_term *)
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   224
550
353eea6ec232 replaced id, var, tid, tvar by idT, varT, tidT, tvarT;
wenzelm
parents: 376
diff changeset
   225
fun predef_term "id" = Some (IdentSy "id")
3828
f6a7ca242dc2 added longid;
wenzelm
parents: 2583
diff changeset
   226
  | predef_term "longid" = Some (LongIdentSy "longid")
550
353eea6ec232 replaced id, var, tid, tvar by idT, varT, tidT, tvarT;
wenzelm
parents: 376
diff changeset
   227
  | predef_term "var" = Some (VarSy "var")
353eea6ec232 replaced id, var, tid, tvar by idT, varT, tidT, tvarT;
wenzelm
parents: 376
diff changeset
   228
  | predef_term "tid" = Some (TFreeSy "tid")
353eea6ec232 replaced id, var, tid, tvar by idT, varT, tidT, tvarT;
wenzelm
parents: 376
diff changeset
   229
  | predef_term "tvar" = Some (TVarSy "tvar")
11697
8dd899efbd35 added "num" token;
wenzelm
parents: 9326
diff changeset
   230
  | predef_term "num" = Some (NumSy "num")
8dd899efbd35 added "num" token;
wenzelm
parents: 9326
diff changeset
   231
  | predef_term "xnum" = Some (XNumSy "xnum")
550
353eea6ec232 replaced id, var, tid, tvar by idT, varT, tidT, tvarT;
wenzelm
parents: 376
diff changeset
   232
  | predef_term "xstr" = Some (StrSy "xstr")
353eea6ec232 replaced id, var, tid, tvar by idT, varT, tidT, tvarT;
wenzelm
parents: 376
diff changeset
   233
  | predef_term _ = None;
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   234
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   235
4703
a50ab39756db adapted to symbols, scan;
wenzelm
parents: 4587
diff changeset
   236
(* xstr tokens *)
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   237
4703
a50ab39756db adapted to symbols, scan;
wenzelm
parents: 4587
diff changeset
   238
val scan_chr =
a50ab39756db adapted to symbols, scan;
wenzelm
parents: 4587
diff changeset
   239
  $$ "\\" |-- Scan.one Symbol.not_eof ||
a50ab39756db adapted to symbols, scan;
wenzelm
parents: 4587
diff changeset
   240
  Scan.one (not_equal "'" andf Symbol.not_eof) ||
a50ab39756db adapted to symbols, scan;
wenzelm
parents: 4587
diff changeset
   241
  $$ "'" --| Scan.ahead (Scan.one (not_equal "'"));
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   242
4703
a50ab39756db adapted to symbols, scan;
wenzelm
parents: 4587
diff changeset
   243
val scan_str =
a50ab39756db adapted to symbols, scan;
wenzelm
parents: 4587
diff changeset
   244
  $$ "'" |-- $$ "'" |--
4921
74bc10921f7d adapted to new Scan.fail_with / Scan.!!;
wenzelm
parents: 4902
diff changeset
   245
    !! (fn (cs, _) => "Inner lexical error: malformed literal string at " ^
5112
9e74cf11e4a4 Symbol.beginning;
wenzelm
parents: 4938
diff changeset
   246
      quote ("''" ^ Symbol.beginning cs))
4921
74bc10921f7d adapted to new Scan.fail_with / Scan.!!;
wenzelm
parents: 4902
diff changeset
   247
    (Scan.repeat scan_chr --| $$ "'" --| $$ "'");
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   248
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   249
4703
a50ab39756db adapted to symbols, scan;
wenzelm
parents: 4587
diff changeset
   250
fun implode_xstr cs = enclose "''" "''" (implode (map (fn "'" => "\\'" | c => c) cs));
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   251
4703
a50ab39756db adapted to symbols, scan;
wenzelm
parents: 4587
diff changeset
   252
fun explode_xstr str =
5868
0022d0a913b5 tuned usage of read;
wenzelm
parents: 5860
diff changeset
   253
  (case Scan.read Symbol.stopper scan_str (Symbol.explode str) of
0022d0a913b5 tuned usage of read;
wenzelm
parents: 5860
diff changeset
   254
    Some cs => cs
0022d0a913b5 tuned usage of read;
wenzelm
parents: 5860
diff changeset
   255
  | _ => error ("Inner lexical error: literal string expected at " ^ quote str));
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   256
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   257
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   258
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   259
(** tokenize **)
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   260
2363
963285471dc5 tokenize: no gets exploded char list;
wenzelm
parents: 1507
diff changeset
   261
fun tokenize lex xids chs =
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   262
  let
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   263
    val scan_xid =
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   264
      if xids then $$ "_" ^^ scan_id || scan_id
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   265
      else scan_id;
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   266
550
353eea6ec232 replaced id, var, tid, tvar by idT, varT, tidT, tvarT;
wenzelm
parents: 376
diff changeset
   267
    val scan_val =
4902
8fbccead3695 added scan_tvar;
wenzelm
parents: 4703
diff changeset
   268
      scan_tvar >> pair TVarSy ||
4703
a50ab39756db adapted to symbols, scan;
wenzelm
parents: 4587
diff changeset
   269
      scan_var >> pair VarSy ||
a50ab39756db adapted to symbols, scan;
wenzelm
parents: 4587
diff changeset
   270
      scan_tid >> pair TFreeSy ||
11697
8dd899efbd35 added "num" token;
wenzelm
parents: 9326
diff changeset
   271
      scan_int >> pair NumSy ||
8dd899efbd35 added "num" token;
wenzelm
parents: 9326
diff changeset
   272
      $$ "#" ^^ scan_int >> pair XNumSy ||
3828
f6a7ca242dc2 added longid;
wenzelm
parents: 2583
diff changeset
   273
      scan_longid >> pair LongIdentSy ||
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   274
      scan_xid >> pair IdentSy;
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   275
4703
a50ab39756db adapted to symbols, scan;
wenzelm
parents: 4587
diff changeset
   276
    val scan_lit = Scan.literal lex >> (pair Token o implode);
550
353eea6ec232 replaced id, var, tid, tvar by idT, varT, tidT, tvarT;
wenzelm
parents: 376
diff changeset
   277
4703
a50ab39756db adapted to symbols, scan;
wenzelm
parents: 4587
diff changeset
   278
    val scan_token =
a50ab39756db adapted to symbols, scan;
wenzelm
parents: 4587
diff changeset
   279
      Scan.max (op <= o pairself snd) scan_lit scan_val >> (fn (tk, s) => Some (tk s)) ||
a50ab39756db adapted to symbols, scan;
wenzelm
parents: 4587
diff changeset
   280
      scan_str >> (Some o StrSy o implode_xstr) ||
a50ab39756db adapted to symbols, scan;
wenzelm
parents: 4587
diff changeset
   281
      Scan.one Symbol.is_blank >> K None;
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   282
  in
4938
c8bbbf3c59fa Symbol.stopper;
wenzelm
parents: 4921
diff changeset
   283
    (case Scan.error (Scan.finite Symbol.stopper (Scan.repeat scan_token)) chs of
4703
a50ab39756db adapted to symbols, scan;
wenzelm
parents: 4587
diff changeset
   284
      (toks, []) => mapfilter I toks @ [EndToken]
a50ab39756db adapted to symbols, scan;
wenzelm
parents: 4587
diff changeset
   285
    | (_, cs) => error ("Inner lexical error at: " ^ quote (implode cs)))
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   286
  end;
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   287
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   288
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   289
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   290
(** scan variables **)
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   291
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   292
(* scan_vname *)
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   293
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   294
fun scan_vname chrs =
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   295
  let
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   296
    fun nat_of_chs n [] = n
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   297
      | nat_of_chs n (c :: cs) = nat_of_chs (n * 10 + (ord c - ord "0")) cs;
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   298
4703
a50ab39756db adapted to symbols, scan;
wenzelm
parents: 4587
diff changeset
   299
    val nat = nat_of_chs 0;
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   300
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   301
    fun split_vname chs =
4703
a50ab39756db adapted to symbols, scan;
wenzelm
parents: 4587
diff changeset
   302
      let val (cs, ds) = take_suffix Symbol.is_digit chs
a50ab39756db adapted to symbols, scan;
wenzelm
parents: 4587
diff changeset
   303
      in (implode cs, nat ds) end
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
    val scan =
4703
a50ab39756db adapted to symbols, scan;
wenzelm
parents: 4587
diff changeset
   306
      scan_letter_letdigs -- Scan.optional ($$ "." |-- scan_digits1 >> nat) ~1;
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   307
  in
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   308
    (case scan chrs of
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   309
      ((cs, ~1), cs') => (split_vname cs, cs')
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   310
    | ((cs, i), cs') => ((implode cs, i), cs'))
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   311
  end;
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   312
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   313
4703
a50ab39756db adapted to symbols, scan;
wenzelm
parents: 4587
diff changeset
   314
(* indexname *)
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   315
4703
a50ab39756db adapted to symbols, scan;
wenzelm
parents: 4587
diff changeset
   316
fun indexname cs =
5868
0022d0a913b5 tuned usage of read;
wenzelm
parents: 5860
diff changeset
   317
  (case Scan.read Symbol.stopper scan_vname cs of
0022d0a913b5 tuned usage of read;
wenzelm
parents: 5860
diff changeset
   318
    Some xi => xi
4703
a50ab39756db adapted to symbols, scan;
wenzelm
parents: 4587
diff changeset
   319
  | _ => error ("Lexical error in variable name: " ^ quote (implode cs)));
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   320
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   321
4703
a50ab39756db adapted to symbols, scan;
wenzelm
parents: 4587
diff changeset
   322
(* read_var *)
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   323
550
353eea6ec232 replaced id, var, tid, tvar by idT, varT, tidT, tvarT;
wenzelm
parents: 376
diff changeset
   324
fun const c = Const (c, dummyT);
353eea6ec232 replaced id, var, tid, tvar by idT, varT, tidT, tvarT;
wenzelm
parents: 376
diff changeset
   325
fun free x = Free (x, dummyT);
353eea6ec232 replaced id, var, tid, tvar by idT, varT, tidT, tvarT;
wenzelm
parents: 376
diff changeset
   326
fun var xi = Var (xi, dummyT);
353eea6ec232 replaced id, var, tid, tvar by idT, varT, tidT, tvarT;
wenzelm
parents: 376
diff changeset
   327
4703
a50ab39756db adapted to symbols, scan;
wenzelm
parents: 4587
diff changeset
   328
fun read_var str =
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   329
  let
550
353eea6ec232 replaced id, var, tid, tvar by idT, varT, tidT, tvarT;
wenzelm
parents: 376
diff changeset
   330
    fun tvar (x, i) = var ("'" ^ x, i);
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   331
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   332
    val scan =
4703
a50ab39756db adapted to symbols, scan;
wenzelm
parents: 4587
diff changeset
   333
      $$ "?" |-- $$ "'" |-- scan_vname >> tvar ||
a50ab39756db adapted to symbols, scan;
wenzelm
parents: 4587
diff changeset
   334
      $$ "?" |-- scan_vname >> var ||
a50ab39756db adapted to symbols, scan;
wenzelm
parents: 4587
diff changeset
   335
      Scan.any Symbol.not_eof >> (free o implode);
5868
0022d0a913b5 tuned usage of read;
wenzelm
parents: 5860
diff changeset
   336
  in the (Scan.read Symbol.stopper scan (Symbol.explode str)) end;
4587
6bce9ef27d7e added read_var;
wenzelm
parents: 4247
diff changeset
   337
6bce9ef27d7e added read_var;
wenzelm
parents: 4247
diff changeset
   338
5260
1835a591d3a7 binding / skolem vars;
wenzelm
parents: 5112
diff changeset
   339
(* variable kinds *)
1835a591d3a7 binding / skolem vars;
wenzelm
parents: 5112
diff changeset
   340
9289
be6e79d1aae0 added internal, dest_internal;
wenzelm
parents: 7784
diff changeset
   341
val internal = suffix "_";
be6e79d1aae0 added internal, dest_internal;
wenzelm
parents: 7784
diff changeset
   342
val dest_internal = unsuffix "_";
be6e79d1aae0 added internal, dest_internal;
wenzelm
parents: 7784
diff changeset
   343
5286
cfb74a99182c dest_binding, dest_skolem;
wenzelm
parents: 5260
diff changeset
   344
val skolem = suffix "__";
cfb74a99182c dest_binding, dest_skolem;
wenzelm
parents: 5260
diff changeset
   345
val dest_skolem = unsuffix "__";
5260
1835a591d3a7 binding / skolem vars;
wenzelm
parents: 5112
diff changeset
   346
1835a591d3a7 binding / skolem vars;
wenzelm
parents: 5112
diff changeset
   347
5860
ed11c9890852 added read_nat;
wenzelm
parents: 5513
diff changeset
   348
(* read_nat *)
ed11c9890852 added read_nat;
wenzelm
parents: 5513
diff changeset
   349
ed11c9890852 added read_nat;
wenzelm
parents: 5513
diff changeset
   350
fun read_nat str =
5868
0022d0a913b5 tuned usage of read;
wenzelm
parents: 5860
diff changeset
   351
  apsome (#1 o Term.read_int) (Scan.read Symbol.stopper scan_digits1 (Symbol.explode str));
5860
ed11c9890852 added read_nat;
wenzelm
parents: 5513
diff changeset
   352
ed11c9890852 added read_nat;
wenzelm
parents: 5513
diff changeset
   353
9326
1625c1f172b3 added read_xnum;
wenzelm
parents: 9289
diff changeset
   354
(* read_xnum *)
1625c1f172b3 added read_xnum;
wenzelm
parents: 9289
diff changeset
   355
1625c1f172b3 added read_xnum;
wenzelm
parents: 9289
diff changeset
   356
fun read_xnum str =
1625c1f172b3 added read_xnum;
wenzelm
parents: 9289
diff changeset
   357
  let
1625c1f172b3 added read_xnum;
wenzelm
parents: 9289
diff changeset
   358
    val (sign, digs) =
1625c1f172b3 added read_xnum;
wenzelm
parents: 9289
diff changeset
   359
      (case Symbol.explode str of
1625c1f172b3 added read_xnum;
wenzelm
parents: 9289
diff changeset
   360
        "#" :: "-" :: cs => (~1, cs)
1625c1f172b3 added read_xnum;
wenzelm
parents: 9289
diff changeset
   361
      | "#" :: cs => (1, cs)
11697
8dd899efbd35 added "num" token;
wenzelm
parents: 9326
diff changeset
   362
      | "-" :: cs => (~1, cs)
8dd899efbd35 added "num" token;
wenzelm
parents: 9326
diff changeset
   363
      | cs => (1, cs));
9326
1625c1f172b3 added read_xnum;
wenzelm
parents: 9289
diff changeset
   364
  in sign * #1 (Term.read_int digs) end;
1625c1f172b3 added read_xnum;
wenzelm
parents: 9289
diff changeset
   365
1625c1f172b3 added read_xnum;
wenzelm
parents: 9289
diff changeset
   366
7784
228283fa5de4 read_idents;
wenzelm
parents: 7472
diff changeset
   367
(* read_ident(s) *)
228283fa5de4 read_idents;
wenzelm
parents: 7472
diff changeset
   368
228283fa5de4 read_idents;
wenzelm
parents: 7472
diff changeset
   369
fun read_idents str =
228283fa5de4 read_idents;
wenzelm
parents: 7472
diff changeset
   370
  let
228283fa5de4 read_idents;
wenzelm
parents: 7472
diff changeset
   371
    val blanks = Scan.any Symbol.is_blank;
228283fa5de4 read_idents;
wenzelm
parents: 7472
diff changeset
   372
    val junk = Scan.any Symbol.not_eof;
228283fa5de4 read_idents;
wenzelm
parents: 7472
diff changeset
   373
    val idents = Scan.repeat1 (blanks |-- scan_id --| blanks) -- junk;
228283fa5de4 read_idents;
wenzelm
parents: 7472
diff changeset
   374
  in
228283fa5de4 read_idents;
wenzelm
parents: 7472
diff changeset
   375
    (case Scan.read Symbol.stopper idents (Symbol.explode str) of
228283fa5de4 read_idents;
wenzelm
parents: 7472
diff changeset
   376
      Some (ids, []) => ids
228283fa5de4 read_idents;
wenzelm
parents: 7472
diff changeset
   377
    | Some (_, bad) => error ("Bad identifier: " ^ quote (implode bad))
228283fa5de4 read_idents;
wenzelm
parents: 7472
diff changeset
   378
    | None => error ("No identifier found in: " ^ quote str))
228283fa5de4 read_idents;
wenzelm
parents: 7472
diff changeset
   379
  end;
228283fa5de4 read_idents;
wenzelm
parents: 7472
diff changeset
   380
228283fa5de4 read_idents;
wenzelm
parents: 7472
diff changeset
   381
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   382
end;