src/Pure/Isar/token.ML
author wenzelm
Fri Mar 01 16:49:41 2019 +0100 (4 months ago ago)
changeset 70032 29a4f633609e
parent 68730 0bc491938780
child 70072 def3ec9cdb7e
permissions -rw-r--r--
clarified signature;
more thorough end_pos;
wenzelm@36959
     1
(*  Title:      Pure/Isar/token.ML
wenzelm@5825
     2
    Author:     Markus Wenzel, TU Muenchen
wenzelm@5825
     3
wenzelm@36959
     4
Outer token syntax for Isabelle/Isar.
wenzelm@5825
     5
*)
wenzelm@5825
     6
wenzelm@36959
     7
signature TOKEN =
wenzelm@5825
     8
sig
wenzelm@36959
     9
  datatype kind =
wenzelm@59081
    10
    (*immediate source*)
wenzelm@59081
    11
    Command | Keyword | Ident | Long_Ident | Sym_Ident | Var | Type_Ident | Type_Var | Nat |
wenzelm@59081
    12
    Float | Space |
wenzelm@59081
    13
    (*delimited content*)
wenzelm@67439
    14
    String | Alt_String | Verbatim | Cartouche | Comment of Comment.kind option |
wenzelm@59081
    15
    (*special content*)
wenzelm@61819
    16
    Error of string | EOF
wenzelm@58012
    17
  val str_of_kind: kind -> string
wenzelm@55788
    18
  type file = {src_path: Path.T, lines: string list, digest: SHA1.digest, pos: Position.T}
wenzelm@58012
    19
  type T
wenzelm@61814
    20
  type src = T list
wenzelm@61814
    21
  type name_value = {name: string, kind: string, print: Proof.context -> Markup.T * xstring}
wenzelm@27814
    22
  datatype value =
wenzelm@58012
    23
    Source of src |
wenzelm@57944
    24
    Literal of bool * Markup.T |
wenzelm@61814
    25
    Name of name_value * morphism |
wenzelm@57944
    26
    Typ of typ |
wenzelm@57944
    27
    Term of term |
wenzelm@57942
    28
    Fact of string option * thm list |
wenzelm@57944
    29
    Attribute of morphism -> attribute |
wenzelm@58017
    30
    Declaration of declaration |
wenzelm@57944
    31
    Files of file Exn.result list
wenzelm@55708
    32
  val pos_of: T -> Position.T
wenzelm@55709
    33
  val range_of: T list -> Position.range
wenzelm@68184
    34
  val adjust_offsets: (int -> int option) -> T -> T
wenzelm@36959
    35
  val eof: T
wenzelm@36959
    36
  val is_eof: T -> bool
wenzelm@36959
    37
  val not_eof: T -> bool
wenzelm@36959
    38
  val stopper: T Scan.stopper
wenzelm@36959
    39
  val kind_of: T -> kind
wenzelm@36959
    40
  val is_kind: kind -> T -> bool
wenzelm@46811
    41
  val is_command: T -> bool
wenzelm@59924
    42
  val keyword_with: (string -> bool) -> T -> bool
wenzelm@59939
    43
  val is_command_modifier: T -> bool
wenzelm@59924
    44
  val ident_with: (string -> bool) -> T -> bool
wenzelm@36959
    45
  val is_proper: T -> bool
wenzelm@36959
    46
  val is_comment: T -> bool
wenzelm@67439
    47
  val is_informal_comment: T -> bool
wenzelm@67439
    48
  val is_formal_comment: T -> bool
wenzelm@68729
    49
  val is_ignored: T -> bool
wenzelm@36959
    50
  val is_begin_ignore: T -> bool
wenzelm@36959
    51
  val is_end_ignore: T -> bool
wenzelm@48749
    52
  val is_error: T -> bool
wenzelm@48771
    53
  val is_space: T -> bool
wenzelm@36959
    54
  val is_blank: T -> bool
wenzelm@36959
    55
  val is_newline: T -> bool
wenzelm@59795
    56
  val content_of: T -> string
wenzelm@68298
    57
  val source_of: T -> string
wenzelm@59809
    58
  val input_of: T -> Input.source
wenzelm@59795
    59
  val inner_syntax_of: T -> string
wenzelm@56202
    60
  val keyword_markup: bool * Markup.T -> string -> Markup.T
wenzelm@55915
    61
  val completion_report: T -> Position.report_text list
wenzelm@59125
    62
  val reports: Keyword.keywords -> T -> Position.report_text list
wenzelm@59125
    63
  val markups: Keyword.keywords -> T -> Markup.T list
wenzelm@36959
    64
  val unparse: T -> string
wenzelm@55745
    65
  val print: T -> string
wenzelm@36959
    66
  val text_of: T -> string * string
wenzelm@70032
    67
  val file_source: file -> Input.source
wenzelm@54520
    68
  val get_files: T -> file Exn.result list
wenzelm@54520
    69
  val put_files: file Exn.result list -> T -> T
wenzelm@36959
    70
  val get_value: T -> value option
wenzelm@61822
    71
  val reports_of_value: T -> Position.report list
wenzelm@61814
    72
  val name_value: name_value -> value
wenzelm@61814
    73
  val get_name: T -> name_value option
wenzelm@59646
    74
  val declare_maxidx: T -> Proof.context -> Proof.context
wenzelm@61820
    75
  val map_facts: (string option -> thm list -> thm list) -> T -> T
wenzelm@67652
    76
  val trim_context_src: src -> src
wenzelm@58011
    77
  val transform: morphism -> T -> T
wenzelm@55914
    78
  val init_assignable: T -> T
wenzelm@61814
    79
  val assign: value option -> T -> T
wenzelm@61814
    80
  val evaluate: ('a -> value) -> (T -> 'a) -> T -> 'a
wenzelm@36959
    81
  val closure: T -> T
wenzelm@58012
    82
  val pretty_value: Proof.context -> T -> Pretty.T
wenzelm@61814
    83
  val name_of_src: src -> string * Position.T
wenzelm@61814
    84
  val args_of_src: src -> T list
wenzelm@61814
    85
  val checked_src: src -> bool
