src/Pure/Isar/outer_lex.ML
author wenzelm
Sat Aug 09 22:43:56 2008 +0200 (2008-08-09 ago)
changeset 27814 05a50886dacb
parent 27799 52f07d5292cd
child 27835 ff8b8513965a
permissions -rw-r--r--
unified Args.T with OuterLex.token;
renamed val_of to content_of;
added InternalValue kind;
added datatype value/slot with static binding (from args.ML);
renamed is_sid to ident_or_symbolic;
wenzelm@5825
     1
(*  Title:      Pure/Isar/outer_lex.ML
wenzelm@5825
     2
    ID:         $Id$
wenzelm@5825
     3
    Author:     Markus Wenzel, TU Muenchen
wenzelm@5825
     4
wenzelm@5825
     5
Outer lexical syntax for Isabelle/Isar.
wenzelm@5825
     6
*)
wenzelm@5825
     7
wenzelm@5825
     8
signature OUTER_LEX =
wenzelm@5825
     9
sig
wenzelm@5825
    10
  datatype token_kind =
wenzelm@27814
    11
    Command | Keyword | Ident | LongIdent | SymIdent | Var | TypeIdent | TypeVar |
wenzelm@27814
    12
    Nat | String | AltString | Verbatim | Space | Comment | InternalValue |
wenzelm@27814
    13
    Malformed | Error of string | Sync | EOF
wenzelm@27814
    14
  datatype value =
wenzelm@27814
    15
    Text of string | Typ of typ | Term of term | Fact of thm list |
wenzelm@27814
    16
    Attribute of morphism -> attribute
wenzelm@27814
    17
  type token
wenzelm@5825
    18
  val str_of_kind: token_kind -> string
wenzelm@5825
    19
  val position_of: token -> Position.T
wenzelm@27752
    20
  val end_position_of: token -> Position.T
wenzelm@5825
    21
  val pos_of: token -> string
wenzelm@27733
    22
  val eof: token
wenzelm@27733
    23
  val is_eof: token -> bool
wenzelm@27733
    24
  val not_eof: token -> bool
wenzelm@27733
    25
  val not_sync: token -> bool
wenzelm@27733
    26
  val stopper: token Scan.stopper
wenzelm@23721
    27
  val kind_of: token -> token_kind
wenzelm@5825
    28
  val is_kind: token_kind -> token -> bool
wenzelm@7026
    29
  val keyword_with: (string -> bool) -> token -> bool
wenzelm@16029
    30
  val ident_with: (string -> bool) -> token -> bool
wenzelm@5825
    31
  val is_proper: token -> bool
wenzelm@9130
    32
  val is_semicolon: token -> bool
wenzelm@17069
    33
  val is_comment: token -> bool
wenzelm@8580
    34
  val is_begin_ignore: token -> bool
wenzelm@8580
    35
  val is_end_ignore: token -> bool
wenzelm@17069
    36
  val is_blank: token -> bool
wenzelm@8651
    37
  val is_newline: token -> bool
wenzelm@27747
    38
  val source_of: token -> string
wenzelm@27814
    39
  val content_of: token -> string
wenzelm@14991
    40
  val unparse: token -> string
wenzelm@23788
    41
  val text_of: token -> string * string
wenzelm@27814
    42
  val get_value: token -> value option
wenzelm@27814
    43
  val map_value: (value -> value) -> token -> token
wenzelm@27814
    44
  val mk_text: string -> token
wenzelm@27814
    45
  val mk_typ: typ -> token
wenzelm@27814
    46
  val mk_term: term -> token
wenzelm@27814
    47
  val mk_fact: thm list -> token
wenzelm@27814
    48
  val mk_attribute: (morphism -> attribute) -> token
wenzelm@27814
    49
  val assignable: token -> token
wenzelm@27814
    50
  val assign: value option -> token -> unit
wenzelm@27814
    51
  val closure: token -> token
wenzelm@27814
    52
  val ident_or_symbolic: string -> bool
wenzelm@27769
    53
  val !!! : string -> (SymbolPos.T list -> 'a) -> SymbolPos.T list -> 'a
wenzelm@27769
    54
  val scan_quoted: SymbolPos.T list -> SymbolPos.T list * SymbolPos.T list
wenzelm@27769
    55
  val source_proper: (token, 'a) Source.source -> (token, (token, 'a) Source.source) Source.source