wenzelm@61814
    86
  val check_src: Proof.context -> (Proof.context -> 'a Name_Space.table) -> src -> src * 'a
wenzelm@58011
    87
  val pretty_src: Proof.context -> src -> Pretty.T
wenzelm@27814
    88
  val ident_or_symbolic: string -> bool
wenzelm@61471
    89
  val read_cartouche: Symbol_Pos.T list -> T
wenzelm@67497
    90
  val tokenize: Keyword.keywords -> {strict: bool} -> Symbol_Pos.T list -> T list
wenzelm@59083
    91
  val explode: Keyword.keywords -> Position.T -> string -> T list
wenzelm@67495
    92
  val explode0: Keyword.keywords -> string -> T list
wenzelm@63640
    93
  val print_name: Keyword.keywords -> string -> string
wenzelm@59085
    94
  val make: (int * int) * string -> Position.T -> T * Position.T
wenzelm@61814
    95
  val make_string: string * Position.T -> T
wenzelm@63019
    96
  val make_int: int -> T list
wenzelm@61814
    97
  val make_src: string * Position.T -> T list -> src
wenzelm@58011
    98
  type 'a parser = T list -> 'a * T list
wenzelm@58011
    99
  type 'a context_parser = Context.generic * T list -> 'a * (Context.generic * T list)
wenzelm@67504
   100
  val read_body: Keyword.keywords -> 'a parser -> Symbol_Pos.T list -> 'a option
wenzelm@58903
   101
  val read_antiq: Keyword.keywords -> 'a parser -> Symbol_Pos.T list * Position.T -> 'a
wenzelm@58011
   102
  val syntax_generic: 'a context_parser -> src -> Context.generic -> 'a * Context.generic
wenzelm@58011
   103
  val syntax: 'a context_parser -> src -> Proof.context -> 'a * Proof.context
wenzelm@5825
   104
end;
wenzelm@5825
   105
wenzelm@36959
   106
structure Token: TOKEN =
wenzelm@5825
   107
struct
wenzelm@5825
   108
wenzelm@5825
   109
(** tokens **)
wenzelm@5825
   110
wenzelm@58012
   111
(* token kind *)
wenzelm@5825
   112
wenzelm@36959
   113
datatype kind =
wenzelm@59081
   114
  (*immediate source*)
wenzelm@59081
   115
  Command | Keyword | Ident | Long_Ident | Sym_Ident | Var | Type_Ident | Type_Var | Nat |
wenzelm@59081
   116
  Float | Space |
wenzelm@59081
   117
  (*delimited content*)
wenzelm@67439
   118
  String | Alt_String | Verbatim | Cartouche | Comment of Comment.kind option |
wenzelm@59081
   119
  (*special content*)
wenzelm@61819
   120
  Error of string | EOF;
wenzelm@5825
   121
wenzelm@5825
   122
val str_of_kind =
wenzelm@7026
   123
 fn Command => "command"
wenzelm@7026
   124
  | Keyword => "keyword"
wenzelm@5825
   125
  | Ident => "identifier"
wenzelm@59081
   126
  | Long_Ident => "long identifier"
wenzelm@59081
   127
  | Sym_Ident => "symbolic identifier"
wenzelm@5825
   128
  | Var => "schematic variable"
wenzelm@59081
   129
  | Type_Ident => "type variable"
wenzelm@59081
   130
  | Type_Var => "schematic type variable"
wenzelm@40290
   131
  | Nat => "natural number"
wenzelm@40290
   132
  | Float => "floating-point number"
wenzelm@59081
   133
  | Space => "white space"
wenzelm@55103
   134
  | String => "quoted string"
wenzelm@59081
   135
  | Alt_String => "back-quoted string"
wenzelm@5825
   136
  | Verbatim => "verbatim text"
wenzelm@55103
   137
  | Cartouche => "text cartouche"
wenzelm@67439
   138
  | Comment NONE => "informal comment"
wenzelm@67439
   139
  | Comment (SOME _) => "formal comment"
wenzelm@23729
   140
  | Error _ => "bad input"
wenzelm@48911
   141
  | EOF => "end-of-input";
wenzelm@5825
   142
wenzelm@59085
   143
val immediate_kinds =
wenzelm@59085
   144
  Vector.fromList
wenzelm@59085
   145
    [Command, Keyword, Ident, Long_Ident, Sym_Ident, Var, Type_Ident, Type_Var, Nat, Float, Space];
wenzelm@59085
   146
wenzelm@67439
   147
val delimited_kind =
wenzelm@67439
   148
  (fn String => true
wenzelm@67439
   149
    | Alt_String => true
wenzelm@67439
   150
    | Verbatim => true
wenzelm@67439
   151
    | Cartouche => true
wenzelm@67439
   152
    | Comment _ => true
wenzelm@67439
   153
    | _ => false);
wenzelm@55828
   154
wenzelm@5825
   155
wenzelm@58012
   156
(* datatype token *)
wenzelm@58012
   157
wenzelm@58012
   158
(*The value slot assigns an (optional) internal value to a token,
wenzelm@58012
   159
  usually as a side-effect of special scanner setup (see also
wenzelm@58012
   160
  args.ML).  Note that an assignable ref designates an intermediate
wenzelm@58012
   161
  state of internalization -- it is NOT meant to persist.*)
wenzelm@58012
   162
wenzelm@58012
   163
type file = {src_path: Path.T, lines: string list, digest: SHA1.digest, pos: Position.T};
wenzelm@58012
   164
wenzelm@61814
   165
type name_value = {name: string, kind: string, print: Proof.context -> Markup.T * xstring};
wenzelm@58012
   166
wenzelm@61814
   167
datatype T = Token of (Symbol_Pos.text * Position.range) * (kind * string) * slot
wenzelm@58012
   168
wenzelm@58012
   169
and slot =
wenzelm@58012
   170
  Slot |
wenzelm@58012
   171
  Value of value option |
wenzelm@58012
   172
  Assignable of value option Unsynchronized.ref
wenzelm@58012
   173
wenzelm@58012
   174
and value =
wenzelm@61814
   175
  Source of T list |
wenzelm@58012
   176
  Literal of bool * Markup.T |
wenzelm@61814
   177
  Name of name_value * morphism |
wenzelm@58012
   178
  Typ of typ |
wenzelm@58012
   179
  Term of term |
wenzelm@58012
   180
  Fact of string option * thm list |  (*optional name for dynamic fact, i.e. fact "variable"*)
wenzelm@58012
   181
  Attribute of morphism -> attribute |
wenzelm@58017
   182
  Declaration of declaration |
wenzelm@58012
   183
  Files of file Exn.result list;
wenzelm@58012
   184
wenzelm@61814
   185
type src = T list;
wenzelm@58012
   186
wenzelm@58012
   187
wenzelm@27733
   188
(* position *)
wenzelm@5825
   189
wenzelm@55708
   190
fun pos_of (Token ((_, (pos, _)), _, _)) = pos;
wenzelm@55708
   191
fun end_pos_of (Token ((_, (_, pos)), _, _)) = pos;
wenzelm@27663
   192
wenzelm@55709
   193
fun range_of (toks as tok :: _) =
wenzelm@55709
   194
      let val pos' = end_pos_of (List.last toks)
wenzelm@62797
   195
      in Position.range (pos_of tok, pos') end
wenzelm@55709
   196
  | range_of [] = Position.no_range;
wenzelm@5825
   197
wenzelm@68184
   198
fun adjust_offsets adjust (Token ((x, range), y, z)) =
wenzelm@68184
   199
  Token ((x, apply2 (Position.adjust_offsets adjust) range), y, z);
wenzelm@68184
   200
wenzelm@5825
   201
wenzelm@58855
   202
(* stopper *)
wenzelm@27733
   203
wenzelm@27814
   204
fun mk_eof pos = Token (("", (pos, Position.none)), (EOF, ""), Slot);
wenzelm@27733
   205
val eof = mk_eof Position.none;
wenzelm@27733
   206
wenzelm@27814
   207
fun is_eof (Token (_, (EOF, _), _)) = true
wenzelm@27733
   208
  | is_eof _ = false;
wenzelm@27733
   209
wenzelm@27733
   210
val not_eof = not o is_eof;
wenzelm@27733
   211
wenzelm@27752
   212
val stopper =
wenzelm@55708
   213
  Scan.stopper (fn [] => eof | toks => mk_eof (end_pos_of (List.last toks))) is_eof;
wenzelm@27733
   214
wenzelm@27733
   215
wenzelm@5825
   216
(* kind of token *)
wenzelm@5825
   217
wenzelm@27814
   218
fun kind_of (Token (_, (k, _), _)) = k;
wenzelm@27814
   219
fun is_kind k (Token (_, (k', _), _)) = k = k';
wenzelm@5825
   220
wenzelm@46811
   221
val is_command = is_kind Command;
wenzelm@59123
   222
wenzelm@27814
   223
fun keyword_with pred (Token (_, (Keyword, x), _)) = pred x
wenzelm@7026
   224
  | keyword_with _ _ = false;
wenzelm@5825
   225
wenzelm@59990
   226
val is_command_modifier = keyword_with (fn x => x = "private" orelse x = "qualified");
wenzelm@59924
   227
wenzelm@27814
   228
fun ident_with pred (Token (_, (Ident, x), _)) = pred x
wenzelm@16029
   229
  | ident_with _ _ = false;
wenzelm@16029
   230
wenzelm@68729
   231
fun is_ignored (Token (_, (Space, _), _)) = true
wenzelm@68729
   232
  | is_ignored (Token (_, (Comment NONE, _), _)) = true
wenzelm@68729
   233
  | is_ignored _ = false;
wenzelm@68729
   234
wenzelm@27814
   235
fun is_proper (Token (_, (Space, _), _)) = false
wenzelm@67439
   236
  | is_proper (Token (_, (Comment _, _), _)) = false
wenzelm@5825
   237
  | is_proper _ = true;
wenzelm@5825
   238
wenzelm@67439
   239
fun is_comment (Token (_, (Comment _, _), _)) = true
wenzelm@17069
   240
  | is_comment _ = false;
wenzelm@17069
   241
wenzelm@67439
   242
fun is_informal_comment (Token (_, (Comment NONE, _), _)) = true
wenzelm@67439
   243
  | is_informal_comment _ = false;
wenzelm@67439
   244
wenzelm@67439
   245
fun is_formal_comment (Token (_, (Comment (SOME _), _), _)) = true
wenzelm@67439
   246
  | is_formal_comment _ = false;
wenzelm@67439
   247
wenzelm@67439
   248
fun is_begin_ignore (Token (_, (Comment NONE, "<"), _)) = true
wenzelm@8580
   249
  | is_begin_ignore _ = false;
wenzelm@8580
   250
wenzelm@67439
   251
fun is_end_ignore (Token (_, (Comment NONE, ">"), _)) = true
wenzelm@8580
   252
  | is_end_ignore _ = false;
wenzelm@8580
   253
wenzelm@48749
   254
fun is_error (Token (_, (Error _, _), _)) = true
wenzelm@48749
   255
  | is_error _ = false;
wenzelm@48749
   256
wenzelm@8651
   257
wenzelm@17069
   258
(* blanks and newlines -- space tokens obey lines *)
wenzelm@8651
   259
wenzelm@48771
   260
fun is_space (Token (_, (Space, _), _)) = true
wenzelm@48771
   261
  | is_space _ = false;
wenzelm@48771
   262
wenzelm@27814
   263
fun is_blank (Token (_, (Space, x), _)) = not (String.isSuffix "\n" x)
wenzelm@17069
   264
  | is_blank _ = false;
wenzelm@17069
   265
wenzelm@27814
   266
fun is_newline (Token (_, (Space, x), _)) = String.isSuffix "\n" x
wenzelm@8651
   267
  | is_newline _ = false;
wenzelm@8651
   268
wenzelm@5825
   269
wenzelm@14991
   270
(* token content *)
wenzelm@9155
   271
wenzelm@59795
   272
fun content_of (Token (_, (_, x), _)) = x;
wenzelm@68298
   273
fun source_of (Token ((source, _), _, _)) = source;
wenzelm@25642
   274
wenzelm@59809
   275
fun input_of (Token ((source, range), (kind, _), _)) =
wenzelm@59064
   276
  Input.source (delimited_kind kind) source range;
wenzelm@27873
   277
wenzelm@59795
   278
fun inner_syntax_of tok =
wenzelm@59795
   279
  let val x = content_of tok
wenzelm@59809
   280
  in if YXML.detect x then x else Syntax.implode_input (input_of tok) end;
wenzelm@27747
   281
wenzelm@27747
   282
wenzelm@55915
   283
(* markup reports *)
wenzelm@55744
   284
wenzelm@55744
   285
local
wenzelm@55744
   286
wenzelm@55744
   287
val token_kind_markup =
wenzelm@59124
   288
 fn Var => (Markup.var, "")
wenzelm@59081
   289
  | Type_Ident => (Markup.tfree, "")
wenzelm@59081
   290
  | Type_Var => (Markup.tvar, "")
wenzelm@59081
   291
  | String => (Markup.string, "")
wenzelm@59081
   292
  | Alt_String => (Markup.alt_string, "")
wenzelm@59081
   293
  | Verbatim => (Markup.verbatim, "")
wenzelm@59081
   294
  | Cartouche => (Markup.cartouche, "")
wenzelm@67440
   295
  | Comment _ => (Markup.comment, "")
wenzelm@64677
   296
  | Error msg => (Markup.bad (), msg)
wenzelm@59124
   297
  | _ => (Markup.empty, "");
wenzelm@55744
   298
wenzelm@59125
   299
fun keyword_reports tok = map (fn markup => ((pos_of tok, markup), ""));
wenzelm@59123
   300
wenzelm@59125
   301
fun command_markups keywords x =
wenzelm@66067
   302
  if Keyword.is_theory_end keywords x then [Markup.keyword2 |> Markup.keyword_properties]
wenzelm@65174
   303
  else
wenzelm@65174
   304
    (if Keyword.is_proof_asm keywords x then [Markup.keyword3]
wenzelm@65174
   305
     else if Keyword.is_improper keywords x then [Markup.keyword1, Markup.improper]
wenzelm@65174
   306
     else [Markup.keyword1])
wenzelm@66066
   307
    |> map Markup.command_properties;
wenzelm@59123
   308
wenzelm@56063
   309
in
wenzelm@56063
   310
wenzelm@56202
   311
fun keyword_markup (important, keyword) x =
wenzelm@56202
   312
  if important orelse Symbol.is_ascii_identifier x then keyword else Markup.delimiter;
wenzelm@55919
   313
wenzelm@55915
   314
fun completion_report tok =
wenzelm@55914
   315
  if is_kind Keyword tok
wenzelm@55915
   316
  then map (fn m => ((pos_of tok, m), "")) (Completion.suppress_abbrevs (content_of tok))
wenzelm@55915
   317
  else [];
wenzelm@55744
   318
wenzelm@59125
   319
fun reports keywords tok =
wenzelm@59123
   320
  if is_command tok then
wenzelm@59125
   321
    keyword_reports tok (command_markups keywords (content_of tok))
wenzelm@59123
   322
  else if is_kind Keyword tok then
wenzelm@66044
   323
    keyword_reports tok
wenzelm@66067
   324
      [keyword_markup (false, Markup.keyword2 |> Markup.keyword_properties) (content_of tok)]
wenzelm@55915
   325
  else
wenzelm@68298
   326
    let
wenzelm@68298
   327
      val pos = pos_of tok;
wenzelm@68298
   328
      val (m, text) = token_kind_markup (kind_of tok);
wenzelm@68298
   329
      val delete = #2 (Symbol_Pos.explode_delete (source_of tok, pos));
wenzelm@68298
   330
    in ((pos, m), text) :: map (fn p => ((p, Markup.delete), "")) delete end;
wenzelm@55915
   331
wenzelm@59125
   332
fun markups keywords = map (#2 o #1) o reports keywords;
wenzelm@55914
   333
wenzelm@55744
   334
end;
wenzelm@55744
   335
wenzelm@55744
   336
wenzelm@27747
   337
(* unparse *)
wenzelm@27747
   338
wenzelm@27814
   339
fun unparse (Token (_, (kind, x), _)) =
wenzelm@14991
   340
  (case kind of
wenzelm@43773
   341
    String => Symbol_Pos.quote_string_qq x
wenzelm@59081
   342
  | Alt_String => Symbol_Pos.quote_string_bq x
wenzelm@43773
   343
  | Verbatim => enclose "{*" "*}" x
wenzelm@55033
   344
  | Cartouche => cartouche x
wenzelm@67439
   345
  | Comment NONE => enclose "(*" "*)" x
wenzelm@23729
   346
  | EOF => ""
wenzelm@14991
   347
  | _ => x);
wenzelm@14991
   348
wenzelm@59125
   349
fun print tok = Markup.markups (markups Keyword.empty_keywords tok) (unparse tok);
wenzelm@55745
   350
wenzelm@23788
   351
fun text_of tok =
wenzelm@58861
   352
  let
wenzelm@58861
   353
    val k = str_of_kind (kind_of tok);
wenzelm@59125
   354
    val ms = markups Keyword.empty_keywords tok;
wenzelm@58861
   355
    val s = unparse tok;
wenzelm@58861
   356
  in
wenzelm@58861
   357
    if s = "" then (k, "")
wenzelm@58861
   358
    else if size s < 40 andalso not (exists_string (fn c => c = "\n") s)
wenzelm@59125
   359
    then (k ^ " " ^ Markup.markups ms s, "")
wenzelm@59125
   360
    else (k, Markup.markups ms s)
wenzelm@58861
   361
  end;
wenzelm@23729
   362
wenzelm@5825
   363
wenzelm@5825
   364
wenzelm@27814
   365
(** associated values **)
wenzelm@27814
   366
wenzelm@48867
   367
(* inlined file content *)
wenzelm@48867
   368
wenzelm@70032
   369
fun file_source (file: file) =
wenzelm@70032
   370
  let
wenzelm@70032
   371
    val text = cat_lines (#lines file);
wenzelm@70032
   372
    val end_pos = fold Position.advance (Symbol.explode text) (#pos file);
wenzelm@70032
   373
  in Input.source true text (Position.range (#pos file, end_pos)) end;
wenzelm@70032
   374
wenzelm@54519
   375
fun get_files (Token (_, _, Value (SOME (Files files)))) = files
wenzelm@54519
   376
  | get_files _ = [];
wenzelm@48867
   377
wenzelm@54519
   378
fun put_files [] tok = tok
wenzelm@54519
   379
  | put_files files (Token (x, y, Slot)) = Token (x, y, Value (SOME (Files files)))
wenzelm@55708
   380
  | put_files _ tok = raise Fail ("Cannot put inlined files here" ^ Position.here (pos_of tok));
wenzelm@48867
   381
wenzelm@48867
   382
wenzelm@27814
   383
(* access values *)
wenzelm@27814
   384
wenzelm@27814
   385
fun get_value (Token (_, _, Value v)) = v
wenzelm@27814
   386
  | get_value _ = NONE;
wenzelm@27814
   387
wenzelm@27814
   388
fun map_value f (Token (x, y, Value (SOME v))) = Token (x, y, Value (SOME (f v)))
wenzelm@27814
   389
  | map_value _ tok = tok;
wenzelm@27814
   390
wenzelm@61814
   391
wenzelm@61822
   392
(* reports of value *)
wenzelm@61814
   393
wenzelm@61822
   394
fun get_assignable_value (Token (_, _, Assignable r)) = ! r
wenzelm@61822
   395
  | get_assignable_value (Token (_, _, Value v)) = v
wenzelm@61822
   396
  | get_assignable_value _ = NONE;
wenzelm@60211
   397
wenzelm@55914
   398
fun reports_of_value tok =
wenzelm@60211
   399
  (case get_assignable_value tok of
wenzelm@56063
   400
    SOME (Literal markup) =>
wenzelm@56063
   401
      let
wenzelm@56063
   402
        val pos = pos_of tok;
wenzelm@56063
   403
        val x = content_of tok;
wenzelm@56063
   404
      in
wenzelm@56063
   405
        if Position.is_reported pos then
wenzelm@56063
   406
          map (pair pos) (keyword_markup markup x :: Completion.suppress_abbrevs x)
wenzelm@56063
   407
        else []
wenzelm@56063
   408
      end
wenzelm@56063
   409
  | _ => []);
wenzelm@55914
   410
wenzelm@27814
   411
wenzelm@61822
   412
(* name value *)
wenzelm@61822
   413
wenzelm@61822
   414
fun name_value a = Name (a, Morphism.identity);
wenzelm@61822
   415
wenzelm@61822
   416
fun get_name tok =
wenzelm@61822
   417
  (case get_assignable_value tok of
wenzelm@61822
   418
    SOME (Name (a, _)) => SOME a
wenzelm@61822
   419
  | _ => NONE);
wenzelm@61822
   420
wenzelm@61822
   421
wenzelm@59646
   422
(* maxidx *)
wenzelm@59646
   423
wenzelm@59646
   424
fun declare_maxidx tok =
wenzelm@59646
   425
  (case get_value tok of
wenzelm@61814
   426
    SOME (Source src) => fold declare_maxidx src
wenzelm@59646
   427
  | SOME (Typ T) => Variable.declare_maxidx (Term.maxidx_of_typ T)
wenzelm@59646
   428
  | SOME (Term t) => Variable.declare_maxidx (Term.maxidx_of_term t)
wenzelm@59646
   429
  | SOME (Fact (_, ths)) => fold (Variable.declare_maxidx o Thm.maxidx_of) ths
wenzelm@59646
   430
  | SOME (Attribute _) => I  (* FIXME !? *)
wenzelm@59646
   431
  | SOME (Declaration decl) =>
wenzelm@59646
   432
      (fn ctxt =>
wenzelm@59646
   433
        let val ctxt' = Context.proof_map (Morphism.form decl) ctxt
wenzelm@59646
   434
        in Variable.declare_maxidx (Variable.maxidx_of ctxt') ctxt end)
wenzelm@61814
   435
  | _ => I);
wenzelm@59646
   436
wenzelm@59646
   437
wenzelm@61080
   438
(* fact values *)
wenzelm@61080
   439
wenzelm@61080
   440
fun map_facts f =
wenzelm@61080
   441
  map_value (fn v =>
wenzelm@61080
   442
    (case v of
wenzelm@61814
   443
      Source src => Source (map (map_facts f) src)
wenzelm@61820
   444
    | Fact (a, ths) => Fact (a, f a ths)
wenzelm@61814
   445
    | _ => v));
wenzelm@61080
   446
wenzelm@67652
   447
val trim_context_src = (map o map_facts) (K (map Thm.trim_context));
wenzelm@67652
   448
wenzelm@61080
   449
wenzelm@58012
   450
(* transform *)
wenzelm@58012
   451
wenzelm@58012
   452
fun transform phi =
wenzelm@58012
   453
  map_value (fn v =>
wenzelm@58012
   454
    (case v of
wenzelm@61814
   455
      Source src => Source (map (transform phi) src)
wenzelm@58012
   456
    | Literal _ => v
wenzelm@58012
   457
    | Name (a, psi) => Name (a, psi $> phi)
wenzelm@58012
   458
    | Typ T => Typ (Morphism.typ phi T)
wenzelm@58012
   459
    | Term t => Term (Morphism.term phi t)
wenzelm@58012
   460
    | Fact (a, ths) => Fact (a, Morphism.fact phi ths)
wenzelm@58012
   461
    | Attribute att => Attribute (Morphism.transform phi att)
wenzelm@58017
   462
    | Declaration decl => Declaration (Morphism.transform phi decl)
wenzelm@61814
   463
    | Files _ => v));
wenzelm@58012
   464
wenzelm@58012
   465
wenzelm@58012
   466
(* static binding *)
wenzelm@58012
   467
wenzelm@58012
   468
(*1st stage: initialize assignable slots*)
wenzelm@61814
   469
fun init_assignable tok =
wenzelm@61814
   470
  (case tok of
wenzelm@61814
   471
    Token (x, y, Slot) => Token (x, y, Assignable (Unsynchronized.ref NONE))
wenzelm@61814
   472
  | Token (_, _, Value _) => tok
wenzelm@61814
   473
  | Token (_, _, Assignable r) => (r := NONE; tok));
wenzelm@58012
   474
wenzelm@58012
   475
(*2nd stage: assign values as side-effect of scanning*)
wenzelm@61814
   476
fun assign v tok =
wenzelm@61814
   477
  (case tok of
wenzelm@61814
   478
    Token (x, y, Slot) => Token (x, y, Value v)
wenzelm@61814
   479
  | Token (_, _, Value _) => tok
wenzelm@61814
   480
  | Token (_, _, Assignable r) => (r := v; tok));
wenzelm@61814
   481
wenzelm@61814
   482
fun evaluate mk eval arg =
wenzelm@61814
   483
  let val x = eval arg in (assign (SOME (mk x)) arg; x) end;
wenzelm@58012
   484
wenzelm@58012
   485
(*3rd stage: static closure of final values*)
wenzelm@58012
   486
fun closure (Token (x, y, Assignable (Unsynchronized.ref v))) = Token (x, y, Value v)
wenzelm@58012
   487
  | closure tok = tok;
wenzelm@58012
   488
wenzelm@58012
   489
wenzelm@58012
   490
(* pretty *)
wenzelm@57944
   491
wenzelm@57944
   492
fun pretty_value ctxt tok =
wenzelm@57944
   493
  (case get_value tok of
wenzelm@57944
   494
    SOME (Literal markup) =>
wenzelm@57944
   495
      let val x = content_of tok
wenzelm@57944
   496
      in Pretty.mark_str (keyword_markup markup x, x) end
wenzelm@61814
   497
  | SOME (Name ({print, ...}, _)) => Pretty.quote (Pretty.mark_str (print ctxt))
wenzelm@57944
   498
  | SOME (Typ T) => Syntax.pretty_typ ctxt T
wenzelm@57944
   499
  | SOME (Term t) => Syntax.pretty_term ctxt t
wenzelm@57944
   500
  | SOME (Fact (_, ths)) =>
wenzelm@62094
   501
      Pretty.enclose "(" ")" (Pretty.breaks (map (Pretty.cartouche o Thm.pretty_thm ctxt) ths))
wenzelm@59125
   502
  | _ => Pretty.marks_str (markups Keyword.empty_keywords tok, unparse tok));
wenzelm@57944
   503
wenzelm@61814
   504
wenzelm@61814
   505
(* src *)
wenzelm@61814
   506
wenzelm@61825
   507
fun dest_src ([]: src) = raise Fail "Empty token source"
wenzelm@61814
   508
  | dest_src (head :: args) = (head, args);
wenzelm@61814
   509
wenzelm@61814
   510
fun name_of_src src =
wenzelm@61814
   511
  let
wenzelm@61814
   512
    val head = #1 (dest_src src);
wenzelm@61814
   513
    val name =
wenzelm@61814
   514
      (case get_name head of
wenzelm@61814
   515
        SOME {name, ...} => name
wenzelm@61814
   516
      | NONE => content_of head);
wenzelm@61814
   517
  in (name, pos_of head) end;
wenzelm@61814
   518
wenzelm@61814
   519
val args_of_src = #2 o dest_src;
wenzelm@61814
   520
wenzelm@58011
   521
fun pretty_src ctxt src =
wenzelm@58011
   522
  let
wenzelm@61814
   523
    val (head, args) = dest_src src;
wenzelm@58011
   524
    val prt_name =
wenzelm@61814
   525
      (case get_name head of
wenzelm@61814
   526
        SOME {print, ...} => Pretty.mark_str (print ctxt)
wenzelm@61814
   527
      | NONE => Pretty.str (content_of head));
wenzelm@61814
   528
  in Pretty.block (Pretty.breaks (Pretty.quote prt_name :: map (pretty_value ctxt) args)) end;
wenzelm@61814
   529
wenzelm@61814
   530
fun checked_src (head :: _) = is_some (get_name head)
wenzelm@61814
   531
  | checked_src [] = true;
wenzelm@61814
   532
wenzelm@61814
   533
fun check_src ctxt get_table src =
wenzelm@61814
   534
  let
wenzelm@61814
   535
    val (head, args) = dest_src src;
wenzelm@61814
   536
    val table = get_table ctxt;
wenzelm@61814
   537
  in
wenzelm@61814
   538
    (case get_name head of
wenzelm@61814
   539
      SOME {name, ...} => (src, Name_Space.get table name)
wenzelm@61814
   540
    | NONE =>
wenzelm@61814
   541
        let
wenzelm@64421
   542
          val pos = pos_of head;
wenzelm@64421
   543
          val (name, x) = Name_Space.check (Context.Proof ctxt) table (content_of head, pos);
wenzelm@64421
   544
          val _ = Context_Position.report ctxt pos Markup.operator;
wenzelm@61814
   545
          val kind = Name_Space.kind_of (Name_Space.space_of_table table);
wenzelm@61814
   546
          fun print ctxt' =
wenzelm@61814
   547
            Name_Space.markup_extern ctxt' (Name_Space.space_of_table (get_table ctxt')) name;
wenzelm@61814
   548
          val value = name_value {name = name, kind = kind, print = print};
wenzelm@61814
   549
          val head' = closure (assign (SOME value) head);
wenzelm@61814
   550
        in (head' :: args, x) end)
wenzelm@61814
   551
  end;
wenzelm@58011
   552
wenzelm@58011
   553
wenzelm@59125
   554
wenzelm@5825
   555
(** scanners **)
wenzelm@5825
   556
wenzelm@30573
   557
open Basic_Symbol_Pos;
wenzelm@5825
   558
wenzelm@48764
   559
val err_prefix = "Outer lexical error: ";
wenzelm@48764
   560
wenzelm@48764
   561
fun !!! msg = Symbol_Pos.!!! (fn () => err_prefix ^ msg);
wenzelm@5825
   562
wenzelm@5825
   563
wenzelm@5825
   564
(* scan symbolic idents *)
wenzelm@5825
   565
wenzelm@8231
   566
val scan_symid =
wenzelm@55033
   567
  Scan.many1 (Symbol.is_symbolic_char o Symbol_Pos.symbol) ||
wenzelm@40525
   568
  Scan.one (Symbol.is_symbolic o Symbol_Pos.symbol) >> single;
wenzelm@5825
   569
wenzelm@8231
   570
fun is_symid str =
wenzelm@8231
   571
  (case try Symbol.explode str of
wenzelm@55033
   572
    SOME [s] => Symbol.is_symbolic s orelse Symbol.is_symbolic_char s
wenzelm@55033
   573
  | SOME ss => forall Symbol.is_symbolic_char ss
wenzelm@8231
   574
  | _ => false);
wenzelm@8231
   575
wenzelm@27814
   576
fun ident_or_symbolic "begin" = false
wenzelm@27814
   577
  | ident_or_symbolic ":" = true
wenzelm@27814
   578
  | ident_or_symbolic "::" = true
wenzelm@50239
   579
  | ident_or_symbolic s = Symbol_Pos.is_identifier s orelse is_symid s;
wenzelm@5825
   580
wenzelm@5825
   581
wenzelm@5825
   582
(* scan verbatim text *)
wenzelm@5825
   583
wenzelm@5825
   584
val scan_verb =
wenzelm@55107
   585
  $$$ "*" --| Scan.ahead (~$$ "}") ||
wenzelm@58854
   586
  Scan.one (fn (s, _) => s <> "*" andalso Symbol.not_eof s) >> single;
wenzelm@5825
   587
wenzelm@5825
   588
val scan_verbatim =
wenzelm@55107
   589
  Scan.ahead ($$ "{" -- $$ "*") |--
wenzelm@55106
   590
    !!! "unclosed verbatim text"
wenzelm@55107
   591
      ((Symbol_Pos.scan_pos --| $$ "{" --| $$ "*") --
wenzelm@61476
   592
        (Scan.repeats scan_verb -- ($$ "*" |-- $$ "}" |-- Symbol_Pos.scan_pos)));
wenzelm@5825
   593
wenzelm@48743
   594
val recover_verbatim =
wenzelm@61476
   595
  $$$ "{" @@@ $$$ "*" @@@ Scan.repeats scan_verb;
wenzelm@48743
   596
wenzelm@5825
   597
wenzelm@55033
   598
(* scan cartouche *)
wenzelm@55033
   599
wenzelm@55033
   600
val scan_cartouche =
wenzelm@55104
   601
  Symbol_Pos.scan_pos --
wenzelm@55105
   602
    ((Symbol_Pos.scan_cartouche err_prefix >> Symbol_Pos.cartouche_content) -- Symbol_Pos.scan_pos);
wenzelm@55033
   603
wenzelm@55033
   604
wenzelm@5825
   605
(* scan space *)
wenzelm@5825
   606
wenzelm@48771
   607
fun space_symbol (s, _) = Symbol.is_blank s andalso s <> "\n";
wenzelm@5825
   608
wenzelm@5825
   609
val scan_space =
wenzelm@48771
   610
  Scan.many1 space_symbol @@@ Scan.optional ($$$ "\n") [] ||
wenzelm@48771
   611
  Scan.many space_symbol @@@ $$$ "\n";
wenzelm@5825
   612
wenzelm@5825
   613
wenzelm@27780
   614
(* scan comment *)
wenzelm@5825
   615
wenzelm@5825
   616
val scan_comment =
wenzelm@55105
   617
  Symbol_Pos.scan_pos -- (Symbol_Pos.scan_comment_body err_prefix -- Symbol_Pos.scan_pos);
wenzelm@5825
   618
wenzelm@5825
   619
wenzelm@27663
   620
wenzelm@27769
   621
(** token sources **)
wenzelm@5825
   622
wenzelm@23678
   623
local
wenzelm@23678
   624
wenzelm@27769
   625
fun token_leq ((_, syms1), (_, syms2)) = length syms1 <= length syms2;
wenzelm@27780
   626
wenzelm@27799
   627
fun token k ss =
wenzelm@43709
   628
  Token ((Symbol_Pos.implode ss, Symbol_Pos.range ss), (k, Symbol_Pos.content ss), Slot);
wenzelm@27799
   629
wenzelm@27799
   630
fun token_range k (pos1, (ss, pos2)) =
wenzelm@59112
   631
  Token (Symbol_Pos.implode_range (pos1, pos2) ss, (k, Symbol_Pos.content ss), Slot);
wenzelm@23678
   632
wenzelm@59083
   633
fun scan_token keywords = !!! "bad input"
wenzelm@48764
   634
  (Symbol_Pos.scan_string_qq err_prefix >> token_range String ||
wenzelm@59081
   635
    Symbol_Pos.scan_string_bq err_prefix >> token_range Alt_String ||
wenzelm@27799
   636
    scan_verbatim >> token_range Verbatim ||
wenzelm@55033
   637
    scan_cartouche >> token_range Cartouche ||
wenzelm@67439
   638
    scan_comment >> token_range (Comment NONE) ||
wenzelm@67446
   639
    Comment.scan >> (fn (k, ss) => token (Comment (SOME k)) ss) ||
wenzelm@27780
   640
    scan_space >> token Space ||
wenzelm@27780
   641
    (Scan.max token_leq
wenzelm@27769
   642
      (Scan.max token_leq
wenzelm@58903
   643
        (Scan.literal (Keyword.major_keywords keywords) >> pair Command)
wenzelm@58903
   644
        (Scan.literal (Keyword.minor_keywords keywords) >> pair Keyword))
wenzelm@59081
   645
      (Lexicon.scan_longid >> pair Long_Ident ||
wenzelm@42290
   646
        Lexicon.scan_id >> pair Ident ||
wenzelm@42290
   647
        Lexicon.scan_var >> pair Var ||
wenzelm@59081
   648
        Lexicon.scan_tid >> pair Type_Ident ||
wenzelm@59081
   649
        Lexicon.scan_tvar >> pair Type_Var ||
wenzelm@62782
   650
        Symbol_Pos.scan_float >> pair Float ||
wenzelm@62782
   651
        Symbol_Pos.scan_nat >> pair Nat ||
wenzelm@59081
   652
        scan_symid >> pair Sym_Ident) >> uncurry token));
wenzelm@27769
   653
wenzelm@27769
   654
fun recover msg =
wenzelm@48743
   655
  (Symbol_Pos.recover_string_qq ||
wenzelm@48743
   656
    Symbol_Pos.recover_string_bq ||
wenzelm@48743
   657
    recover_verbatim ||
wenzelm@55033
   658
    Symbol_Pos.recover_cartouche ||
wenzelm@48743
   659
    Symbol_Pos.recover_comment ||
wenzelm@58854
   660
    Scan.one (Symbol.not_eof o Symbol_Pos.symbol) >> single)
wenzelm@27780
   661
  >> (single o token (Error msg));
wenzelm@23678
   662
wenzelm@23678
   663
in
wenzelm@5825
   664
wenzelm@67497
   665
fun make_source keywords {strict} =
wenzelm@58864
   666
  let
wenzelm@59083
   667
    val scan_strict = Scan.bulk (scan_token keywords);
wenzelm@58864
   668
    val scan = if strict then scan_strict else Scan.recover scan_strict recover;
wenzelm@58864
   669
  in Source.source Symbol_Pos.stopper scan end;
wenzelm@27780
   670
wenzelm@61471
   671
fun read_cartouche syms =
wenzelm@61471
   672
  (case Scan.read Symbol_Pos.stopper (scan_cartouche >> token_range Cartouche) syms of
wenzelm@61471
   673
    SOME tok => tok
wenzelm@61471
   674
  | NONE => error ("Single cartouche expected" ^ Position.here (#1 (Symbol_Pos.range syms))));
wenzelm@61471
   675
wenzelm@23678
   676
end;
wenzelm@5825
   677
wenzelm@30586
   678
wenzelm@59083
   679
(* explode *)
wenzelm@59083
   680
wenzelm@67497
   681
fun tokenize keywords strict syms =
wenzelm@67497
   682
  Source.of_list syms |> make_source keywords strict |> Source.exhaust;
wenzelm@67495
   683
wenzelm@67495
   684
fun explode keywords pos text =
wenzelm@67497
   685
  Symbol_Pos.explode (text, pos) |> tokenize keywords {strict = false};
wenzelm@67495
   686
wenzelm@67495
   687
fun explode0 keywords = explode keywords Position.none;
wenzelm@59083
   688
wenzelm@59083
   689
wenzelm@63640
   690
(* print name in parsable form *)
wenzelm@63640
   691
wenzelm@63640
   692
fun print_name keywords name =
wenzelm@63640
   693
  ((case explode keywords Position.none name of
wenzelm@63640
   694
    [tok] => not (member (op =) [Ident, Long_Ident, Sym_Ident, Nat] (kind_of tok))
wenzelm@63640
   695
  | _ => true) ? Symbol_Pos.quote_string_qq) name;
wenzelm@63640
   696
wenzelm@63640
   697
wenzelm@59085
   698
(* make *)
wenzelm@59085
   699
wenzelm@59085
   700
fun make ((k, n), s) pos =
wenzelm@59085
   701
  let
wenzelm@68184
   702
    val pos' = Position.advance_offsets n pos;
wenzelm@62797
   703
    val range = Position.range (pos, pos');
wenzelm@59085
   704
    val tok =
wenzelm@61814
   705
      if 0 <= k andalso k < Vector.length immediate_kinds then
wenzelm@59085
   706
        Token ((s, range), (Vector.sub (immediate_kinds, k), s), Slot)
wenzelm@59085
   707
      else
wenzelm@59085
   708
        (case explode Keyword.empty_keywords pos s of
wenzelm@59085
   709
          [tok] => tok
wenzelm@59085
   710
        | _ => Token ((s, range), (Error (err_prefix ^ "exactly one token expected"), s), Slot))
wenzelm@59085
   711
  in (tok, pos') end;
wenzelm@59085
   712
wenzelm@61814
   713
fun make_string (s, pos) =
wenzelm@62799
   714
  let
wenzelm@62799
   715
    val Token ((x, _), y, z) = #1 (make ((~1, 0), Symbol_Pos.quote_string_qq s) Position.none);
wenzelm@62800
   716
    val pos' = Position.no_range_position pos;
wenzelm@62799
   717
  in Token ((x, (pos', pos')), y, z) end;
wenzelm@61814
   718
wenzelm@63019
   719
val make_int = explode Keyword.empty_keywords Position.none o signed_string_of_int;
wenzelm@63019
   720
wenzelm@61814
   721
fun make_src a args = make_string a :: args;
wenzelm@61814
   722
wenzelm@59085
   723
wenzelm@58011
   724
wenzelm@58011
   725
(** parsers **)
wenzelm@58011
   726
wenzelm@58011
   727
type 'a parser = T list -> 'a * T list;
wenzelm@58011
   728
type 'a context_parser = Context.generic * T list -> 'a * (Context.generic * T list);
wenzelm@58011
   729
wenzelm@58045
   730
wenzelm@67502
   731
(* read body -- e.g. antiquotation source *)
wenzelm@58045
   732
wenzelm@67502
   733
fun read_body keywords scan =
wenzelm@67502
   734
  tokenize (Keyword.no_command_keywords keywords) {strict = true}
wenzelm@67502
   735
  #> filter is_proper
wenzelm@67504
   736
  #> Scan.read stopper scan;
wenzelm@58045
   737
wenzelm@58903
   738
fun read_antiq keywords scan (syms, pos) =
wenzelm@67502
   739
  (case read_body keywords scan syms of
wenzelm@67504
   740
    SOME x => x
wenzelm@67504
   741
  | NONE => error ("Malformed antiquotation" ^ Position.here pos));
wenzelm@58045
   742
wenzelm@58045
   743
wenzelm@58045
   744
(* wrapped syntax *)
wenzelm@58045
   745
wenzelm@61814
   746
fun syntax_generic scan src context =
wenzelm@58011
   747
  let
wenzelm@61814
   748
    val (name, pos) = name_of_src src;
wenzelm@64421
   749
    val old_reports = maps reports_of_value src;
wenzelm@61814
   750
    val args1 = map init_assignable (args_of_src src);
wenzelm@58011
   751
    fun reported_text () =
wenzelm@58011
   752
      if Context_Position.is_visible_generic context then
wenzelm@64421
   753
        let val new_reports = maps (reports_of_value o closure) args1 in
wenzelm@64421
   754
          if old_reports <> new_reports then
wenzelm@64421
   755
            map (fn (p, m) => Position.reported_text p m "") new_reports
wenzelm@64421
   756
          else []
wenzelm@64421
   757
        end
wenzelm@58011
   758
      else [];
wenzelm@58011
   759
  in
wenzelm@58011
   760
    (case Scan.error (Scan.finite' stopper (Scan.option scan)) (context, args1) of
wenzelm@58011
   761
      (SOME x, (context', [])) =>
wenzelm@58011
   762
        let val _ = Output.report (reported_text ())
wenzelm@58011
   763
        in (x, context') end
wenzelm@61814
   764
    | (_, (context', args2)) =>
wenzelm@58011
   765
        let
wenzelm@58011
   766
          val print_name =
wenzelm@61814
   767
            (case get_name (hd src) of
wenzelm@58011
   768
              NONE => quote name
wenzelm@61814
   769
            | SOME {kind, print, ...} =>
wenzelm@61814
   770
                let
wenzelm@61814
   771
                  val ctxt' = Context.proof_of context';
wenzelm@61814
   772
                  val (markup, xname) = print ctxt';
wenzelm@61814
   773
                in plain_words kind ^ " " ^ quote (Markup.markup markup xname) end);
wenzelm@58011
   774
          val print_args =
wenzelm@58011
   775
            if null args2 then "" else ":\n  " ^ space_implode " " (map print args2);
wenzelm@58011
   776
        in
wenzelm@58011
   777
          error ("Bad arguments for " ^ print_name ^ Position.here pos ^ print_args ^
wenzelm@58011
   778
            Markup.markup_report (implode (reported_text ())))
wenzelm@58011
   779
        end)
wenzelm@58011
   780
  end;
wenzelm@58011
   781
wenzelm@58011
   782
fun syntax scan src = apsnd Context.the_proof o syntax_generic scan src o Context.Proof;
wenzelm@58011
   783
wenzelm@5825
   784
end;
wenzelm@58011
   785
wenzelm@58011
   786
type 'a parser = 'a Token.parser;
wenzelm@58011
   787
type 'a context_parser = 'a Token.context_parser;