wenzelm@27780
    56
  val source': bool Option.option -> (unit -> Scan.lexicon * Scan.lexicon) ->
wenzelm@27780
    57
    (SymbolPos.T, 'a) Source.source -> (token, (SymbolPos.T, 'a) Source.source) Source.source
wenzelm@27769
    58
  val source: bool Option.option -> (unit -> Scan.lexicon * Scan.lexicon) ->
wenzelm@27769
    59
    Position.T -> (Symbol.symbol, 'a) Source.source -> (token,
wenzelm@27769
    60
      (SymbolPos.T, Position.T * (Symbol.symbol, 'a) Source.source) Source.source) Source.source
wenzelm@5825
    61
end;
wenzelm@5825
    62
wenzelm@5825
    63
structure OuterLex: OUTER_LEX =
wenzelm@5825
    64
struct
wenzelm@5825
    65
wenzelm@5825
    66
(** tokens **)
wenzelm@5825
    67
wenzelm@27814
    68
(* token values *)
wenzelm@27814
    69
wenzelm@27814
    70
(*The value slot assigns an (optional) internal value to a token,
wenzelm@27814
    71
  usually as a side-effect of special scanner setup (see also
wenzelm@27814
    72
  args.ML).  Note that an assignable ref designates an intermediate
wenzelm@27814
    73
  state of internalization -- it is NOT meant to persist.*)
wenzelm@27814
    74
wenzelm@27814
    75
datatype value =
wenzelm@27814
    76
  Text of string |
wenzelm@27814
    77
  Typ of typ |
wenzelm@27814
    78
  Term of term |
wenzelm@27814
    79
  Fact of thm list |
wenzelm@27814
    80
  Attribute of morphism -> attribute;
wenzelm@27814
    81
wenzelm@27814
    82
datatype slot =
wenzelm@27814
    83
  Slot |
wenzelm@27814
    84
  Value of value option |
wenzelm@27814
    85
  Assignable of value option ref;
wenzelm@27814
    86
wenzelm@27814
    87
wenzelm@5825
    88
(* datatype token *)
wenzelm@5825
    89
wenzelm@5825
    90
datatype token_kind =
wenzelm@27814
    91
  Command | Keyword | Ident | LongIdent | SymIdent | Var | TypeIdent | TypeVar |
wenzelm@27814
    92
  Nat | String | AltString | Verbatim | Space | Comment | InternalValue |
wenzelm@27814
    93
  Malformed | Error of string | Sync | EOF;
wenzelm@5825
    94
wenzelm@27814
    95
datatype token = Token of (SymbolPos.text * Position.range) * (token_kind * string) * slot;
wenzelm@5825
    96
wenzelm@5825
    97
val str_of_kind =
wenzelm@7026
    98
 fn Command => "command"
wenzelm@7026
    99
  | Keyword => "keyword"
wenzelm@5825
   100
  | Ident => "identifier"
wenzelm@5825
   101
  | LongIdent => "long identifier"
wenzelm@5825
   102
  | SymIdent => "symbolic identifier"
wenzelm@5825
   103
  | Var => "schematic variable"
wenzelm@5825
   104
  | TypeIdent => "type variable"
wenzelm@5825
   105
  | TypeVar => "schematic type variable"
wenzelm@5825
   106
  | Nat => "number"
wenzelm@5825
   107
  | String => "string"
wenzelm@17164
   108
  | AltString => "back-quoted string"
wenzelm@5825
   109
  | Verbatim => "verbatim text"
wenzelm@7682
   110
  | Space => "white space"
wenzelm@7682
   111
  | Comment => "comment text"
wenzelm@27814
   112
  | InternalValue => "internal value"
wenzelm@23729
   113
  | Malformed => "malformed symbolic character"
wenzelm@23729
   114
  | Error _ => "bad input"
wenzelm@23788
   115
  | Sync => "sync marker"
wenzelm@5825
   116
  | EOF => "end-of-file";
wenzelm@5825
   117
wenzelm@5825
   118
wenzelm@27733
   119
(* position *)
wenzelm@5825
   120
wenzelm@27814
   121
fun position_of (Token ((_, (pos, _)), _, _)) = pos;
wenzelm@27814
   122
fun end_position_of (Token ((_, (_, pos)), _, _)) = pos;
wenzelm@27663
   123
wenzelm@5825
   124
val pos_of = Position.str_of o position_of;
wenzelm@5825
   125
wenzelm@5825
   126
wenzelm@27733
   127
(* control tokens *)
wenzelm@27733
   128
wenzelm@27814
   129
fun mk_eof pos = Token (("", (pos, Position.none)), (EOF, ""), Slot);
wenzelm@27733
   130
val eof = mk_eof Position.none;
wenzelm@27733
   131
wenzelm@27814
   132
fun is_eof (Token (_, (EOF, _), _)) = true
wenzelm@27733
   133
  | is_eof _ = false;
wenzelm@27733
   134
wenzelm@27733
   135
val not_eof = not o is_eof;
wenzelm@27733
   136
wenzelm@27814
   137
fun not_sync (Token (_, (Sync, _), _)) = false
wenzelm@27733
   138
  | not_sync _ = true;
wenzelm@27733
   139
wenzelm@27752
   140
val stopper =
wenzelm@27752
   141
  Scan.stopper (fn [] => eof | toks => mk_eof (end_position_of (List.last toks))) is_eof;
wenzelm@27733
   142
wenzelm@27733
   143
wenzelm@5825
   144
(* kind of token *)
wenzelm@5825
   145
wenzelm@27814
   146
fun kind_of (Token (_, (k, _), _)) = k;
wenzelm@27814
   147
fun is_kind k (Token (_, (k', _), _)) = k = k';
wenzelm@5825
   148
wenzelm@27814
   149
fun keyword_with pred (Token (_, (Keyword, x), _)) = pred x
wenzelm@7026
   150
  | keyword_with _ _ = false;
wenzelm@5825
   151
wenzelm@27814
   152
fun ident_with pred (Token (_, (Ident, x), _)) = pred x
wenzelm@16029
   153
  | ident_with _ _ = false;
wenzelm@16029
   154
wenzelm@27814
   155
fun is_proper (Token (_, (Space, _), _)) = false
wenzelm@27814
   156
  | is_proper (Token (_, (Comment, _), _)) = false
wenzelm@5825
   157
  | is_proper _ = true;
wenzelm@5825
   158
wenzelm@27814
   159
fun is_semicolon (Token (_, (Keyword, ";"), _)) = true
wenzelm@9130
   160
  | is_semicolon _ = false;
wenzelm@9130
   161
wenzelm@27814
   162
fun is_comment (Token (_, (Comment, _), _)) = true
wenzelm@17069
   163
  | is_comment _ = false;
wenzelm@17069
   164
wenzelm@27814
   165
fun is_begin_ignore (Token (_, (Comment, "<"), _)) = true
wenzelm@8580
   166
  | is_begin_ignore _ = false;
wenzelm@8580
   167
wenzelm@27814
   168
fun is_end_ignore (Token (_, (Comment, ">"), _)) = true
wenzelm@8580
   169
  | is_end_ignore _ = false;
wenzelm@8580
   170
wenzelm@8651
   171
wenzelm@17069
   172
(* blanks and newlines -- space tokens obey lines *)
wenzelm@8651
   173
wenzelm@27814
   174
fun is_blank (Token (_, (Space, x), _)) = not (String.isSuffix "\n" x)
wenzelm@17069
   175
  | is_blank _ = false;
wenzelm@17069
   176
wenzelm@27814
   177
fun is_newline (Token (_, (Space, x), _)) = String.isSuffix "\n" x
wenzelm@8651
   178
  | is_newline _ = false;
wenzelm@8651
   179
wenzelm@5825
   180
wenzelm@14991
   181
(* token content *)
wenzelm@9155
   182
wenzelm@27814
   183
fun source_of (Token ((source, (pos, _)), _, _)) =
wenzelm@27814
   184
  YXML.string_of (XML.Elem (Markup.tokenN, Position.properties_of pos, [XML.Text source]));
wenzelm@25642
   185
wenzelm@27814
   186
fun content_of (Token (_, (_, x), _)) = x;
wenzelm@27747
   187
wenzelm@27747
   188
wenzelm@27747
   189
(* unparse *)
wenzelm@27747
   190
wenzelm@18547
   191
fun escape q =
wenzelm@18547
   192
  implode o map (fn s => if s = q orelse s = "\\" then "\\" ^ s else s) o Symbol.explode;
wenzelm@18547
   193
wenzelm@27814
   194
fun unparse (Token (_, (kind, x), _)) =
wenzelm@14991
   195
  (case kind of
wenzelm@18547
   196
    String => x |> quote o escape "\""
wenzelm@18547
   197
  | AltString => x |> enclose "`" "`" o escape "`"
wenzelm@14991
   198
  | Verbatim => x |> enclose "{*" "*}"
wenzelm@14991
   199
  | Comment => x |> enclose "(*" "*)"
wenzelm@25642
   200
  | Malformed => Output.escape (translate_string Output.output x)
wenzelm@23729
   201
  | Sync => ""
wenzelm@23729
   202
  | EOF => ""
wenzelm@14991
   203
  | _ => x);
wenzelm@14991
   204
wenzelm@23788
   205
fun text_of tok =
wenzelm@23788
   206
  if is_semicolon tok then ("terminator", "")
wenzelm@23729
   207
  else
wenzelm@23788
   208
    let
wenzelm@23788
   209
      val k = str_of_kind (kind_of tok);
wenzelm@25642
   210
      val s = unparse tok
wenzelm@27814
   211
        handle ERROR _ => Symbol.separate_chars (content_of tok);
wenzelm@23788
   212
    in
wenzelm@23788
   213
      if s = "" then (k, "")
wenzelm@23788
   214
      else if size s < 40 andalso not (exists_string (fn c => c = "\n") s) then (k ^ " " ^ s, "")
wenzelm@23788
   215
      else (k, s)
wenzelm@23788
   216
    end;
wenzelm@23729
   217
wenzelm@5825
   218
wenzelm@5825
   219
wenzelm@27814
   220
(** associated values **)
wenzelm@27814
   221
wenzelm@27814
   222
(* access values *)
wenzelm@27814
   223
wenzelm@27814
   224
fun get_value (Token (_, _, Value v)) = v
wenzelm@27814
   225
  | get_value _ = NONE;
wenzelm@27814
   226
wenzelm@27814
   227
fun map_value f (Token (x, y, Value (SOME v))) = Token (x, y, Value (SOME (f v)))
wenzelm@27814
   228
  | map_value _ tok = tok;
wenzelm@27814
   229
wenzelm@27814
   230
wenzelm@27814
   231
(* make values *)
wenzelm@27814
   232
wenzelm@27814
   233
fun mk_value k v = Token ((k, Position.no_range), (InternalValue, k), Value (SOME v));
wenzelm@27814
   234
wenzelm@27814
   235
val mk_text = mk_value "<text>" o Text;
wenzelm@27814
   236
val mk_typ = mk_value "<typ>" o Typ;
wenzelm@27814
   237
val mk_term = mk_value "<term>" o Term;
wenzelm@27814
   238
val mk_fact = mk_value "<fact>" o Fact;
wenzelm@27814
   239
val mk_attribute = mk_value "<attribute>" o Attribute;
wenzelm@27814
   240
wenzelm@27814
   241
wenzelm@27814
   242
(* static binding *)
wenzelm@27814
   243
wenzelm@27814
   244
(*1st stage: make empty slots assignable*)
wenzelm@27814
   245
fun assignable (Token (x, y, Slot)) = Token (x, y, Assignable (ref NONE))
wenzelm@27814
   246
  | assignable tok = tok;
wenzelm@27814
   247
wenzelm@27814
   248
(*2nd stage: assign values as side-effect of scanning*)
wenzelm@27814
   249
fun assign v (Token (_, _, Assignable r)) = r := v
wenzelm@27814
   250
  | assign _ _ = ();
wenzelm@27814
   251
wenzelm@27814
   252
(*3rd stage: static closure of final values*)
wenzelm@27814
   253
fun closure (Token (x, y, Assignable (ref v))) = Token (x, y, Value v)
wenzelm@27814
   254
  | closure tok = tok;
wenzelm@27814
   255
wenzelm@27814
   256
wenzelm@27814
   257
wenzelm@5825
   258
(** scanners **)
wenzelm@5825
   259
wenzelm@27769
   260
open BasicSymbolPos;
wenzelm@5825
   261
wenzelm@27769
   262
fun !!! msg = SymbolPos.!!! ("Outer lexical error: " ^ msg);
wenzelm@5825
   263
wenzelm@27769
   264
fun change_prompt scan = Scan.prompt "# " scan;
wenzelm@5825
   265
wenzelm@5825
   266
wenzelm@5825
   267
(* scan symbolic idents *)
wenzelm@5825
   268
wenzelm@20664
   269
val is_sym_char = member (op =) (explode "!#$%&*+-/<=>?@^_|~");
wenzelm@5825
   270
wenzelm@8231
   271
val scan_symid =
wenzelm@27769
   272
  Scan.many1 (is_sym_char o symbol) ||
wenzelm@27769
   273
  Scan.one (Symbol.is_symbolic o symbol) >> single;
wenzelm@5825
   274
wenzelm@8231
   275
fun is_symid str =
wenzelm@8231
   276
  (case try Symbol.explode str of
skalberg@15531
   277
    SOME [s] => Symbol.is_symbolic s orelse is_sym_char s
skalberg@15531
   278
  | SOME ss => forall is_sym_char ss
wenzelm@8231
   279
  | _ => false);
wenzelm@8231
   280
wenzelm@27814
   281
fun ident_or_symbolic "begin" = false
wenzelm@27814
   282
  | ident_or_symbolic ":" = true
wenzelm@27814
   283
  | ident_or_symbolic "::" = true
wenzelm@27814
   284
  | ident_or_symbolic s = Syntax.is_identifier s orelse is_symid s;
wenzelm@5825
   285
wenzelm@5825
   286
wenzelm@5825
   287
(* scan strings *)
wenzelm@5825
   288
wenzelm@17164
   289
local
wenzelm@17164
   290
wenzelm@25579
   291
val char_code =
wenzelm@27769
   292
  Scan.one (Symbol.is_ascii_digit o symbol) --
wenzelm@27769
   293
  Scan.one (Symbol.is_ascii_digit o symbol) --
wenzelm@27769
   294
  Scan.one (Symbol.is_ascii_digit o symbol) :|--
wenzelm@27769
   295
  (fn (((a, pos), (b, _)), (c, _)) =>
wenzelm@25579
   296
    let val (n, _) = Library.read_int [a, b, c]
wenzelm@27769
   297
    in if n <= 255 then Scan.succeed [(chr n, pos)] else Scan.fail end);
wenzelm@25579
   298
wenzelm@17164
   299
fun scan_str q =
wenzelm@27769
   300
  $$$ "\\" |-- !!! "bad escape character in string" ($$$ q || $$$ "\\" || char_code) ||
wenzelm@27769
   301
  Scan.one (fn (s, _) => s <> q andalso s <> "\\" andalso Symbol.is_regular s) >> single;
wenzelm@5825
   302
wenzelm@17164
   303
fun scan_strs q =
wenzelm@27780
   304
  (SymbolPos.scan_pos --| $$$ q) -- !!! "missing quote at end of string"
wenzelm@27780
   305
    (change_prompt ((Scan.repeat (scan_str q) >> flat) -- ($$$ q |-- SymbolPos.scan_pos)));
wenzelm@17164
   306
wenzelm@17164
   307
in
wenzelm@17164
   308
wenzelm@17164
   309
val scan_string = scan_strs "\"";
wenzelm@17164
   310
val scan_alt_string = scan_strs "`";
wenzelm@17164
   311
wenzelm@27769
   312
val scan_quoted = Scan.trace (scan_string || scan_alt_string) >> #2;
wenzelm@27752
   313
wenzelm@17164
   314
end;
wenzelm@5825
   315
wenzelm@5825
   316
wenzelm@5825
   317
(* scan verbatim text *)
wenzelm@5825
   318
wenzelm@5825
   319
val scan_verb =
wenzelm@27769
   320
  $$$ "*" --| Scan.ahead (~$$$ "}") ||
wenzelm@27769
   321
  Scan.one (fn (s, _) => s <> "*" andalso Symbol.is_regular s) >> single;
wenzelm@5825
   322
wenzelm@5825
   323
val scan_verbatim =
wenzelm@27780
   324
  (SymbolPos.scan_pos --| $$$ "{" --| $$$ "*") -- !!! "missing end of verbatim text"
wenzelm@27780
   325
    (change_prompt ((Scan.repeat scan_verb >> flat) -- ($$$ "*" |-- $$$ "}" |-- SymbolPos.scan_pos)));
wenzelm@5825
   326
wenzelm@5825
   327
wenzelm@5825
   328
(* scan space *)
wenzelm@5825
   329
wenzelm@19305
   330
fun is_space s = Symbol.is_blank s andalso s <> "\n";
wenzelm@5825
   331
wenzelm@5825
   332
val scan_space =
wenzelm@27769
   333
  Scan.many1 (is_space o symbol) @@@ Scan.optional ($$$ "\n") [] ||
wenzelm@27769
   334
  Scan.many (is_space o symbol) @@@ $$$ "\n";
wenzelm@5825
   335
wenzelm@5825
   336
wenzelm@27780
   337
(* scan comment *)
wenzelm@5825
   338
wenzelm@5825
   339
val scan_comment =
wenzelm@27780
   340
  SymbolPos.scan_pos -- (SymbolPos.scan_comment_body !!! -- SymbolPos.scan_pos);
wenzelm@5825
   341
wenzelm@5825
   342
wenzelm@23678
   343
(* scan malformed symbols *)
wenzelm@23678
   344
wenzelm@23678
   345
val scan_malformed =
wenzelm@27769
   346
  $$$ Symbol.malformed |--
wenzelm@27769
   347
    change_prompt (Scan.many (Symbol.is_regular o symbol))
wenzelm@27769
   348
  --| Scan.option ($$$ Symbol.end_malformed);
wenzelm@27752
   349
wenzelm@27752
   350
wenzelm@27663
   351
wenzelm@27769
   352
(** token sources **)
wenzelm@5825
   353
wenzelm@27769
   354
fun source_proper src = src |> Source.filter is_proper;
wenzelm@5825
   355
wenzelm@23678
   356
local
wenzelm@23678
   357
wenzelm@27769
   358
fun token_leq ((_, syms1), (_, syms2)) = length syms1 <= length syms2;
wenzelm@27780
   359
wenzelm@27799
   360
fun token k ss =
wenzelm@27814
   361
  Token ((SymbolPos.implode ss, SymbolPos.range ss), (k, SymbolPos.content ss), Slot);
wenzelm@27799
   362
wenzelm@27799
   363
fun token_range k (pos1, (ss, pos2)) =
wenzelm@27814
   364
  Token (SymbolPos.implode_range pos1 pos2 ss, (k, SymbolPos.content ss), Slot);
wenzelm@23678
   365
wenzelm@27769
   366
fun scan (lex1, lex2) = !!! "bad input"
wenzelm@27799
   367
  (scan_string >> token_range String ||
wenzelm@27799
   368
    scan_alt_string >> token_range AltString ||
wenzelm@27799
   369
    scan_verbatim >> token_range Verbatim ||
wenzelm@27799
   370
    scan_comment >> token_range Comment ||
wenzelm@27780
   371
    scan_space >> token Space ||
wenzelm@27780
   372
    scan_malformed >> token Malformed ||
wenzelm@27780
   373
    Scan.one (Symbol.is_sync o symbol) >> (token Sync o single) ||
wenzelm@27780
   374
    (Scan.max token_leq
wenzelm@27769
   375
      (Scan.max token_leq
wenzelm@27769
   376
        (Scan.literal lex2 >> pair Command)
wenzelm@27769
   377
        (Scan.literal lex1 >> pair Keyword))
wenzelm@27769
   378
      (Syntax.scan_longid >> pair LongIdent ||
wenzelm@27769
   379
        Syntax.scan_id >> pair Ident ||
wenzelm@27769
   380
        Syntax.scan_var >> pair Var ||
wenzelm@27769
   381
        Syntax.scan_tid >> pair TypeIdent ||
wenzelm@27769
   382
        Syntax.scan_tvar >> pair TypeVar ||
wenzelm@27769
   383
        Syntax.scan_nat >> pair Nat ||
wenzelm@27780
   384
        scan_symid >> pair SymIdent) >> uncurry token));
wenzelm@27769
   385
wenzelm@27769
   386
fun recover msg =
wenzelm@27769
   387
  Scan.many ((Symbol.is_regular andf (not o Symbol.is_blank)) o symbol)
wenzelm@27780
   388
  >> (single o token (Error msg));
wenzelm@23678
   389
wenzelm@23678
   390
in
wenzelm@5825
   391
wenzelm@27780
   392
fun source' do_recover get_lex =
wenzelm@27780
   393
  Source.source SymbolPos.stopper (Scan.bulk (fn xs => scan (get_lex ()) xs))
wenzelm@27780
   394
    (Option.map (rpair recover) do_recover);
wenzelm@27780
   395
wenzelm@5825
   396
fun source do_recover get_lex pos src =
wenzelm@27769
   397
  SymbolPos.source pos src
wenzelm@27780
   398
  |> source' do_recover get_lex;
wenzelm@23678
   399
wenzelm@23678
   400
end;
wenzelm@5825
   401
wenzelm@5825
   402
end;