src/Pure/Isar/token.ML
author wenzelm
Mon, 23 Aug 2021 12:54:28 +0200
changeset 74171 a9e79c3645c4
parent 73691 2f9877db82a1
child 74174 a3b0fc510705
permissions -rw-r--r--
clarified signature;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
36959
f5417836dbea renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents: 32738
diff changeset
     1
(*  Title:      Pure/Isar/token.ML
5825
24e4b1780d33 Outer lexical syntax for Isabelle/Isar.
wenzelm
parents:
diff changeset
     2
    Author:     Markus Wenzel, TU Muenchen
24e4b1780d33 Outer lexical syntax for Isabelle/Isar.
wenzelm
parents:
diff changeset
     3
36959
f5417836dbea renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents: 32738
diff changeset
     4
Outer token syntax for Isabelle/Isar.
5825
24e4b1780d33 Outer lexical syntax for Isabelle/Isar.
wenzelm
parents:
diff changeset
     5
*)
24e4b1780d33 Outer lexical syntax for Isabelle/Isar.
wenzelm
parents:
diff changeset
     6
36959
f5417836dbea renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents: 32738
diff changeset
     7
signature TOKEN =
5825
24e4b1780d33 Outer lexical syntax for Isabelle/Isar.
wenzelm
parents:
diff changeset
     8
sig
36959
f5417836dbea renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents: 32738
diff changeset
     9
  datatype kind =
59081
2ceb05ee0331 clarified token kind;
wenzelm
parents: 59064
diff changeset
    10
    (*immediate source*)
2ceb05ee0331 clarified token kind;
wenzelm
parents: 59064
diff changeset
    11
    Command | Keyword | Ident | Long_Ident | Sym_Ident | Var | Type_Ident | Type_Var | Nat |
2ceb05ee0331 clarified token kind;
wenzelm
parents: 59064
diff changeset
    12
    Float | Space |
2ceb05ee0331 clarified token kind;
wenzelm
parents: 59064
diff changeset
    13
    (*delimited content*)
67439
78759a7bd874 more uniform support for formal comments in outer syntax, notably \<^cancel> and \<^latex>;
wenzelm
parents: 66067
diff changeset
    14
    String | Alt_String | Verbatim | Cartouche | Comment of Comment.kind option |
59081
2ceb05ee0331 clarified token kind;
wenzelm
parents: 59064
diff changeset
    15
    (*special content*)
61819
wenzelm
parents: 61814
diff changeset
    16
    Error of string | EOF
58012
0b0519c41229 support for nested Token.src within Token.T;
wenzelm
parents: 58011
diff changeset
    17
  val str_of_kind: kind -> string
55788
67699e08e969 store blobs / inlined files as separate text lines: smaller values are more healthy for the Poly/ML RTS and allow implicit sharing;
wenzelm
parents: 55750
diff changeset
    18
  type file = {src_path: Path.T, lines: string list, digest: SHA1.digest, pos: Position.T}
58012
0b0519c41229 support for nested Token.src within Token.T;
wenzelm
parents: 58011
diff changeset
    19
  type T
61814
1ca1142e1711 clarified type Token.src: plain token list, with usual implicit value assignment;
wenzelm
parents: 61614
diff changeset
    20
  type src = T list
1ca1142e1711 clarified type Token.src: plain token list, with usual implicit value assignment;
wenzelm
parents: 61614
diff changeset
    21
  type name_value = {name: string, kind: string, print: Proof.context -> Markup.T * xstring}
27814
05a50886dacb unified Args.T with OuterLex.token;
wenzelm
parents: 27799
diff changeset
    22
  datatype value =
58012
0b0519c41229 support for nested Token.src within Token.T;
wenzelm
parents: 58011
diff changeset
    23
    Source of src |
57944
fff8d328da56 more informative Token.Name with history of morphisms;
wenzelm
parents: 57942
diff changeset
    24
    Literal of bool * Markup.T |
61814
1ca1142e1711 clarified type Token.src: plain token list, with usual implicit value assignment;
wenzelm
parents: 61614
diff changeset
    25
    Name of name_value * morphism |
57944
fff8d328da56 more informative Token.Name with history of morphisms;
wenzelm
parents: 57942
diff changeset
    26
    Typ of typ |
fff8d328da56 more informative Token.Name with history of morphisms;
wenzelm
parents: 57942
diff changeset
    27
    Term of term |
57942
e5bec882fdd0 more informative Token.Fact: retain name of dynamic fact (without selection);
wenzelm
parents: 56202
diff changeset
    28
    Fact of string option * thm list |
57944
fff8d328da56 more informative Token.Name with history of morphisms;
wenzelm
parents: 57942
diff changeset
    29
    Attribute of morphism -> attribute |
58017
5bdb58845eab support for declaration within token source;
wenzelm
parents: 58012
diff changeset
    30
    Declaration of declaration |
57944
fff8d328da56 more informative Token.Name with history of morphisms;
wenzelm
parents: 57942
diff changeset
    31
    Files of file Exn.result list
55708
f4b114070675 tuned signature;
wenzelm
parents: 55111
diff changeset
    32
  val pos_of: T -> Position.T
68183
6560324b1e4d adjust position according to offset of command/exec id;
wenzelm
parents: 67652
diff changeset
    33
  val adjust_offsets: (int -> int option) -> T -> T
36959
f5417836dbea renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents: 32738
diff changeset
    34
  val eof: T
f5417836dbea renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents: 32738
diff changeset
    35
  val is_eof: T -> bool
f5417836dbea renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents: 32738
diff changeset
    36
  val not_eof: T -> bool
f5417836dbea renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents: 32738
diff changeset
    37
  val stopper: T Scan.stopper
f5417836dbea renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents: 32738
diff changeset
    38
  val kind_of: T -> kind
f5417836dbea renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents: 32738
diff changeset
    39
  val is_kind: kind -> T -> bool
46811
03a2dc9e0624 clarified command span: include trailing whitespace/comments and thus reduce number of ignored spans with associated transactions and states (factor 2);
wenzelm
parents: 45666
diff changeset
    40
  val is_command: T -> bool
59924
801b979ec0c2 more general notion of command span: command keyword not necessarily at start;
wenzelm
parents: 59913
diff changeset
    41
  val keyword_with: (string -> bool) -> T -> bool
59939
7d46aa03696e support for 'restricted' modifier: only qualified accesses outside the local scope;
wenzelm
parents: 59924
diff changeset
    42
  val is_command_modifier: T -> bool
59924
801b979ec0c2 more general notion of command span: command keyword not necessarily at start;
wenzelm
parents: 59913
diff changeset
    43
  val ident_with: (string -> bool) -> T -> bool
36959
f5417836dbea renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents: 32738
diff changeset
    44
  val is_proper: T -> bool
f5417836dbea renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents: 32738
diff changeset
    45
  val is_comment: T -> bool
67439
78759a7bd874 more uniform support for formal comments in outer syntax, notably \<^cancel> and \<^latex>;
wenzelm
parents: 66067
diff changeset
    46
  val is_informal_comment: T -> bool
78759a7bd874 more uniform support for formal comments in outer syntax, notably \<^cancel> and \<^latex>;
wenzelm
parents: 66067
diff changeset
    47
  val is_formal_comment: T -> bool
69891
def3ec9cdb7e document markers are formal comments, and may thus occur anywhere in the command-span;
wenzelm
parents: 69851
diff changeset
    48
  val is_document_marker: T -> bool
68729
3a02b424d5fb clarified ignored span / core range: include formal comments, e.g. relevant for error messages from antiquotations;
wenzelm
parents: 68298
diff changeset
    49
  val is_ignored: T -> bool
36959
f5417836dbea renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents: 32738
diff changeset
    50
  val is_begin_ignore: T -> bool
f5417836dbea renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents: 32738
diff changeset
    51
  val is_end_ignore: T -> bool
48749
c197b3c3e7fa some attempts to keep malformed syntax errors focussed, without too much red spilled onto the document view;
wenzelm
parents: 48743
diff changeset
    52
  val is_error: T -> bool
48771
2ea997196d04 clarified Command.range vs. Command.proper_range according to Scala version, which is potentially relevant for command status markup;
wenzelm
parents: 48764
diff changeset
    53
  val is_space: T -> bool
36959
f5417836dbea renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents: 32738
diff changeset
    54
  val is_blank: T -> bool
f5417836dbea renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents: 32738
diff changeset
    55
  val is_newline: T -> bool
69891
def3ec9cdb7e document markers are formal comments, and may thus occur anywhere in the command-span;
wenzelm
parents: 69851
diff changeset
    56
  val range_of: T list -> Position.range
def3ec9cdb7e document markers are formal comments, and may thus occur anywhere in the command-span;
wenzelm
parents: 69851
diff changeset
    57
  val core_range_of: T list -> Position.range
59795
d453c69596cc clarified input source;
wenzelm
parents: 59666
diff changeset
    58
  val content_of: T -> string
68298
2c3ce27cf4a8 markup for deleted fragments of token source (NB: quoted tokens transform "\123" implicitly);
wenzelm
parents: 68183
diff changeset
    59
  val source_of: T -> string
59809
87641097d0f3 tuned signature;
wenzelm
parents: 59795
diff changeset
    60
  val input_of: T -> Input.source
59795
d453c69596cc clarified input source;
wenzelm
parents: 59666
diff changeset
    61
  val inner_syntax_of: T -> string
56202
0a11d17eeeff more markup for improper elements;
wenzelm
parents: 56064
diff changeset
    62
  val keyword_markup: bool * Markup.T -> string -> Markup.T
55915
607948c90bf0 suppress short abbreviations more uniformly, for outer and quasi-outer syntax;
wenzelm
parents: 55914
diff changeset
    63
  val completion_report: T -> Position.report_text list
59125
ee19c92ae8b4 more explicit markup for improper commands;
wenzelm
parents: 59124
diff changeset
    64
  val reports: Keyword.keywords -> T -> Position.report_text list
ee19c92ae8b4 more explicit markup for improper commands;
wenzelm
parents: 59124
diff changeset
    65
  val markups: Keyword.keywords -> T -> Markup.T list
36959
f5417836dbea renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents: 32738
diff changeset
    66
  val unparse: T -> string
55745
b865c3035d5c tuned message -- more markup;
wenzelm
parents: 55744
diff changeset
    67
  val print: T -> string
36959
f5417836dbea renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents: 32738
diff changeset
    68
  val text_of: T -> string * string
69851
29a4f633609e clarified signature;
wenzelm
parents: 68730
diff changeset
    69
  val file_source: file -> Input.source
54520
cee77d2e9582 release file errors at runtime: Command.eval instead of Command.read;
wenzelm
parents: 54519
diff changeset
    70
  val get_files: T -> file Exn.result list
cee77d2e9582 release file errors at runtime: Command.eval instead of Command.read;
wenzelm
parents: 54519
diff changeset
    71
  val put_files: file Exn.result list -> T -> T
36959
f5417836dbea renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents: 32738
diff changeset
    72
  val get_value: T -> value option
61822
wenzelm
parents: 61820
diff changeset
    73
  val reports_of_value: T -> Position.report list
61814
1ca1142e1711 clarified type Token.src: plain token list, with usual implicit value assignment;
wenzelm
parents: 61614
diff changeset
    74
  val name_value: name_value -> value
1ca1142e1711 clarified type Token.src: plain token list, with usual implicit value assignment;
wenzelm
parents: 61614
diff changeset
    75
  val get_name: T -> name_value option
59646
48d400469bcb added declare_maxidx operations for Eisbach;
wenzelm
parents: 59125
diff changeset
    76
  val declare_maxidx: T -> Proof.context -> Proof.context
61820
e65344e3eeb5 tuned signature;
wenzelm
parents: 61819
diff changeset
    77
  val map_facts: (string option -> thm list -> thm list) -> T -> T
67652
11716a084cae clarified signature;
wenzelm
parents: 67504
diff changeset
    78
  val trim_context_src: src -> src
58011
bc6bced136e5 tuned signature -- moved type src to Token, without aliases;
wenzelm
parents: 57944
diff changeset
    79
  val transform: morphism -> T -> T
55914
c5b752d549e3 clarified init_assignable: make double-sure that initial values are reset;
wenzelm
parents: 55828
diff changeset
    80
  val init_assignable: T -> T
61814
1ca1142e1711 clarified type Token.src: plain token list, with usual implicit value assignment;
wenzelm
parents: 61614
diff changeset
    81
  val assign: value option -> T -> T
1ca1142e1711 clarified type Token.src: plain token list, with usual implicit value assignment;
wenzelm
parents: 61614
diff changeset
    82
  val evaluate: ('a -> value) -> (T -> 'a) -> T -> 'a
36959
f5417836dbea renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents: 32738
diff changeset
    83
  val closure: T -> T
58012
0b0519c41229 support for nested Token.src within Token.T;
wenzelm
parents: 58011
diff changeset
    84
  val pretty_value: Proof.context -> T -> Pretty.T
61814
1ca1142e1711 clarified type Token.src: plain token list, with usual implicit value assignment;
wenzelm
parents: 61614
diff changeset
    85
  val name_of_src: src -> string * Position.T
1ca1142e1711 clarified type Token.src: plain token list, with usual implicit value assignment;
wenzelm
parents: 61614
diff changeset
    86
  val args_of_src: src -> T list
1ca1142e1711 clarified type Token.src: plain token list, with usual implicit value assignment;
wenzelm
parents: 61614
diff changeset
    87
  val checked_src: src -> bool
1ca1142e1711 clarified type Token.src: plain token list, with usual implicit value assignment;
wenzelm
parents: 61614
diff changeset
    88
  val check_src: Proof.context -> (Proof.context -> 'a Name_Space.table) -> src -> src * 'a
58011
bc6bced136e5 tuned signature -- moved type src to Token, without aliases;
wenzelm
parents: 57944
diff changeset
    89
  val pretty_src: Proof.context -> src -> Pretty.T
27814
05a50886dacb unified Args.T with OuterLex.token;
wenzelm
parents: 27799
diff changeset
    90
  val ident_or_symbolic: string -> bool
61471
9d4c08af61b8 support control symbol antiquotations;
wenzelm
parents: 61268
diff changeset
    91
  val read_cartouche: Symbol_Pos.T list -> T
67497
3a0b08e7dfe9 clarified signature;
wenzelm
parents: 67495
diff changeset
    92
  val tokenize: Keyword.keywords -> {strict: bool} -> Symbol_Pos.T list -> T list
59083
88b0b1f28adc tuned signature;
wenzelm
parents: 59081
diff changeset
    93
  val explode: Keyword.keywords -> Position.T -> string -> T list
67495
90d760fa8f34 clarified operations;
wenzelm
parents: 67446
diff changeset
    94
  val explode0: Keyword.keywords -> string -> T list
63640
c273583f0203 print name in parsable form;
wenzelm
parents: 63019
diff changeset
    95
  val print_name: Keyword.keywords -> string -> string
73691
2f9877db82a1 reimplemented Mirabelle as Isabelle/ML presentation hook + Isabelle/Scala tool, but sledgehammer is still inactive;
wenzelm
parents: 71675
diff changeset
    96
  val print_properties: Keyword.keywords -> Properties.T -> string
59085
08a6901eb035 clarified define_command: send tokens more directly, without requiring keywords in ML;
wenzelm
parents: 59083
diff changeset
    97
  val make: (int * int) * string -> Position.T -> T * Position.T
61814
1ca1142e1711 clarified type Token.src: plain token list, with usual implicit value assignment;
wenzelm
parents: 61614
diff changeset
    98
  val make_string: string * Position.T -> T
63019
80ef19b51493 prefer internal attribute source;
wenzelm
parents: 62969
diff changeset
    99
  val make_int: int -> T list
61814
1ca1142e1711 clarified type Token.src: plain token list, with usual implicit value assignment;
wenzelm
parents: 61614
diff changeset
   100
  val make_src: string * Position.T -> T list -> src
58011
bc6bced136e5 tuned signature -- moved type src to Token, without aliases;
wenzelm
parents: 57944
diff changeset
   101
  type 'a parser = T list -> 'a * T list
bc6bced136e5 tuned signature -- moved type src to Token, without aliases;
wenzelm
parents: 57944
diff changeset
   102
  type 'a context_parser = Context.generic * T list -> 'a * (Context.generic * T list)
67504
310114bec0d7 clarified signature;
wenzelm
parents: 67503
diff changeset
   103
  val read_body: Keyword.keywords -> 'a parser -> Symbol_Pos.T list -> 'a option
58903
38c72f5f6c2e explicit type Keyword.keywords;
wenzelm
parents: 58865
diff changeset
   104
  val read_antiq: Keyword.keywords -> 'a parser -> Symbol_Pos.T list * Position.T -> 'a
58011
bc6bced136e5 tuned signature -- moved type src to Token, without aliases;
wenzelm
parents: 57944
diff changeset
   105
  val syntax_generic: 'a context_parser -> src -> Context.generic -> 'a * Context.generic
bc6bced136e5 tuned signature -- moved type src to Token, without aliases;
wenzelm
parents: 57944
diff changeset
   106
  val syntax: 'a context_parser -> src -> Proof.context -> 'a * Proof.context
5825
24e4b1780d33 Outer lexical syntax for Isabelle/Isar.
wenzelm
parents:
diff changeset
   107
end;
24e4b1780d33 Outer lexical syntax for Isabelle/Isar.
wenzelm
parents:
diff changeset
   108
36959
f5417836dbea renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents: 32738
diff changeset
   109
structure Token: TOKEN =
5825
24e4b1780d33 Outer lexical syntax for Isabelle/Isar.
wenzelm
parents:
diff changeset
   110
struct
24e4b1780d33 Outer lexical syntax for Isabelle/Isar.
wenzelm
parents:
diff changeset
   111
24e4b1780d33 Outer lexical syntax for Isabelle/Isar.
wenzelm
parents:
diff changeset
   112
(** tokens **)
24e4b1780d33 Outer lexical syntax for Isabelle/Isar.
wenzelm
parents:
diff changeset
   113
58012
0b0519c41229 support for nested Token.src within Token.T;
wenzelm
parents: 58011
diff changeset
   114
(* token kind *)
5825
24e4b1780d33 Outer lexical syntax for Isabelle/Isar.
wenzelm
parents:
diff changeset
   115
36959
f5417836dbea renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents: 32738
diff changeset
   116
datatype kind =
59081
2ceb05ee0331 clarified token kind;
wenzelm
parents: 59064
diff changeset
   117
  (*immediate source*)
2ceb05ee0331 clarified token kind;
wenzelm
parents: 59064
diff changeset
   118
  Command | Keyword | Ident | Long_Ident | Sym_Ident | Var | Type_Ident | Type_Var | Nat |
2ceb05ee0331 clarified token kind;
wenzelm
parents: 59064
diff changeset
   119
  Float | Space |
2ceb05ee0331 clarified token kind;
wenzelm
parents: 59064
diff changeset
   120
  (*delimited content*)
67439
78759a7bd874 more uniform support for formal comments in outer syntax, notably \<^cancel> and \<^latex>;
wenzelm
parents: 66067
diff changeset
   121
  String | Alt_String | Verbatim | Cartouche | Comment of Comment.kind option |
59081
2ceb05ee0331 clarified token kind;
wenzelm
parents: 59064
diff changeset
   122
  (*special content*)
61819
wenzelm
parents: 61814
diff changeset
   123
  Error of string | EOF;
5825
24e4b1780d33 Outer lexical syntax for Isabelle/Isar.
wenzelm
parents:
diff changeset
   124
24e4b1780d33 Outer lexical syntax for Isabelle/Isar.
wenzelm
parents:
diff changeset
   125
val str_of_kind =
7026
69724548fad1 separate command tokens;
wenzelm
parents: 6859
diff changeset
   126
 fn Command => "command"
69724548fad1 separate command tokens;
wenzelm
parents: 6859
diff changeset
   127
  | Keyword => "keyword"
5825
24e4b1780d33 Outer lexical syntax for Isabelle/Isar.
wenzelm
parents:
diff changeset
   128
  | Ident => "identifier"
59081
2ceb05ee0331 clarified token kind;
wenzelm
parents: 59064
diff changeset
   129
  | Long_Ident => "long identifier"
2ceb05ee0331 clarified token kind;
wenzelm
parents: 59064
diff changeset
   130
  | Sym_Ident => "symbolic identifier"
5825
24e4b1780d33 Outer lexical syntax for Isabelle/Isar.
wenzelm
parents:
diff changeset
   131
  | Var => "schematic variable"
59081
2ceb05ee0331 clarified token kind;
wenzelm
parents: 59064
diff changeset
   132
  | Type_Ident => "type variable"
2ceb05ee0331 clarified token kind;
wenzelm
parents: 59064
diff changeset
   133
  | Type_Var => "schematic type variable"
40290
47f572aff50a support for floating-point tokens in outer syntax (coinciding with inner syntax version);
wenzelm
parents: 38229
diff changeset
   134
  | Nat => "natural number"
47f572aff50a support for floating-point tokens in outer syntax (coinciding with inner syntax version);
wenzelm
parents: 38229
diff changeset
   135
  | Float => "floating-point number"
59081
2ceb05ee0331 clarified token kind;
wenzelm
parents: 59064
diff changeset
   136
  | Space => "white space"
55103
57d87ec3da4c tuned errors;
wenzelm
parents: 55033
diff changeset
   137
  | String => "quoted string"
59081
2ceb05ee0331 clarified token kind;
wenzelm
parents: 59064
diff changeset
   138
  | Alt_String => "back-quoted string"
5825
24e4b1780d33 Outer lexical syntax for Isabelle/Isar.
wenzelm
parents:
diff changeset
   139
  | Verbatim => "verbatim text"
55103
57d87ec3da4c tuned errors;
wenzelm
parents: 55033
diff changeset
   140
  | Cartouche => "text cartouche"
67439
78759a7bd874 more uniform support for formal comments in outer syntax, notably \<^cancel> and \<^latex>;
wenzelm
parents: 66067
diff changeset
   141
  | Comment NONE => "informal comment"
78759a7bd874 more uniform support for formal comments in outer syntax, notably \<^cancel> and \<^latex>;
wenzelm
parents: 66067
diff changeset
   142
  | Comment (SOME _) => "formal comment"
23729
d1ba656978c5 separated Malformed (symbolic char) from Error (bad input);
wenzelm
parents: 23721
diff changeset
   143
  | Error _ => "bad input"
48911
5debc3e4fa81 tuned messages: end-of-input rarely means physical end-of-file from the past;
wenzelm
parents: 48905
diff changeset
   144
  | EOF => "end-of-input";
5825
24e4b1780d33 Outer lexical syntax for Isabelle/Isar.
wenzelm
parents:
diff changeset
   145
59085
08a6901eb035 clarified define_command: send tokens more directly, without requiring keywords in ML;
wenzelm
parents: 59083
diff changeset
   146
val immediate_kinds =
08a6901eb035 clarified define_command: send tokens more directly, without requiring keywords in ML;
wenzelm
parents: 59083
diff changeset
   147
  Vector.fromList
08a6901eb035 clarified define_command: send tokens more directly, without requiring keywords in ML;
wenzelm
parents: 59083
diff changeset
   148
    [Command, Keyword, Ident, Long_Ident, Sym_Ident, Var, Type_Ident, Type_Var, Nat, Float, Space];
08a6901eb035 clarified define_command: send tokens more directly, without requiring keywords in ML;
wenzelm
parents: 59083
diff changeset
   149
67439
78759a7bd874 more uniform support for formal comments in outer syntax, notably \<^cancel> and \<^latex>;
wenzelm
parents: 66067
diff changeset
   150
val delimited_kind =
78759a7bd874 more uniform support for formal comments in outer syntax, notably \<^cancel> and \<^latex>;
wenzelm
parents: 66067
diff changeset
   151
  (fn String => true
78759a7bd874 more uniform support for formal comments in outer syntax, notably \<^cancel> and \<^latex>;
wenzelm
parents: 66067
diff changeset
   152
    | Alt_String => true
78759a7bd874 more uniform support for formal comments in outer syntax, notably \<^cancel> and \<^latex>;
wenzelm
parents: 66067
diff changeset
   153
    | Verbatim => true
78759a7bd874 more uniform support for formal comments in outer syntax, notably \<^cancel> and \<^latex>;
wenzelm
parents: 66067
diff changeset
   154
    | Cartouche => true
78759a7bd874 more uniform support for formal comments in outer syntax, notably \<^cancel> and \<^latex>;
wenzelm
parents: 66067
diff changeset
   155
    | Comment _ => true
78759a7bd874 more uniform support for formal comments in outer syntax, notably \<^cancel> and \<^latex>;
wenzelm
parents: 66067
diff changeset
   156
    | _ => false);
55828
42ac3cfb89f6 clarified language markup: added "delimited" property;
wenzelm
parents: 55788
diff changeset
   157
5825
24e4b1780d33 Outer lexical syntax for Isabelle/Isar.
wenzelm
parents:
diff changeset
   158
58012
0b0519c41229 support for nested Token.src within Token.T;
wenzelm
parents: 58011
diff changeset
   159
(* datatype token *)
0b0519c41229 support for nested Token.src within Token.T;
wenzelm
parents: 58011
diff changeset
   160
0b0519c41229 support for nested Token.src within Token.T;
wenzelm
parents: 58011
diff changeset
   161
(*The value slot assigns an (optional) internal value to a token,
0b0519c41229 support for nested Token.src within Token.T;
wenzelm
parents: 58011
diff changeset
   162
  usually as a side-effect of special scanner setup (see also
0b0519c41229 support for nested Token.src within Token.T;
wenzelm
parents: 58011
diff changeset
   163
  args.ML).  Note that an assignable ref designates an intermediate
0b0519c41229 support for nested Token.src within Token.T;
wenzelm
parents: 58011
diff changeset
   164
  state of internalization -- it is NOT meant to persist.*)
0b0519c41229 support for nested Token.src within Token.T;
wenzelm
parents: 58011
diff changeset
   165
0b0519c41229 support for nested Token.src within Token.T;
wenzelm
parents: 58011
diff changeset
   166
type file = {src_path: Path.T, lines: string list, digest: SHA1.digest, pos: Position.T};
0b0519c41229 support for nested Token.src within Token.T;
wenzelm
parents: 58011
diff changeset
   167
61814
1ca1142e1711 clarified type Token.src: plain token list, with usual implicit value assignment;
wenzelm
parents: 61614
diff changeset
   168
type name_value = {name: string, kind: string, print: Proof.context -> Markup.T * xstring};
58012
0b0519c41229 support for nested Token.src within Token.T;
wenzelm
parents: 58011
diff changeset
   169
61814
1ca1142e1711 clarified type Token.src: plain token list, with usual implicit value assignment;
wenzelm
parents: 61614
diff changeset
   170
datatype T = Token of (Symbol_Pos.text * Position.range) * (kind * string) * slot
58012
0b0519c41229 support for nested Token.src within Token.T;
wenzelm
parents: 58011
diff changeset
   171
0b0519c41229 support for nested Token.src within Token.T;
wenzelm
parents: 58011
diff changeset
   172
and slot =
0b0519c41229 support for nested Token.src within Token.T;
wenzelm
parents: 58011
diff changeset
   173
  Slot |
0b0519c41229 support for nested Token.src within Token.T;
wenzelm
parents: 58011
diff changeset
   174
  Value of value option |
0b0519c41229 support for nested Token.src within Token.T;
wenzelm
parents: 58011
diff changeset
   175
  Assignable of value option Unsynchronized.ref
0b0519c41229 support for nested Token.src within Token.T;
wenzelm
parents: 58011
diff changeset
   176
0b0519c41229 support for nested Token.src within Token.T;
wenzelm
parents: 58011
diff changeset
   177
and value =
61814
1ca1142e1711 clarified type Token.src: plain token list, with usual implicit value assignment;
wenzelm
parents: 61614
diff changeset
   178
  Source of T list |
58012
0b0519c41229 support for nested Token.src within Token.T;
wenzelm
parents: 58011
diff changeset
   179
  Literal of bool * Markup.T |
61814
1ca1142e1711 clarified type Token.src: plain token list, with usual implicit value assignment;
wenzelm
parents: 61614
diff changeset
   180
  Name of name_value * morphism |
58012
0b0519c41229 support for nested Token.src within Token.T;
wenzelm
parents: 58011
diff changeset
   181
  Typ of typ |
0b0519c41229 support for nested Token.src within Token.T;
wenzelm
parents: 58011
diff changeset
   182
  Term of term |
0b0519c41229 support for nested Token.src within Token.T;
wenzelm
parents: 58011
diff changeset
   183
  Fact of string option * thm list |  (*optional name for dynamic fact, i.e. fact "variable"*)
0b0519c41229 support for nested Token.src within Token.T;
wenzelm
parents: 58011
diff changeset
   184
  Attribute of morphism -> attribute |
58017
5bdb58845eab support for declaration within token source;
wenzelm
parents: 58012
diff changeset
   185
  Declaration of declaration |
58012
0b0519c41229 support for nested Token.src within Token.T;
wenzelm
parents: 58011
diff changeset
   186
  Files of file Exn.result list;
0b0519c41229 support for nested Token.src within Token.T;
wenzelm
parents: 58011
diff changeset
   187
61814
1ca1142e1711 clarified type Token.src: plain token list, with usual implicit value assignment;
wenzelm
parents: 61614
diff changeset
   188
type src = T list;
58012
0b0519c41229 support for nested Token.src within Token.T;
wenzelm
parents: 58011
diff changeset
   189
0b0519c41229 support for nested Token.src within Token.T;
wenzelm
parents: 58011
diff changeset
   190
27733
d3d7038fb7b5 abstract type Scan.stopper, position taken from last input token;
wenzelm
parents: 27663
diff changeset
   191
(* position *)
5825
24e4b1780d33 Outer lexical syntax for Isabelle/Isar.
wenzelm
parents:
diff changeset
   192
55708
f4b114070675 tuned signature;
wenzelm
parents: 55111
diff changeset
   193
fun pos_of (Token ((_, (pos, _)), _, _)) = pos;
f4b114070675 tuned signature;
wenzelm
parents: 55111
diff changeset
   194
fun end_pos_of (Token ((_, (_, pos)), _, _)) = pos;
27663
098798321622 maintain token range;
wenzelm
parents: 27358
diff changeset
   195
68183
6560324b1e4d adjust position according to offset of command/exec id;
wenzelm
parents: 67652
diff changeset
   196
fun adjust_offsets adjust (Token ((x, range), y, z)) =
6560324b1e4d adjust position according to offset of command/exec id;
wenzelm
parents: 67652
diff changeset
   197
  Token ((x, apply2 (Position.adjust_offsets adjust) range), y, z);
6560324b1e4d adjust position according to offset of command/exec id;
wenzelm
parents: 67652
diff changeset
   198
5825
24e4b1780d33 Outer lexical syntax for Isabelle/Isar.
wenzelm
parents:
diff changeset
   199
58855
2885e2eaa0fb removed pointless markup;
wenzelm
parents: 58854
diff changeset
   200
(* stopper *)
27733
d3d7038fb7b5 abstract type Scan.stopper, position taken from last input token;
wenzelm
parents: 27663
diff changeset
   201
27814
05a50886dacb unified Args.T with OuterLex.token;
wenzelm
parents: 27799
diff changeset
   202
fun mk_eof pos = Token (("", (pos, Position.none)), (EOF, ""), Slot);
27733
d3d7038fb7b5 abstract type Scan.stopper, position taken from last input token;
wenzelm
parents: 27663
diff changeset
   203
val eof = mk_eof Position.none;
d3d7038fb7b5 abstract type Scan.stopper, position taken from last input token;
wenzelm
parents: 27663
diff changeset
   204
27814
05a50886dacb unified Args.T with OuterLex.token;
wenzelm
parents: 27799
diff changeset
   205
fun is_eof (Token (_, (EOF, _), _)) = true
27733
d3d7038fb7b5 abstract type Scan.stopper, position taken from last input token;
wenzelm
parents: 27663
diff changeset
   206
  | is_eof _ = false;
d3d7038fb7b5 abstract type Scan.stopper, position taken from last input token;
wenzelm
parents: 27663
diff changeset
   207
d3d7038fb7b5 abstract type Scan.stopper, position taken from last input token;
wenzelm
parents: 27663
diff changeset
   208
val not_eof = not o is_eof;
d3d7038fb7b5 abstract type Scan.stopper, position taken from last input token;
wenzelm
parents: 27663
diff changeset
   209
27752
ea7d573e565f removed obsolete range_of (already included in position);
wenzelm
parents: 27747
diff changeset
   210
val stopper =
55708
f4b114070675 tuned signature;
wenzelm
parents: 55111
diff changeset
   211
  Scan.stopper (fn [] => eof | toks => mk_eof (end_pos_of (List.last toks))) is_eof;
27733
d3d7038fb7b5 abstract type Scan.stopper, position taken from last input token;
wenzelm
parents: 27663
diff changeset
   212
d3d7038fb7b5 abstract type Scan.stopper, position taken from last input token;
wenzelm
parents: 27663
diff changeset
   213
5825
24e4b1780d33 Outer lexical syntax for Isabelle/Isar.
wenzelm
parents:
diff changeset
   214
(* kind of token *)
24e4b1780d33 Outer lexical syntax for Isabelle/Isar.
wenzelm
parents:
diff changeset
   215
27814
05a50886dacb unified Args.T with OuterLex.token;
wenzelm
parents: 27799
diff changeset
   216
fun kind_of (Token (_, (k, _), _)) = k;
05a50886dacb unified Args.T with OuterLex.token;
wenzelm
parents: 27799
diff changeset
   217
fun is_kind k (Token (_, (k', _), _)) = k = k';
5825
24e4b1780d33 Outer lexical syntax for Isabelle/Isar.
wenzelm
parents:
diff changeset
   218
46811
03a2dc9e0624 clarified command span: include trailing whitespace/comments and thus reduce number of ignored spans with associated transactions and states (factor 2);
wenzelm
parents: 45666
diff changeset
   219
val is_command = is_kind Command;
59123
e68e44836d04 imitate command markup and rendering of Isabelle/jEdit in HTML output;
wenzelm
parents: 59112
diff changeset
   220
27814
05a50886dacb unified Args.T with OuterLex.token;
wenzelm
parents: 27799
diff changeset
   221
fun keyword_with pred (Token (_, (Keyword, x), _)) = pred x
7026
69724548fad1 separate command tokens;
wenzelm
parents: 6859
diff changeset
   222
  | keyword_with _ _ = false;
5825
24e4b1780d33 Outer lexical syntax for Isabelle/Isar.
wenzelm
parents:
diff changeset
   223
59990
a81dc82ecba3 clarified keyword 'qualified' in accordance to a similar keyword from Haskell (despite unrelated Binding.qualified in Isabelle/ML);
wenzelm
parents: 59939
diff changeset
   224
val is_command_modifier = keyword_with (fn x => x = "private" orelse x = "qualified");
59924
801b979ec0c2 more general notion of command span: command keyword not necessarily at start;
wenzelm
parents: 59913
diff changeset
   225
27814
05a50886dacb unified Args.T with OuterLex.token;
wenzelm
parents: 27799
diff changeset
   226
fun ident_with pred (Token (_, (Ident, x), _)) = pred x
16029
070ed43b86f8 added ident_with;
wenzelm
parents: 15531
diff changeset
   227
  | ident_with _ _ = false;
070ed43b86f8 added ident_with;
wenzelm
parents: 15531
diff changeset
   228
68729
3a02b424d5fb clarified ignored span / core range: include formal comments, e.g. relevant for error messages from antiquotations;
wenzelm
parents: 68298
diff changeset
   229
fun is_ignored (Token (_, (Space, _), _)) = true
3a02b424d5fb clarified ignored span / core range: include formal comments, e.g. relevant for error messages from antiquotations;
wenzelm
parents: 68298
diff changeset
   230
  | is_ignored (Token (_, (Comment NONE, _), _)) = true
3a02b424d5fb clarified ignored span / core range: include formal comments, e.g. relevant for error messages from antiquotations;
wenzelm
parents: 68298
diff changeset
   231
  | is_ignored _ = false;
3a02b424d5fb clarified ignored span / core range: include formal comments, e.g. relevant for error messages from antiquotations;
wenzelm
parents: 68298
diff changeset
   232
27814
05a50886dacb unified Args.T with OuterLex.token;
wenzelm
parents: 27799
diff changeset
   233
fun is_proper (Token (_, (Space, _), _)) = false
67439
78759a7bd874 more uniform support for formal comments in outer syntax, notably \<^cancel> and \<^latex>;
wenzelm
parents: 66067
diff changeset
   234
  | is_proper (Token (_, (Comment _, _), _)) = false
5825
24e4b1780d33 Outer lexical syntax for Isabelle/Isar.
wenzelm
parents:
diff changeset
   235
  | is_proper _ = true;
24e4b1780d33 Outer lexical syntax for Isabelle/Isar.
wenzelm
parents:
diff changeset
   236
67439
78759a7bd874 more uniform support for formal comments in outer syntax, notably \<^cancel> and \<^latex>;
wenzelm
parents: 66067
diff changeset
   237
fun is_comment (Token (_, (Comment _, _), _)) = true
17069
ee08b2466a09 clarify is_newline vs. is_blank;
wenzelm
parents: 16029
diff changeset
   238
  | is_comment _ = false;
ee08b2466a09 clarify is_newline vs. is_blank;
wenzelm
parents: 16029
diff changeset
   239
67439
78759a7bd874 more uniform support for formal comments in outer syntax, notably \<^cancel> and \<^latex>;
wenzelm
parents: 66067
diff changeset
   240
fun is_informal_comment (Token (_, (Comment NONE, _), _)) = true
78759a7bd874 more uniform support for formal comments in outer syntax, notably \<^cancel> and \<^latex>;
wenzelm
parents: 66067
diff changeset
   241
  | is_informal_comment _ = false;
78759a7bd874 more uniform support for formal comments in outer syntax, notably \<^cancel> and \<^latex>;
wenzelm
parents: 66067
diff changeset
   242
78759a7bd874 more uniform support for formal comments in outer syntax, notably \<^cancel> and \<^latex>;
wenzelm
parents: 66067
diff changeset
   243
fun is_formal_comment (Token (_, (Comment (SOME _), _), _)) = true
78759a7bd874 more uniform support for formal comments in outer syntax, notably \<^cancel> and \<^latex>;
wenzelm
parents: 66067
diff changeset
   244
  | is_formal_comment _ = false;
78759a7bd874 more uniform support for formal comments in outer syntax, notably \<^cancel> and \<^latex>;
wenzelm
parents: 66067
diff changeset
   245
69891
def3ec9cdb7e document markers are formal comments, and may thus occur anywhere in the command-span;
wenzelm
parents: 69851
diff changeset
   246
fun is_document_marker (Token (_, (Comment (SOME Comment.Marker), _), _)) = true
def3ec9cdb7e document markers are formal comments, and may thus occur anywhere in the command-span;
wenzelm
parents: 69851
diff changeset
   247
  | is_document_marker _ = false;
def3ec9cdb7e document markers are formal comments, and may thus occur anywhere in the command-span;
wenzelm
parents: 69851
diff changeset
   248
67439
78759a7bd874 more uniform support for formal comments in outer syntax, notably \<^cancel> and \<^latex>;
wenzelm
parents: 66067
diff changeset
   249
fun is_begin_ignore (Token (_, (Comment NONE, "<"), _)) = true
8580
e79ee31d3936 added is_begin/end_ignore;
wenzelm
parents: 8231
diff changeset
   250
  | is_begin_ignore _ = false;
e79ee31d3936 added is_begin/end_ignore;
wenzelm
parents: 8231
diff changeset
   251
67439
78759a7bd874 more uniform support for formal comments in outer syntax, notably \<^cancel> and \<^latex>;
wenzelm
parents: 66067
diff changeset
   252
fun is_end_ignore (Token (_, (Comment NONE, ">"), _)) = true
8580
e79ee31d3936 added is_begin/end_ignore;
wenzelm
parents: 8231
diff changeset
   253
  | is_end_ignore _ = false;
e79ee31d3936 added is_begin/end_ignore;
wenzelm
parents: 8231
diff changeset
   254
48749
c197b3c3e7fa some attempts to keep malformed syntax errors focussed, without too much red spilled onto the document view;
wenzelm
parents: 48743
diff changeset
   255
fun is_error (Token (_, (Error _, _), _)) = true
c197b3c3e7fa some attempts to keep malformed syntax errors focussed, without too much red spilled onto the document view;
wenzelm
parents: 48743
diff changeset
   256
  | is_error _ = false;
c197b3c3e7fa some attempts to keep malformed syntax errors focussed, without too much red spilled onto the document view;
wenzelm
parents: 48743
diff changeset
   257
8651
f095f3b8181a added is_newline;
wenzelm
parents: 8580
diff changeset
   258
17069
ee08b2466a09 clarify is_newline vs. is_blank;
wenzelm
parents: 16029
diff changeset
   259
(* blanks and newlines -- space tokens obey lines *)
8651
f095f3b8181a added is_newline;
wenzelm
parents: 8580
diff changeset
   260
48771
2ea997196d04 clarified Command.range vs. Command.proper_range according to Scala version, which is potentially relevant for command status markup;
wenzelm
parents: 48764
diff changeset
   261
fun is_space (Token (_, (Space, _), _)) = true
2ea997196d04 clarified Command.range vs. Command.proper_range according to Scala version, which is potentially relevant for command status markup;
wenzelm
parents: 48764
diff changeset
   262
  | is_space _ = false;
2ea997196d04 clarified Command.range vs. Command.proper_range according to Scala version, which is potentially relevant for command status markup;
wenzelm
parents: 48764
diff changeset
   263
27814
05a50886dacb unified Args.T with OuterLex.token;
wenzelm
parents: 27799
diff changeset
   264
fun is_blank (Token (_, (Space, x), _)) = not (String.isSuffix "\n" x)
17069
ee08b2466a09 clarify is_newline vs. is_blank;
wenzelm
parents: 16029
diff changeset
   265
  | is_blank _ = false;
ee08b2466a09 clarify is_newline vs. is_blank;
wenzelm
parents: 16029
diff changeset
   266
27814
05a50886dacb unified Args.T with OuterLex.token;
wenzelm
parents: 27799
diff changeset
   267
fun is_newline (Token (_, (Space, x), _)) = String.isSuffix "\n" x
8651
f095f3b8181a added is_newline;
wenzelm
parents: 8580
diff changeset
   268
  | is_newline _ = false;
f095f3b8181a added is_newline;
wenzelm
parents: 8580
diff changeset
   269
5825
24e4b1780d33 Outer lexical syntax for Isabelle/Isar.
wenzelm
parents:
diff changeset
   270
69891
def3ec9cdb7e document markers are formal comments, and may thus occur anywhere in the command-span;
wenzelm
parents: 69851
diff changeset
   271
(* range of tokens *)
def3ec9cdb7e document markers are formal comments, and may thus occur anywhere in the command-span;
wenzelm
parents: 69851
diff changeset
   272
def3ec9cdb7e document markers are formal comments, and may thus occur anywhere in the command-span;
wenzelm
parents: 69851
diff changeset
   273
fun range_of (toks as tok :: _) =
def3ec9cdb7e document markers are formal comments, and may thus occur anywhere in the command-span;
wenzelm
parents: 69851
diff changeset
   274
      let val pos' = end_pos_of (List.last toks)
def3ec9cdb7e document markers are formal comments, and may thus occur anywhere in the command-span;
wenzelm
parents: 69851
diff changeset
   275
      in Position.range (pos_of tok, pos') end
def3ec9cdb7e document markers are formal comments, and may thus occur anywhere in the command-span;
wenzelm
parents: 69851
diff changeset
   276
  | range_of [] = Position.no_range;
def3ec9cdb7e document markers are formal comments, and may thus occur anywhere in the command-span;
wenzelm
parents: 69851
diff changeset
   277
def3ec9cdb7e document markers are formal comments, and may thus occur anywhere in the command-span;
wenzelm
parents: 69851
diff changeset
   278
val core_range_of =
def3ec9cdb7e document markers are formal comments, and may thus occur anywhere in the command-span;
wenzelm
parents: 69851
diff changeset
   279
  drop_prefix is_ignored #> drop_suffix is_ignored #> range_of;
def3ec9cdb7e document markers are formal comments, and may thus occur anywhere in the command-span;
wenzelm
parents: 69851
diff changeset
   280
def3ec9cdb7e document markers are formal comments, and may thus occur anywhere in the command-span;
wenzelm
parents: 69851
diff changeset
   281
14991
26fb63c4acb5 added unparse;
wenzelm
parents: 14981
diff changeset
   282
(* token content *)
9155
adfa40218e06 OuterLex.name_of: include val;
wenzelm
parents: 9130
diff changeset
   283
59795
d453c69596cc clarified input source;
wenzelm
parents: 59666
diff changeset
   284
fun content_of (Token (_, (_, x), _)) = x;
68298
2c3ce27cf4a8 markup for deleted fragments of token source (NB: quoted tokens transform "\123" implicitly);
wenzelm
parents: 68183
diff changeset
   285
fun source_of (Token ((source, _), _, _)) = source;
25642
ebdff0dca2a5 text_of: made even more robust against recurrent errors;
wenzelm
parents: 25582
diff changeset
   286
59809
87641097d0f3 tuned signature;
wenzelm
parents: 59795
diff changeset
   287
fun input_of (Token ((source, range), (kind, _), _)) =
59064
a8bcb5a446c8 more abstract type Input.source;
wenzelm
parents: 58978
diff changeset
   288
  Input.source (delimited_kind kind) source range;
27873
34d61938e27a added source_of';
wenzelm
parents: 27856
diff changeset
   289
59795
d453c69596cc clarified input source;
wenzelm
parents: 59666
diff changeset
   290
fun inner_syntax_of tok =
d453c69596cc clarified input source;
wenzelm
parents: 59666
diff changeset
   291
  let val x = content_of tok
59809
87641097d0f3 tuned signature;
wenzelm
parents: 59795
diff changeset
   292
  in if YXML.detect x then x else Syntax.implode_input (input_of tok) end;
27747
d41abb7bc08a token: maintain of source, which retains original position information;
wenzelm
parents: 27733
diff changeset
   293
d41abb7bc08a token: maintain of source, which retains original position information;
wenzelm
parents: 27733
diff changeset
   294
55915
607948c90bf0 suppress short abbreviations more uniformly, for outer and quasi-outer syntax;
wenzelm
parents: 55914
diff changeset
   295
(* markup reports *)
55744
4a4e5686e091 clarified token markup: keyword1/keyword2 is for syntax, and "command" the entity kind;
wenzelm
parents: 55709
diff changeset
   296
4a4e5686e091 clarified token markup: keyword1/keyword2 is for syntax, and "command" the entity kind;
wenzelm
parents: 55709
diff changeset
   297
local
4a4e5686e091 clarified token markup: keyword1/keyword2 is for syntax, and "command" the entity kind;
wenzelm
parents: 55709
diff changeset
   298
4a4e5686e091 clarified token markup: keyword1/keyword2 is for syntax, and "command" the entity kind;
wenzelm
parents: 55709
diff changeset
   299
val token_kind_markup =
59124
wenzelm
parents: 59123
diff changeset
   300
 fn Var => (Markup.var, "")
59081
2ceb05ee0331 clarified token kind;
wenzelm
parents: 59064
diff changeset
   301
  | Type_Ident => (Markup.tfree, "")
2ceb05ee0331 clarified token kind;
wenzelm
parents: 59064
diff changeset
   302
  | Type_Var => (Markup.tvar, "")
2ceb05ee0331 clarified token kind;
wenzelm
parents: 59064
diff changeset
   303
  | String => (Markup.string, "")
2ceb05ee0331 clarified token kind;
wenzelm
parents: 59064
diff changeset
   304
  | Alt_String => (Markup.alt_string, "")
2ceb05ee0331 clarified token kind;
wenzelm
parents: 59064
diff changeset
   305
  | Verbatim => (Markup.verbatim, "")
2ceb05ee0331 clarified token kind;
wenzelm
parents: 59064
diff changeset
   306
  | Cartouche => (Markup.cartouche, "")
67440
e5ba0ca1e465 clarified markup;
wenzelm
parents: 67439
diff changeset
   307
  | Comment _ => (Markup.comment, "")
64677
8dc24130e8fe more uniform treatment of "bad" like other messages (with serial number);
wenzelm
parents: 64421
diff changeset
   308
  | Error msg => (Markup.bad (), msg)
59124
wenzelm
parents: 59123
diff changeset
   309
  | _ => (Markup.empty, "");
55744
4a4e5686e091 clarified token markup: keyword1/keyword2 is for syntax, and "command" the entity kind;
wenzelm
parents: 55709
diff changeset
   310
59125
ee19c92ae8b4 more explicit markup for improper commands;
wenzelm
parents: 59124
diff changeset
   311
fun keyword_reports tok = map (fn markup => ((pos_of tok, markup), ""));
59123
e68e44836d04 imitate command markup and rendering of Isabelle/jEdit in HTML output;
wenzelm
parents: 59112
diff changeset
   312
59125
ee19c92ae8b4 more explicit markup for improper commands;
wenzelm
parents: 59124
diff changeset
   313
fun command_markups keywords x =
66067
cdbcb417db67 more markup for HTML rendering;
wenzelm
parents: 66066
diff changeset
   314
  if Keyword.is_theory_end keywords x then [Markup.keyword2 |> Markup.keyword_properties]
65174
c0388fbd8096 avoid extra decorations for regular command keywords;
wenzelm
parents: 64677
diff changeset
   315
  else
c0388fbd8096 avoid extra decorations for regular command keywords;
wenzelm
parents: 64677
diff changeset
   316
    (if Keyword.is_proof_asm keywords x then [Markup.keyword3]
c0388fbd8096 avoid extra decorations for regular command keywords;
wenzelm
parents: 64677
diff changeset
   317
     else if Keyword.is_improper keywords x then [Markup.keyword1, Markup.improper]
c0388fbd8096 avoid extra decorations for regular command keywords;
wenzelm
parents: 64677
diff changeset
   318
     else [Markup.keyword1])
66066
7ac97dea27d2 tuned signature;
wenzelm
parents: 66044
diff changeset
   319
    |> map Markup.command_properties;
59123
e68e44836d04 imitate command markup and rendering of Isabelle/jEdit in HTML output;
wenzelm
parents: 59112
diff changeset
   320
56063
38f13d055107 more explicit markup for Token.Literal;
wenzelm
parents: 55919
diff changeset
   321
in
38f13d055107 more explicit markup for Token.Literal;
wenzelm
parents: 55919
diff changeset
   322
56202
0a11d17eeeff more markup for improper elements;
wenzelm
parents: 56064
diff changeset
   323
fun keyword_markup (important, keyword) x =
0a11d17eeeff more markup for improper elements;
wenzelm
parents: 56064
diff changeset
   324
  if important orelse Symbol.is_ascii_identifier x then keyword else Markup.delimiter;
55919
2eb8c13339a5 more explicit quasi_keyword markup, for Args.$$$ material, which is somewhere in between of outer and inner syntax;
wenzelm
parents: 55916
diff changeset
   325
55915
607948c90bf0 suppress short abbreviations more uniformly, for outer and quasi-outer syntax;
wenzelm
parents: 55914
diff changeset
   326
fun completion_report tok =
55914
c5b752d549e3 clarified init_assignable: make double-sure that initial values are reset;
wenzelm
parents: 55828
diff changeset
   327
  if is_kind Keyword tok
55915
607948c90bf0 suppress short abbreviations more uniformly, for outer and quasi-outer syntax;
wenzelm
parents: 55914
diff changeset
   328
  then map (fn m => ((pos_of tok, m), "")) (Completion.suppress_abbrevs (content_of tok))
607948c90bf0 suppress short abbreviations more uniformly, for outer and quasi-outer syntax;
wenzelm
parents: 55914
diff changeset
   329
  else [];
55744
4a4e5686e091 clarified token markup: keyword1/keyword2 is for syntax, and "command" the entity kind;
wenzelm
parents: 55709
diff changeset
   330
59125
ee19c92ae8b4 more explicit markup for improper commands;
wenzelm
parents: 59124
diff changeset
   331
fun reports keywords tok =
59123
e68e44836d04 imitate command markup and rendering of Isabelle/jEdit in HTML output;
wenzelm
parents: 59112
diff changeset
   332
  if is_command tok then
59125
ee19c92ae8b4 more explicit markup for improper commands;
wenzelm
parents: 59124
diff changeset
   333
    keyword_reports tok (command_markups keywords (content_of tok))
59123
e68e44836d04 imitate command markup and rendering of Isabelle/jEdit in HTML output;
wenzelm
parents: 59112
diff changeset
   334
  else if is_kind Keyword tok then
66044
bd7516709051 more HTML rendering as in Isabelle/jEdit;
wenzelm
parents: 65174
diff changeset
   335
    keyword_reports tok
66067
cdbcb417db67 more markup for HTML rendering;
wenzelm
parents: 66066
diff changeset
   336
      [keyword_markup (false, Markup.keyword2 |> Markup.keyword_properties) (content_of tok)]
55915
607948c90bf0 suppress short abbreviations more uniformly, for outer and quasi-outer syntax;
wenzelm
parents: 55914
diff changeset
   337
  else
68298
2c3ce27cf4a8 markup for deleted fragments of token source (NB: quoted tokens transform "\123" implicitly);
wenzelm
parents: 68183
diff changeset
   338
    let
2c3ce27cf4a8 markup for deleted fragments of token source (NB: quoted tokens transform "\123" implicitly);
wenzelm
parents: 68183
diff changeset
   339
      val pos = pos_of tok;
2c3ce27cf4a8 markup for deleted fragments of token source (NB: quoted tokens transform "\123" implicitly);
wenzelm
parents: 68183
diff changeset
   340
      val (m, text) = token_kind_markup (kind_of tok);
2c3ce27cf4a8 markup for deleted fragments of token source (NB: quoted tokens transform "\123" implicitly);
wenzelm
parents: 68183
diff changeset
   341
      val delete = #2 (Symbol_Pos.explode_delete (source_of tok, pos));
2c3ce27cf4a8 markup for deleted fragments of token source (NB: quoted tokens transform "\123" implicitly);
wenzelm
parents: 68183
diff changeset
   342
    in ((pos, m), text) :: map (fn p => ((p, Markup.delete), "")) delete end;
55915
607948c90bf0 suppress short abbreviations more uniformly, for outer and quasi-outer syntax;
wenzelm
parents: 55914
diff changeset
   343
59125
ee19c92ae8b4 more explicit markup for improper commands;
wenzelm
parents: 59124
diff changeset
   344
fun markups keywords = map (#2 o #1) o reports keywords;
55914
c5b752d549e3 clarified init_assignable: make double-sure that initial values are reset;
wenzelm
parents: 55828
diff changeset
   345
55744
4a4e5686e091 clarified token markup: keyword1/keyword2 is for syntax, and "command" the entity kind;
wenzelm
parents: 55709
diff changeset
   346
end;
4a4e5686e091 clarified token markup: keyword1/keyword2 is for syntax, and "command" the entity kind;
wenzelm
parents: 55709
diff changeset
   347
4a4e5686e091 clarified token markup: keyword1/keyword2 is for syntax, and "command" the entity kind;
wenzelm
parents: 55709
diff changeset
   348
27747
d41abb7bc08a token: maintain of source, which retains original position information;
wenzelm
parents: 27733
diff changeset
   349
(* unparse *)
d41abb7bc08a token: maintain of source, which retains original position information;
wenzelm
parents: 27733
diff changeset
   350
27814
05a50886dacb unified Args.T with OuterLex.token;
wenzelm
parents: 27799
diff changeset
   351
fun unparse (Token (_, (kind, x), _)) =
14991
26fb63c4acb5 added unparse;
wenzelm
parents: 14981
diff changeset
   352
  (case kind of
43773
e8ba493027a3 more precise Symbol_Pos.quote_string;
wenzelm
parents: 43731
diff changeset
   353
    String => Symbol_Pos.quote_string_qq x
59081
2ceb05ee0331 clarified token kind;
wenzelm
parents: 59064
diff changeset
   354
  | Alt_String => Symbol_Pos.quote_string_bq x
43773
e8ba493027a3 more precise Symbol_Pos.quote_string;
wenzelm
parents: 43731
diff changeset
   355
  | Verbatim => enclose "{*" "*}" x
55033
8e8243975860 support for nested text cartouches;
wenzelm
parents: 54520
diff changeset
   356
  | Cartouche => cartouche x
67439
78759a7bd874 more uniform support for formal comments in outer syntax, notably \<^cancel> and \<^latex>;
wenzelm
parents: 66067
diff changeset
   357
  | Comment NONE => enclose "(*" "*)" x
23729
d1ba656978c5 separated Malformed (symbolic char) from Error (bad input);
wenzelm
parents: 23721
diff changeset
   358
  | EOF => ""
14991
26fb63c4acb5 added unparse;
wenzelm
parents: 14981
diff changeset
   359
  | _ => x);
26fb63c4acb5 added unparse;
wenzelm
parents: 14981
diff changeset
   360
59125
ee19c92ae8b4 more explicit markup for improper commands;
wenzelm
parents: 59124
diff changeset
   361
fun print tok = Markup.markups (markups Keyword.empty_keywords tok) (unparse tok);
55745
b865c3035d5c tuned message -- more markup;
wenzelm
parents: 55744
diff changeset
   362
23788
54ce229dc858 Symbol.not_eof/sync is superceded by Symbol.is_regular (rules out further control symbols);
wenzelm
parents: 23729
diff changeset
   363
fun text_of tok =
58861
5ff61774df11 command-line terminator ";" is no longer accepted;
wenzelm
parents: 58855
diff changeset
   364
  let
5ff61774df11 command-line terminator ";" is no longer accepted;
wenzelm
parents: 58855
diff changeset
   365
    val k = str_of_kind (kind_of tok);
59125
ee19c92ae8b4 more explicit markup for improper commands;
wenzelm
parents: 59124
diff changeset
   366
    val ms = markups Keyword.empty_keywords tok;
58861
5ff61774df11 command-line terminator ";" is no longer accepted;
wenzelm
parents: 58855
diff changeset
   367
    val s = unparse tok;
5ff61774df11 command-line terminator ";" is no longer accepted;
wenzelm
parents: 58855
diff changeset
   368
  in
5ff61774df11 command-line terminator ";" is no longer accepted;
wenzelm
parents: 58855
diff changeset
   369
    if s = "" then (k, "")
5ff61774df11 command-line terminator ";" is no longer accepted;
wenzelm
parents: 58855
diff changeset
   370
    else if size s < 40 andalso not (exists_string (fn c => c = "\n") s)
59125
ee19c92ae8b4 more explicit markup for improper commands;
wenzelm
parents: 59124
diff changeset
   371
    then (k ^ " " ^ Markup.markups ms s, "")
ee19c92ae8b4 more explicit markup for improper commands;
wenzelm
parents: 59124
diff changeset
   372
    else (k, Markup.markups ms s)
58861
5ff61774df11 command-line terminator ";" is no longer accepted;
wenzelm
parents: 58855
diff changeset
   373
  end;
23729
d1ba656978c5 separated Malformed (symbolic char) from Error (bad input);
wenzelm
parents: 23721
diff changeset
   374
5825
24e4b1780d33 Outer lexical syntax for Isabelle/Isar.
wenzelm
parents:
diff changeset
   375
24e4b1780d33 Outer lexical syntax for Isabelle/Isar.
wenzelm
parents:
diff changeset
   376
27814
05a50886dacb unified Args.T with OuterLex.token;
wenzelm
parents: 27799
diff changeset
   377
(** associated values **)
05a50886dacb unified Args.T with OuterLex.token;
wenzelm
parents: 27799
diff changeset
   378
48867
e9beabf045ab some support for inlining file content into outer syntax token language;
wenzelm
parents: 48771
diff changeset
   379
(* inlined file content *)
e9beabf045ab some support for inlining file content into outer syntax token language;
wenzelm
parents: 48771
diff changeset
   380
69851
29a4f633609e clarified signature;
wenzelm
parents: 68730
diff changeset
   381
fun file_source (file: file) =
29a4f633609e clarified signature;
wenzelm
parents: 68730
diff changeset
   382
  let
29a4f633609e clarified signature;
wenzelm
parents: 68730
diff changeset
   383
    val text = cat_lines (#lines file);
74171
a9e79c3645c4 clarified signature;
wenzelm
parents: 73691
diff changeset
   384
    val end_pos = Position.advance_symbol_explode text (#pos file);
69851
29a4f633609e clarified signature;
wenzelm
parents: 68730
diff changeset
   385
  in Input.source true text (Position.range (#pos file, end_pos)) end;
29a4f633609e clarified signature;
wenzelm
parents: 68730
diff changeset
   386
54519
5fed81762406 maintain blobs within document state: digest + text in ML, digest-only in Scala;
wenzelm
parents: 51266
diff changeset
   387
fun get_files (Token (_, _, Value (SOME (Files files)))) = files
5fed81762406 maintain blobs within document state: digest + text in ML, digest-only in Scala;
wenzelm
parents: 51266
diff changeset
   388
  | get_files _ = [];
48867
e9beabf045ab some support for inlining file content into outer syntax token language;
wenzelm
parents: 48771
diff changeset
   389
54519
5fed81762406 maintain blobs within document state: digest + text in ML, digest-only in Scala;
wenzelm
parents: 51266
diff changeset
   390
fun put_files [] tok = tok
5fed81762406 maintain blobs within document state: digest + text in ML, digest-only in Scala;
wenzelm
parents: 51266
diff changeset
   391
  | put_files files (Token (x, y, Slot)) = Token (x, y, Value (SOME (Files files)))
55708
f4b114070675 tuned signature;
wenzelm
parents: 55111
diff changeset
   392
  | put_files _ tok = raise Fail ("Cannot put inlined files here" ^ Position.here (pos_of tok));
48867
e9beabf045ab some support for inlining file content into outer syntax token language;
wenzelm
parents: 48771
diff changeset
   393
e9beabf045ab some support for inlining file content into outer syntax token language;
wenzelm
parents: 48771
diff changeset
   394
27814
05a50886dacb unified Args.T with OuterLex.token;
wenzelm
parents: 27799
diff changeset
   395
(* access values *)
05a50886dacb unified Args.T with OuterLex.token;
wenzelm
parents: 27799
diff changeset
   396
05a50886dacb unified Args.T with OuterLex.token;
wenzelm
parents: 27799
diff changeset
   397
fun get_value (Token (_, _, Value v)) = v
05a50886dacb unified Args.T with OuterLex.token;
wenzelm
parents: 27799
diff changeset
   398
  | get_value _ = NONE;
05a50886dacb unified Args.T with OuterLex.token;
wenzelm
parents: 27799
diff changeset
   399
05a50886dacb unified Args.T with OuterLex.token;
wenzelm
parents: 27799
diff changeset
   400
fun map_value f (Token (x, y, Value (SOME v))) = Token (x, y, Value (SOME (f v)))
05a50886dacb unified Args.T with OuterLex.token;
wenzelm
parents: 27799
diff changeset
   401
  | map_value _ tok = tok;
05a50886dacb unified Args.T with OuterLex.token;
wenzelm
parents: 27799
diff changeset
   402
61814
1ca1142e1711 clarified type Token.src: plain token list, with usual implicit value assignment;
wenzelm
parents: 61614
diff changeset
   403
61822
wenzelm
parents: 61820
diff changeset
   404
(* reports of value *)
61814
1ca1142e1711 clarified type Token.src: plain token list, with usual implicit value assignment;
wenzelm
parents: 61614
diff changeset
   405
61822
wenzelm
parents: 61820
diff changeset
   406
fun get_assignable_value (Token (_, _, Assignable r)) = ! r
wenzelm
parents: 61820
diff changeset
   407
  | get_assignable_value (Token (_, _, Value v)) = v
wenzelm
parents: 61820
diff changeset
   408
  | get_assignable_value _ = NONE;
60211
c0f686b39ebb modifier markup for all parsed tokens;
wenzelm
parents: 59990
diff changeset
   409
55914
c5b752d549e3 clarified init_assignable: make double-sure that initial values are reset;
wenzelm
parents: 55828
diff changeset
   410
fun reports_of_value tok =
60211
c0f686b39ebb modifier markup for all parsed tokens;
wenzelm
parents: 59990
diff changeset
   411
  (case get_assignable_value tok of
56063
38f13d055107 more explicit markup for Token.Literal;
wenzelm
parents: 55919
diff changeset
   412
    SOME (Literal markup) =>
38f13d055107 more explicit markup for Token.Literal;
wenzelm
parents: 55919
diff changeset
   413
      let
38f13d055107 more explicit markup for Token.Literal;
wenzelm
parents: 55919
diff changeset
   414
        val pos = pos_of tok;
38f13d055107 more explicit markup for Token.Literal;
wenzelm
parents: 55919
diff changeset
   415
        val x = content_of tok;
38f13d055107 more explicit markup for Token.Literal;
wenzelm
parents: 55919
diff changeset
   416
      in
38f13d055107 more explicit markup for Token.Literal;
wenzelm
parents: 55919
diff changeset
   417
        if Position.is_reported pos then
38f13d055107 more explicit markup for Token.Literal;
wenzelm
parents: 55919
diff changeset
   418
          map (pair pos) (keyword_markup markup x :: Completion.suppress_abbrevs x)
38f13d055107 more explicit markup for Token.Literal;
wenzelm
parents: 55919
diff changeset
   419
        else []
38f13d055107 more explicit markup for Token.Literal;
wenzelm
parents: 55919
diff changeset
   420
      end
38f13d055107 more explicit markup for Token.Literal;
wenzelm
parents: 55919
diff changeset
   421
  | _ => []);
55914
c5b752d549e3 clarified init_assignable: make double-sure that initial values are reset;
wenzelm
parents: 55828
diff changeset
   422
27814
05a50886dacb unified Args.T with OuterLex.token;
wenzelm
parents: 27799
diff changeset
   423
61822
wenzelm
parents: 61820
diff changeset
   424
(* name value *)
wenzelm
parents: 61820
diff changeset
   425
wenzelm
parents: 61820
diff changeset
   426
fun name_value a = Name (a, Morphism.identity);
wenzelm
parents: 61820
diff changeset
   427
wenzelm
parents: 61820
diff changeset
   428
fun get_name tok =
wenzelm
parents: 61820
diff changeset
   429
  (case get_assignable_value tok of
wenzelm
parents: 61820
diff changeset
   430
    SOME (Name (a, _)) => SOME a
wenzelm
parents: 61820
diff changeset
   431
  | _ => NONE);
wenzelm
parents: 61820
diff changeset
   432
wenzelm
parents: 61820
diff changeset
   433
59646
48d400469bcb added declare_maxidx operations for Eisbach;
wenzelm
parents: 59125
diff changeset
   434
(* maxidx *)
48d400469bcb added declare_maxidx operations for Eisbach;
wenzelm
parents: 59125
diff changeset
   435
48d400469bcb added declare_maxidx operations for Eisbach;
wenzelm
parents: 59125
diff changeset
   436
fun declare_maxidx tok =
48d400469bcb added declare_maxidx operations for Eisbach;
wenzelm
parents: 59125
diff changeset
   437
  (case get_value tok of
61814
1ca1142e1711 clarified type Token.src: plain token list, with usual implicit value assignment;
wenzelm
parents: 61614
diff changeset
   438
    SOME (Source src) => fold declare_maxidx src
59646
48d400469bcb added declare_maxidx operations for Eisbach;
wenzelm
parents: 59125
diff changeset
   439
  | SOME (Typ T) => Variable.declare_maxidx (Term.maxidx_of_typ T)
48d400469bcb added declare_maxidx operations for Eisbach;
wenzelm
parents: 59125
diff changeset
   440
  | SOME (Term t) => Variable.declare_maxidx (Term.maxidx_of_term t)
48d400469bcb added declare_maxidx operations for Eisbach;
wenzelm
parents: 59125
diff changeset
   441
  | SOME (Fact (_, ths)) => fold (Variable.declare_maxidx o Thm.maxidx_of) ths
48d400469bcb added declare_maxidx operations for Eisbach;
wenzelm
parents: 59125
diff changeset
   442
  | SOME (Attribute _) => I  (* FIXME !? *)
48d400469bcb added declare_maxidx operations for Eisbach;
wenzelm
parents: 59125
diff changeset
   443
  | SOME (Declaration decl) =>
48d400469bcb added declare_maxidx operations for Eisbach;
wenzelm
parents: 59125
diff changeset
   444
      (fn ctxt =>
48d400469bcb added declare_maxidx operations for Eisbach;
wenzelm
parents: 59125
diff changeset
   445
        let val ctxt' = Context.proof_map (Morphism.form decl) ctxt
48d400469bcb added declare_maxidx operations for Eisbach;
wenzelm
parents: 59125
diff changeset
   446
        in Variable.declare_maxidx (Variable.maxidx_of ctxt') ctxt end)
61814
1ca1142e1711 clarified type Token.src: plain token list, with usual implicit value assignment;
wenzelm
parents: 61614
diff changeset
   447
  | _ => I);
59646
48d400469bcb added declare_maxidx operations for Eisbach;
wenzelm
parents: 59125
diff changeset
   448
48d400469bcb added declare_maxidx operations for Eisbach;
wenzelm
parents: 59125
diff changeset
   449
61080
3bccde9cbb9d trim context more thoroughly;
wenzelm
parents: 60211
diff changeset
   450
(* fact values *)
3bccde9cbb9d trim context more thoroughly;
wenzelm
parents: 60211
diff changeset
   451
3bccde9cbb9d trim context more thoroughly;
wenzelm
parents: 60211
diff changeset
   452
fun map_facts f =
3bccde9cbb9d trim context more thoroughly;
wenzelm
parents: 60211
diff changeset
   453
  map_value (fn v =>
3bccde9cbb9d trim context more thoroughly;
wenzelm
parents: 60211
diff changeset
   454
    (case v of
61814
1ca1142e1711 clarified type Token.src: plain token list, with usual implicit value assignment;
wenzelm
parents: 61614
diff changeset
   455
      Source src => Source (map (map_facts f) src)
61820
e65344e3eeb5 tuned signature;
wenzelm
parents: 61819
diff changeset
   456
    | Fact (a, ths) => Fact (a, f a ths)
61814
1ca1142e1711 clarified type Token.src: plain token list, with usual implicit value assignment;
wenzelm
parents: 61614
diff changeset
   457
    | _ => v));
61080
3bccde9cbb9d trim context more thoroughly;
wenzelm
parents: 60211
diff changeset
   458
67652
11716a084cae clarified signature;
wenzelm
parents: 67504
diff changeset
   459
val trim_context_src = (map o map_facts) (K (map Thm.trim_context));
11716a084cae clarified signature;
wenzelm
parents: 67504
diff changeset
   460
61080
3bccde9cbb9d trim context more thoroughly;
wenzelm
parents: 60211
diff changeset
   461
58012
0b0519c41229 support for nested Token.src within Token.T;
wenzelm
parents: 58011
diff changeset
   462
(* transform *)
0b0519c41229 support for nested Token.src within Token.T;
wenzelm
parents: 58011
diff changeset
   463
0b0519c41229 support for nested Token.src within Token.T;
wenzelm
parents: 58011
diff changeset
   464
fun transform phi =
0b0519c41229 support for nested Token.src within Token.T;
wenzelm
parents: 58011
diff changeset
   465
  map_value (fn v =>
0b0519c41229 support for nested Token.src within Token.T;
wenzelm
parents: 58011
diff changeset
   466
    (case v of
61814
1ca1142e1711 clarified type Token.src: plain token list, with usual implicit value assignment;
wenzelm
parents: 61614
diff changeset
   467
      Source src => Source (map (transform phi) src)
58012
0b0519c41229 support for nested Token.src within Token.T;
wenzelm
parents: 58011
diff changeset
   468
    | Literal _ => v
0b0519c41229 support for nested Token.src within Token.T;
wenzelm
parents: 58011
diff changeset
   469
    | Name (a, psi) => Name (a, psi $> phi)
0b0519c41229 support for nested Token.src within Token.T;
wenzelm
parents: 58011
diff changeset
   470
    | Typ T => Typ (Morphism.typ phi T)
0b0519c41229 support for nested Token.src within Token.T;
wenzelm
parents: 58011
diff changeset
   471
    | Term t => Term (Morphism.term phi t)
0b0519c41229 support for nested Token.src within Token.T;
wenzelm
parents: 58011
diff changeset
   472
    | Fact (a, ths) => Fact (a, Morphism.fact phi ths)
0b0519c41229 support for nested Token.src within Token.T;
wenzelm
parents: 58011
diff changeset
   473
    | Attribute att => Attribute (Morphism.transform phi att)
58017
5bdb58845eab support for declaration within token source;
wenzelm
parents: 58012
diff changeset
   474
    | Declaration decl => Declaration (Morphism.transform phi decl)
61814
1ca1142e1711 clarified type Token.src: plain token list, with usual implicit value assignment;
wenzelm
parents: 61614
diff changeset
   475
    | Files _ => v));
58012
0b0519c41229 support for nested Token.src within Token.T;
wenzelm
parents: 58011
diff changeset
   476
0b0519c41229 support for nested Token.src within Token.T;
wenzelm
parents: 58011
diff changeset
   477
0b0519c41229 support for nested Token.src within Token.T;
wenzelm
parents: 58011
diff changeset
   478
(* static binding *)
0b0519c41229 support for nested Token.src within Token.T;
wenzelm
parents: 58011
diff changeset
   479
0b0519c41229 support for nested Token.src within Token.T;
wenzelm
parents: 58011
diff changeset
   480
(*1st stage: initialize assignable slots*)
61814
1ca1142e1711 clarified type Token.src: plain token list, with usual implicit value assignment;
wenzelm
parents: 61614
diff changeset
   481
fun init_assignable tok =
1ca1142e1711 clarified type Token.src: plain token list, with usual implicit value assignment;
wenzelm
parents: 61614
diff changeset
   482
  (case tok of
1ca1142e1711 clarified type Token.src: plain token list, with usual implicit value assignment;
wenzelm
parents: 61614
diff changeset
   483
    Token (x, y, Slot) => Token (x, y, Assignable (Unsynchronized.ref NONE))
1ca1142e1711 clarified type Token.src: plain token list, with usual implicit value assignment;
wenzelm
parents: 61614
diff changeset
   484
  | Token (_, _, Value _) => tok
1ca1142e1711 clarified type Token.src: plain token list, with usual implicit value assignment;
wenzelm
parents: 61614
diff changeset
   485
  | Token (_, _, Assignable r) => (r := NONE; tok));
58012
0b0519c41229 support for nested Token.src within Token.T;
wenzelm
parents: 58011
diff changeset
   486
0b0519c41229 support for nested Token.src within Token.T;
wenzelm
parents: 58011
diff changeset
   487
(*2nd stage: assign values as side-effect of scanning*)
61814
1ca1142e1711 clarified type Token.src: plain token list, with usual implicit value assignment;
wenzelm
parents: 61614
diff changeset
   488
fun assign v tok =
1ca1142e1711 clarified type Token.src: plain token list, with usual implicit value assignment;
wenzelm
parents: 61614
diff changeset
   489
  (case tok of
1ca1142e1711 clarified type Token.src: plain token list, with usual implicit value assignment;
wenzelm
parents: 61614
diff changeset
   490
    Token (x, y, Slot) => Token (x, y, Value v)
1ca1142e1711 clarified type Token.src: plain token list, with usual implicit value assignment;
wenzelm
parents: 61614
diff changeset
   491
  | Token (_, _, Value _) => tok
1ca1142e1711 clarified type Token.src: plain token list, with usual implicit value assignment;
wenzelm
parents: 61614
diff changeset
   492
  | Token (_, _, Assignable r) => (r := v; tok));
1ca1142e1711 clarified type Token.src: plain token list, with usual implicit value assignment;
wenzelm
parents: 61614
diff changeset
   493
1ca1142e1711 clarified type Token.src: plain token list, with usual implicit value assignment;
wenzelm
parents: 61614
diff changeset
   494
fun evaluate mk eval arg =
1ca1142e1711 clarified type Token.src: plain token list, with usual implicit value assignment;
wenzelm
parents: 61614
diff changeset
   495
  let val x = eval arg in (assign (SOME (mk x)) arg; x) end;
58012
0b0519c41229 support for nested Token.src within Token.T;
wenzelm
parents: 58011
diff changeset
   496
0b0519c41229 support for nested Token.src within Token.T;
wenzelm
parents: 58011
diff changeset
   497
(*3rd stage: static closure of final values*)
0b0519c41229 support for nested Token.src within Token.T;
wenzelm
parents: 58011
diff changeset
   498
fun closure (Token (x, y, Assignable (Unsynchronized.ref v))) = Token (x, y, Value v)
0b0519c41229 support for nested Token.src within Token.T;
wenzelm
parents: 58011
diff changeset
   499
  | closure tok = tok;
0b0519c41229 support for nested Token.src within Token.T;
wenzelm
parents: 58011
diff changeset
   500
0b0519c41229 support for nested Token.src within Token.T;
wenzelm
parents: 58011
diff changeset
   501
0b0519c41229 support for nested Token.src within Token.T;
wenzelm
parents: 58011
diff changeset
   502
(* pretty *)
57944
fff8d328da56 more informative Token.Name with history of morphisms;
wenzelm
parents: 57942
diff changeset
   503
fff8d328da56 more informative Token.Name with history of morphisms;
wenzelm
parents: 57942
diff changeset
   504
fun pretty_value ctxt tok =
fff8d328da56 more informative Token.Name with history of morphisms;
wenzelm
parents: 57942
diff changeset
   505
  (case get_value tok of
fff8d328da56 more informative Token.Name with history of morphisms;
wenzelm
parents: 57942
diff changeset
   506
    SOME (Literal markup) =>
fff8d328da56 more informative Token.Name with history of morphisms;
wenzelm
parents: 57942
diff changeset
   507
      let val x = content_of tok
fff8d328da56 more informative Token.Name with history of morphisms;
wenzelm
parents: 57942
diff changeset
   508
      in Pretty.mark_str (keyword_markup markup x, x) end
61814
1ca1142e1711 clarified type Token.src: plain token list, with usual implicit value assignment;
wenzelm
parents: 61614
diff changeset
   509
  | SOME (Name ({print, ...}, _)) => Pretty.quote (Pretty.mark_str (print ctxt))
57944
fff8d328da56 more informative Token.Name with history of morphisms;
wenzelm
parents: 57942
diff changeset
   510
  | SOME (Typ T) => Syntax.pretty_typ ctxt T
fff8d328da56 more informative Token.Name with history of morphisms;
wenzelm
parents: 57942
diff changeset
   511
  | SOME (Term t) => Syntax.pretty_term ctxt t
fff8d328da56 more informative Token.Name with history of morphisms;
wenzelm
parents: 57942
diff changeset
   512
  | SOME (Fact (_, ths)) =>
62094
7d47cf67516d prefer non-ASCII output;
wenzelm
parents: 61825
diff changeset
   513
      Pretty.enclose "(" ")" (Pretty.breaks (map (Pretty.cartouche o Thm.pretty_thm ctxt) ths))
59125
ee19c92ae8b4 more explicit markup for improper commands;
wenzelm
parents: 59124
diff changeset
   514
  | _ => Pretty.marks_str (markups Keyword.empty_keywords tok, unparse tok));
57944
fff8d328da56 more informative Token.Name with history of morphisms;
wenzelm
parents: 57942
diff changeset
   515
61814
1ca1142e1711 clarified type Token.src: plain token list, with usual implicit value assignment;
wenzelm
parents: 61614
diff changeset
   516
1ca1142e1711 clarified type Token.src: plain token list, with usual implicit value assignment;
wenzelm
parents: 61614
diff changeset
   517
(* src *)
1ca1142e1711 clarified type Token.src: plain token list, with usual implicit value assignment;
wenzelm
parents: 61614
diff changeset
   518
61825
69b035408b18 make SML/NJ happy;
wenzelm
parents: 61822
diff changeset
   519
fun dest_src ([]: src) = raise Fail "Empty token source"
61814
1ca1142e1711 clarified type Token.src: plain token list, with usual implicit value assignment;
wenzelm
parents: 61614
diff changeset
   520
  | dest_src (head :: args) = (head, args);
1ca1142e1711 clarified type Token.src: plain token list, with usual implicit value assignment;
wenzelm
parents: 61614
diff changeset
   521
1ca1142e1711 clarified type Token.src: plain token list, with usual implicit value assignment;
wenzelm
parents: 61614
diff changeset
   522
fun name_of_src src =
1ca1142e1711 clarified type Token.src: plain token list, with usual implicit value assignment;
wenzelm
parents: 61614
diff changeset
   523
  let
1ca1142e1711 clarified type Token.src: plain token list, with usual implicit value assignment;
wenzelm
parents: 61614
diff changeset
   524
    val head = #1 (dest_src src);
1ca1142e1711 clarified type Token.src: plain token list, with usual implicit value assignment;
wenzelm
parents: 61614
diff changeset
   525
    val name =
1ca1142e1711 clarified type Token.src: plain token list, with usual implicit value assignment;
wenzelm
parents: 61614
diff changeset
   526
      (case get_name head of
1ca1142e1711 clarified type Token.src: plain token list, with usual implicit value assignment;
wenzelm
parents: 61614
diff changeset
   527
        SOME {name, ...} => name
1ca1142e1711 clarified type Token.src: plain token list, with usual implicit value assignment;
wenzelm
parents: 61614
diff changeset
   528
      | NONE => content_of head);
1ca1142e1711 clarified type Token.src: plain token list, with usual implicit value assignment;
wenzelm
parents: 61614
diff changeset
   529
  in (name, pos_of head) end;
1ca1142e1711 clarified type Token.src: plain token list, with usual implicit value assignment;
wenzelm
parents: 61614
diff changeset
   530
1ca1142e1711 clarified type Token.src: plain token list, with usual implicit value assignment;
wenzelm
parents: 61614
diff changeset
   531
val args_of_src = #2 o dest_src;
1ca1142e1711 clarified type Token.src: plain token list, with usual implicit value assignment;
wenzelm
parents: 61614
diff changeset
   532
58011
bc6bced136e5 tuned signature -- moved type src to Token, without aliases;
wenzelm
parents: 57944
diff changeset
   533
fun pretty_src ctxt src =
bc6bced136e5 tuned signature -- moved type src to Token, without aliases;
wenzelm
parents: 57944
diff changeset
   534
  let
61814
1ca1142e1711 clarified type Token.src: plain token list, with usual implicit value assignment;
wenzelm
parents: 61614
diff changeset
   535
    val (head, args) = dest_src src;
58011
bc6bced136e5 tuned signature -- moved type src to Token, without aliases;
wenzelm
parents: 57944
diff changeset
   536
    val prt_name =
61814
1ca1142e1711 clarified type Token.src: plain token list, with usual implicit value assignment;
wenzelm
parents: 61614
diff changeset
   537
      (case get_name head of
1ca1142e1711 clarified type Token.src: plain token list, with usual implicit value assignment;
wenzelm
parents: 61614
diff changeset
   538
        SOME {print, ...} => Pretty.mark_str (print ctxt)
1ca1142e1711 clarified type Token.src: plain token list, with usual implicit value assignment;
wenzelm
parents: 61614
diff changeset
   539
      | NONE => Pretty.str (content_of head));
1ca1142e1711 clarified type Token.src: plain token list, with usual implicit value assignment;
wenzelm
parents: 61614
diff changeset
   540
  in Pretty.block (Pretty.breaks (Pretty.quote prt_name :: map (pretty_value ctxt) args)) end;
1ca1142e1711 clarified type Token.src: plain token list, with usual implicit value assignment;
wenzelm
parents: 61614
diff changeset
   541
1ca1142e1711 clarified type Token.src: plain token list, with usual implicit value assignment;
wenzelm
parents: 61614
diff changeset
   542
fun checked_src (head :: _) = is_some (get_name head)
1ca1142e1711 clarified type Token.src: plain token list, with usual implicit value assignment;
wenzelm
parents: 61614
diff changeset
   543
  | checked_src [] = true;
1ca1142e1711 clarified type Token.src: plain token list, with usual implicit value assignment;
wenzelm
parents: 61614
diff changeset
   544
1ca1142e1711 clarified type Token.src: plain token list, with usual implicit value assignment;
wenzelm
parents: 61614
diff changeset
   545
fun check_src ctxt get_table src =
1ca1142e1711 clarified type Token.src: plain token list, with usual implicit value assignment;
wenzelm
parents: 61614
diff changeset
   546
  let
1ca1142e1711 clarified type Token.src: plain token list, with usual implicit value assignment;
wenzelm
parents: 61614
diff changeset
   547
    val (head, args) = dest_src src;
1ca1142e1711 clarified type Token.src: plain token list, with usual implicit value assignment;
wenzelm
parents: 61614
diff changeset
   548
    val table = get_table ctxt;
1ca1142e1711 clarified type Token.src: plain token list, with usual implicit value assignment;
wenzelm
parents: 61614
diff changeset
   549
  in
1ca1142e1711 clarified type Token.src: plain token list, with usual implicit value assignment;
wenzelm
parents: 61614
diff changeset
   550
    (case get_name head of
1ca1142e1711 clarified type Token.src: plain token list, with usual implicit value assignment;
wenzelm
parents: 61614
diff changeset
   551
      SOME {name, ...} => (src, Name_Space.get table name)
1ca1142e1711 clarified type Token.src: plain token list, with usual implicit value assignment;
wenzelm
parents: 61614
diff changeset
   552
    | NONE =>
1ca1142e1711 clarified type Token.src: plain token list, with usual implicit value assignment;
wenzelm
parents: 61614
diff changeset
   553
        let
64421
681fae6b00b5 more careful PIDE reports: avoid duplicates, notably in situation of backtracking loops;
wenzelm
parents: 63936
diff changeset
   554
          val pos = pos_of head;
681fae6b00b5 more careful PIDE reports: avoid duplicates, notably in situation of backtracking loops;
wenzelm
parents: 63936
diff changeset
   555
          val (name, x) = Name_Space.check (Context.Proof ctxt) table (content_of head, pos);
681fae6b00b5 more careful PIDE reports: avoid duplicates, notably in situation of backtracking loops;
wenzelm
parents: 63936
diff changeset
   556
          val _ = Context_Position.report ctxt pos Markup.operator;
61814
1ca1142e1711 clarified type Token.src: plain token list, with usual implicit value assignment;
wenzelm
parents: 61614
diff changeset
   557
          val kind = Name_Space.kind_of (Name_Space.space_of_table table);
1ca1142e1711 clarified type Token.src: plain token list, with usual implicit value assignment;
wenzelm
parents: 61614
diff changeset
   558
          fun print ctxt' =
1ca1142e1711 clarified type Token.src: plain token list, with usual implicit value assignment;
wenzelm
parents: 61614
diff changeset
   559
            Name_Space.markup_extern ctxt' (Name_Space.space_of_table (get_table ctxt')) name;
1ca1142e1711 clarified type Token.src: plain token list, with usual implicit value assignment;
wenzelm
parents: 61614
diff changeset
   560
          val value = name_value {name = name, kind = kind, print = print};
1ca1142e1711 clarified type Token.src: plain token list, with usual implicit value assignment;
wenzelm
parents: 61614
diff changeset
   561
          val head' = closure (assign (SOME value) head);
1ca1142e1711 clarified type Token.src: plain token list, with usual implicit value assignment;
wenzelm
parents: 61614
diff changeset
   562
        in (head' :: args, x) end)
1ca1142e1711 clarified type Token.src: plain token list, with usual implicit value assignment;
wenzelm
parents: 61614
diff changeset
   563
  end;
58011
bc6bced136e5 tuned signature -- moved type src to Token, without aliases;
wenzelm
parents: 57944
diff changeset
   564
bc6bced136e5 tuned signature -- moved type src to Token, without aliases;
wenzelm
parents: 57944
diff changeset
   565
59125
ee19c92ae8b4 more explicit markup for improper commands;
wenzelm
parents: 59124
diff changeset
   566
5825
24e4b1780d33 Outer lexical syntax for Isabelle/Isar.
wenzelm
parents:
diff changeset
   567
(** scanners **)
24e4b1780d33 Outer lexical syntax for Isabelle/Isar.
wenzelm
parents:
diff changeset
   568
30573
49899f26fbd1 de-camelized Symbol_Pos;
wenzelm
parents: 29606
diff changeset
   569
open Basic_Symbol_Pos;
5825
24e4b1780d33 Outer lexical syntax for Isabelle/Isar.
wenzelm
parents:
diff changeset
   570
48764
4fe0920d5049 proper error prefixes;
wenzelm
parents: 48749
diff changeset
   571
val err_prefix = "Outer lexical error: ";
4fe0920d5049 proper error prefixes;
wenzelm
parents: 48749
diff changeset
   572
4fe0920d5049 proper error prefixes;
wenzelm
parents: 48749
diff changeset
   573
fun !!! msg = Symbol_Pos.!!! (fn () => err_prefix ^ msg);
5825
24e4b1780d33 Outer lexical syntax for Isabelle/Isar.
wenzelm
parents:
diff changeset
   574
24e4b1780d33 Outer lexical syntax for Isabelle/Isar.
wenzelm
parents:
diff changeset
   575
24e4b1780d33 Outer lexical syntax for Isabelle/Isar.
wenzelm
parents:
diff changeset
   576
(* scan symbolic idents *)
24e4b1780d33 Outer lexical syntax for Isabelle/Isar.
wenzelm
parents:
diff changeset
   577
8231
fa93309ff27e symid: include single symbolic char;
wenzelm
parents: 7902
diff changeset
   578
val scan_symid =
55033
8e8243975860 support for nested text cartouches;
wenzelm
parents: 54520
diff changeset
   579
  Scan.many1 (Symbol.is_symbolic_char o Symbol_Pos.symbol) ||
40525
14a2e686bdac eliminated slightly odd pervasive Symbol_Pos.symbol;
wenzelm
parents: 40523
diff changeset
   580
  Scan.one (Symbol.is_symbolic o Symbol_Pos.symbol) >> single;
5825
24e4b1780d33 Outer lexical syntax for Isabelle/Isar.
wenzelm
parents:
diff changeset
   581
8231
fa93309ff27e symid: include single symbolic char;
wenzelm
parents: 7902
diff changeset
   582
fun is_symid str =
fa93309ff27e symid: include single symbolic char;
wenzelm
parents: 7902
diff changeset
   583
  (case try Symbol.explode str of
55033
8e8243975860 support for nested text cartouches;
wenzelm
parents: 54520
diff changeset
   584
    SOME [s] => Symbol.is_symbolic s orelse Symbol.is_symbolic_char s
8e8243975860 support for nested text cartouches;
wenzelm
parents: 54520
diff changeset
   585
  | SOME ss => forall Symbol.is_symbolic_char ss
8231
fa93309ff27e symid: include single symbolic char;
wenzelm
parents: 7902
diff changeset
   586
  | _ => false);
fa93309ff27e symid: include single symbolic char;
wenzelm
parents: 7902
diff changeset
   587
27814
05a50886dacb unified Args.T with OuterLex.token;
wenzelm
parents: 27799
diff changeset
   588
fun ident_or_symbolic "begin" = false
05a50886dacb unified Args.T with OuterLex.token;
wenzelm
parents: 27799
diff changeset
   589
  | ident_or_symbolic ":" = true
05a50886dacb unified Args.T with OuterLex.token;
wenzelm
parents: 27799
diff changeset
   590
  | ident_or_symbolic "::" = true
50239
fb579401dc26 tuned signature;
wenzelm
parents: 50201
diff changeset
   591
  | ident_or_symbolic s = Symbol_Pos.is_identifier s orelse is_symid s;
5825
24e4b1780d33 Outer lexical syntax for Isabelle/Isar.
wenzelm
parents:
diff changeset
   592
24e4b1780d33 Outer lexical syntax for Isabelle/Isar.
wenzelm
parents:
diff changeset
   593
24e4b1780d33 Outer lexical syntax for Isabelle/Isar.
wenzelm
parents:
diff changeset
   594
(* scan verbatim text *)
24e4b1780d33 Outer lexical syntax for Isabelle/Isar.
wenzelm
parents:
diff changeset
   595
24e4b1780d33 Outer lexical syntax for Isabelle/Isar.
wenzelm
parents:
diff changeset
   596
val scan_verb =
55107
1a29ea173bf9 tuned signature;
wenzelm
parents: 55106
diff changeset
   597
  $$$ "*" --| Scan.ahead (~$$ "}") ||
58854
b979c781c2db discontinued obsolete \<^sync> marker;
wenzelm
parents: 58850
diff changeset
   598
  Scan.one (fn (s, _) => s <> "*" andalso Symbol.not_eof s) >> single;
5825
24e4b1780d33 Outer lexical syntax for Isabelle/Isar.
wenzelm
parents:
diff changeset
   599
24e4b1780d33 Outer lexical syntax for Isabelle/Isar.
wenzelm
parents:
diff changeset
   600
val scan_verbatim =
55107
1a29ea173bf9 tuned signature;
wenzelm
parents: 55106
diff changeset
   601
  Scan.ahead ($$ "{" -- $$ "*") |--
55106
080c0006e917 tuned error messages, more accurate position;
wenzelm
parents: 55105
diff changeset
   602
    !!! "unclosed verbatim text"
55107
1a29ea173bf9 tuned signature;
wenzelm
parents: 55106
diff changeset
   603
      ((Symbol_Pos.scan_pos --| $$ "{" --| $$ "*") --
61476
1884c40f1539 tuned signature;
wenzelm
parents: 61471
diff changeset
   604
        (Scan.repeats scan_verb -- ($$ "*" |-- $$ "}" |-- Symbol_Pos.scan_pos)));
5825
24e4b1780d33 Outer lexical syntax for Isabelle/Isar.
wenzelm
parents:
diff changeset
   605
48743
a72f8ffecf31 refined recovery of scan errors: longest prefix of delimited token after failure, otherwise just one symbol;
wenzelm
parents: 48741
diff changeset
   606
val recover_verbatim =
61476
1884c40f1539 tuned signature;
wenzelm
parents: 61471
diff changeset
   607
  $$$ "{" @@@ $$$ "*" @@@ Scan.repeats scan_verb;
48743
a72f8ffecf31 refined recovery of scan errors: longest prefix of delimited token after failure, otherwise just one symbol;
wenzelm
parents: 48741
diff changeset
   608
5825
24e4b1780d33 Outer lexical syntax for Isabelle/Isar.
wenzelm
parents:
diff changeset
   609
55033
8e8243975860 support for nested text cartouches;
wenzelm
parents: 54520
diff changeset
   610
(* scan cartouche *)
8e8243975860 support for nested text cartouches;
wenzelm
parents: 54520
diff changeset
   611
8e8243975860 support for nested text cartouches;
wenzelm
parents: 54520
diff changeset
   612
val scan_cartouche =
55104
8284c0d5bf52 clarified scan_cartouche_depth, according to Scala version;
wenzelm
parents: 55103
diff changeset
   613
  Symbol_Pos.scan_pos --
55105
75815b3b38a1 tuned -- more direct err_prefix;
wenzelm
parents: 55104
diff changeset
   614
    ((Symbol_Pos.scan_cartouche err_prefix >> Symbol_Pos.cartouche_content) -- Symbol_Pos.scan_pos);
55033
8e8243975860 support for nested text cartouches;
wenzelm
parents: 54520
diff changeset
   615
8e8243975860 support for nested text cartouches;
wenzelm
parents: 54520
diff changeset
   616
5825
24e4b1780d33 Outer lexical syntax for Isabelle/Isar.
wenzelm
parents:
diff changeset
   617
(* scan space *)
24e4b1780d33 Outer lexical syntax for Isabelle/Isar.
wenzelm
parents:
diff changeset
   618
48771
2ea997196d04 clarified Command.range vs. Command.proper_range according to Scala version, which is potentially relevant for command status markup;
wenzelm
parents: 48764
diff changeset
   619
fun space_symbol (s, _) = Symbol.is_blank s andalso s <> "\n";
5825
24e4b1780d33 Outer lexical syntax for Isabelle/Isar.
wenzelm
parents:
diff changeset
   620
24e4b1780d33 Outer lexical syntax for Isabelle/Isar.
wenzelm
parents:
diff changeset
   621
val scan_space =
48771
2ea997196d04 clarified Command.range vs. Command.proper_range according to Scala version, which is potentially relevant for command status markup;
wenzelm
parents: 48764
diff changeset
   622
  Scan.many1 space_symbol @@@ Scan.optional ($$$ "\n") [] ||
2ea997196d04 clarified Command.range vs. Command.proper_range according to Scala version, which is potentially relevant for command status markup;
wenzelm
parents: 48764
diff changeset
   623
  Scan.many space_symbol @@@ $$$ "\n";
5825
24e4b1780d33 Outer lexical syntax for Isabelle/Isar.
wenzelm
parents:
diff changeset
   624
24e4b1780d33 Outer lexical syntax for Isabelle/Isar.
wenzelm
parents:
diff changeset
   625
27780
7d0910f662f7 more precise positions due to SymbolsPos.implode_delim;
wenzelm
parents: 27769
diff changeset
   626
(* scan comment *)
5825
24e4b1780d33 Outer lexical syntax for Isabelle/Isar.
wenzelm
parents:
diff changeset
   627
24e4b1780d33 Outer lexical syntax for Isabelle/Isar.
wenzelm
parents:
diff changeset
   628
val scan_comment =
55105
75815b3b38a1 tuned -- more direct err_prefix;
wenzelm
parents: 55104
diff changeset
   629
  Symbol_Pos.scan_pos -- (Symbol_Pos.scan_comment_body err_prefix -- Symbol_Pos.scan_pos);
5825
24e4b1780d33 Outer lexical syntax for Isabelle/Isar.
wenzelm
parents:
diff changeset
   630
24e4b1780d33 Outer lexical syntax for Isabelle/Isar.
wenzelm
parents:
diff changeset
   631
27663
098798321622 maintain token range;
wenzelm
parents: 27358
diff changeset
   632
27769
ad50c38ef842 improved position handling due to SymbolPos.T;
wenzelm
parents: 27752
diff changeset
   633
(** token sources **)
5825
24e4b1780d33 Outer lexical syntax for Isabelle/Isar.
wenzelm
parents:
diff changeset
   634
23678
f5d315390edc Malformed token: error msg;
wenzelm
parents: 22873
diff changeset
   635
local
f5d315390edc Malformed token: error msg;
wenzelm
parents: 22873
diff changeset
   636
27769
ad50c38ef842 improved position handling due to SymbolPos.T;
wenzelm
parents: 27752
diff changeset
   637
fun token_leq ((_, syms1), (_, syms2)) = length syms1 <= length syms2;
27780
7d0910f662f7 more precise positions due to SymbolsPos.implode_delim;
wenzelm
parents: 27769
diff changeset
   638
27799
52f07d5292cd tuned SymbolPos interface;
wenzelm
parents: 27780
diff changeset
   639
fun token k ss =
43709
717e96cf9527 discontinued special treatment of hard tabulators;
wenzelm
parents: 42503
diff changeset
   640
  Token ((Symbol_Pos.implode ss, Symbol_Pos.range ss), (k, Symbol_Pos.content ss), Slot);
27799
52f07d5292cd tuned SymbolPos interface;
wenzelm
parents: 27780
diff changeset
   641
52f07d5292cd tuned SymbolPos interface;
wenzelm
parents: 27780
diff changeset
   642
fun token_range k (pos1, (ss, pos2)) =
59112
e670969f34df expand ML cartouches to Input.source;
wenzelm
parents: 59085
diff changeset
   643
  Token (Symbol_Pos.implode_range (pos1, pos2) ss, (k, Symbol_Pos.content ss), Slot);
23678
f5d315390edc Malformed token: error msg;
wenzelm
parents: 22873
diff changeset
   644
59083
88b0b1f28adc tuned signature;
wenzelm
parents: 59081
diff changeset
   645
fun scan_token keywords = !!! "bad input"
48764
4fe0920d5049 proper error prefixes;
wenzelm
parents: 48749
diff changeset
   646
  (Symbol_Pos.scan_string_qq err_prefix >> token_range String ||
59081
2ceb05ee0331 clarified token kind;
wenzelm
parents: 59064
diff changeset
   647
    Symbol_Pos.scan_string_bq err_prefix >> token_range Alt_String ||
27799
52f07d5292cd tuned SymbolPos interface;
wenzelm
parents: 27780
diff changeset
   648
    scan_verbatim >> token_range Verbatim ||
55033
8e8243975860 support for nested text cartouches;
wenzelm
parents: 54520
diff changeset
   649
    scan_cartouche >> token_range Cartouche ||
67439
78759a7bd874 more uniform support for formal comments in outer syntax, notably \<^cancel> and \<^latex>;
wenzelm
parents: 66067
diff changeset
   650
    scan_comment >> token_range (Comment NONE) ||
69891
def3ec9cdb7e document markers are formal comments, and may thus occur anywhere in the command-span;
wenzelm
parents: 69851
diff changeset
   651
    Comment.scan_outer >> (fn (k, ss) => token (Comment (SOME k)) ss) ||
27780
7d0910f662f7 more precise positions due to SymbolsPos.implode_delim;
wenzelm
parents: 27769
diff changeset
   652
    scan_space >> token Space ||
7d0910f662f7 more precise positions due to SymbolsPos.implode_delim;
wenzelm
parents: 27769
diff changeset
   653
    (Scan.max token_leq
27769
ad50c38ef842 improved position handling due to SymbolPos.T;
wenzelm
parents: 27752
diff changeset
   654
      (Scan.max token_leq
58903
38c72f5f6c2e explicit type Keyword.keywords;
wenzelm
parents: 58865
diff changeset
   655
        (Scan.literal (Keyword.major_keywords keywords) >> pair Command)
38c72f5f6c2e explicit type Keyword.keywords;
wenzelm
parents: 58865
diff changeset
   656
        (Scan.literal (Keyword.minor_keywords keywords) >> pair Keyword))
59081
2ceb05ee0331 clarified token kind;
wenzelm
parents: 59064
diff changeset
   657
      (Lexicon.scan_longid >> pair Long_Ident ||
42290
b1f544c84040 discontinued special treatment of structure Lexicon;
wenzelm
parents: 40958
diff changeset
   658
        Lexicon.scan_id >> pair Ident ||
b1f544c84040 discontinued special treatment of structure Lexicon;
wenzelm
parents: 40958
diff changeset
   659
        Lexicon.scan_var >> pair Var ||
59081
2ceb05ee0331 clarified token kind;
wenzelm
parents: 59064
diff changeset
   660
        Lexicon.scan_tid >> pair Type_Ident ||
2ceb05ee0331 clarified token kind;
wenzelm
parents: 59064
diff changeset
   661
        Lexicon.scan_tvar >> pair Type_Var ||
62782
057e8dbe4326 clarified modules;
wenzelm
parents: 62094
diff changeset
   662
        Symbol_Pos.scan_float >> pair Float ||
057e8dbe4326 clarified modules;
wenzelm
parents: 62094
diff changeset
   663
        Symbol_Pos.scan_nat >> pair Nat ||
59081
2ceb05ee0331 clarified token kind;
wenzelm
parents: 59064
diff changeset
   664
        scan_symid >> pair Sym_Ident) >> uncurry token));
27769
ad50c38ef842 improved position handling due to SymbolPos.T;
wenzelm
parents: 27752
diff changeset
   665
ad50c38ef842 improved position handling due to SymbolPos.T;
wenzelm
parents: 27752
diff changeset
   666
fun recover msg =
48743
a72f8ffecf31 refined recovery of scan errors: longest prefix of delimited token after failure, otherwise just one symbol;
wenzelm
parents: 48741
diff changeset
   667
  (Symbol_Pos.recover_string_qq ||
a72f8ffecf31 refined recovery of scan errors: longest prefix of delimited token after failure, otherwise just one symbol;
wenzelm
parents: 48741
diff changeset
   668
    Symbol_Pos.recover_string_bq ||
a72f8ffecf31 refined recovery of scan errors: longest prefix of delimited token after failure, otherwise just one symbol;
wenzelm
parents: 48741
diff changeset
   669
    recover_verbatim ||
55033
8e8243975860 support for nested text cartouches;
wenzelm
parents: 54520
diff changeset
   670
    Symbol_Pos.recover_cartouche ||
48743
a72f8ffecf31 refined recovery of scan errors: longest prefix of delimited token after failure, otherwise just one symbol;
wenzelm
parents: 48741
diff changeset
   671
    Symbol_Pos.recover_comment ||
58854
b979c781c2db discontinued obsolete \<^sync> marker;
wenzelm
parents: 58850
diff changeset
   672
    Scan.one (Symbol.not_eof o Symbol_Pos.symbol) >> single)
27780
7d0910f662f7 more precise positions due to SymbolsPos.implode_delim;
wenzelm
parents: 27769
diff changeset
   673
  >> (single o token (Error msg));
23678
f5d315390edc Malformed token: error msg;
wenzelm
parents: 22873
diff changeset
   674
f5d315390edc Malformed token: error msg;
wenzelm
parents: 22873
diff changeset
   675
in
5825
24e4b1780d33 Outer lexical syntax for Isabelle/Isar.
wenzelm
parents:
diff changeset
   676
67497
3a0b08e7dfe9 clarified signature;
wenzelm
parents: 67495
diff changeset
   677
fun make_source keywords {strict} =
58864
505a8150368a recover via scanner;
wenzelm
parents: 58863
diff changeset
   678
  let
59083
88b0b1f28adc tuned signature;
wenzelm
parents: 59081
diff changeset
   679
    val scan_strict = Scan.bulk (scan_token keywords);
58864
505a8150368a recover via scanner;
wenzelm
parents: 58863
diff changeset
   680
    val scan = if strict then scan_strict else Scan.recover scan_strict recover;
505a8150368a recover via scanner;
wenzelm
parents: 58863
diff changeset
   681
  in Source.source Symbol_Pos.stopper scan end;
27780
7d0910f662f7 more precise positions due to SymbolsPos.implode_delim;
wenzelm
parents: 27769
diff changeset
   682
61471
9d4c08af61b8 support control symbol antiquotations;
wenzelm
parents: 61268
diff changeset
   683
fun read_cartouche syms =
9d4c08af61b8 support control symbol antiquotations;
wenzelm
parents: 61268
diff changeset
   684
  (case Scan.read Symbol_Pos.stopper (scan_cartouche >> token_range Cartouche) syms of
9d4c08af61b8 support control symbol antiquotations;
wenzelm
parents: 61268
diff changeset
   685
    SOME tok => tok
9d4c08af61b8 support control symbol antiquotations;
wenzelm
parents: 61268
diff changeset
   686
  | NONE => error ("Single cartouche expected" ^ Position.here (#1 (Symbol_Pos.range syms))));
9d4c08af61b8 support control symbol antiquotations;
wenzelm
parents: 61268
diff changeset
   687
23678
f5d315390edc Malformed token: error msg;
wenzelm
parents: 22873
diff changeset
   688
end;
5825
24e4b1780d33 Outer lexical syntax for Isabelle/Isar.
wenzelm
parents:
diff changeset
   689
30586
9674f64a0702 moved basic change_prompt, scan_string, scan_alt_string, scan_quoted to symbol_pos.ML;
wenzelm
parents: 30573
diff changeset
   690
59083
88b0b1f28adc tuned signature;
wenzelm
parents: 59081
diff changeset
   691
(* explode *)
88b0b1f28adc tuned signature;
wenzelm
parents: 59081
diff changeset
   692
67497
3a0b08e7dfe9 clarified signature;
wenzelm
parents: 67495
diff changeset
   693
fun tokenize keywords strict syms =
3a0b08e7dfe9 clarified signature;
wenzelm
parents: 67495
diff changeset
   694
  Source.of_list syms |> make_source keywords strict |> Source.exhaust;
67495
90d760fa8f34 clarified operations;
wenzelm
parents: 67446
diff changeset
   695
90d760fa8f34 clarified operations;
wenzelm
parents: 67446
diff changeset
   696
fun explode keywords pos text =
67497
3a0b08e7dfe9 clarified signature;
wenzelm
parents: 67495
diff changeset
   697
  Symbol_Pos.explode (text, pos) |> tokenize keywords {strict = false};
67495
90d760fa8f34 clarified operations;
wenzelm
parents: 67446
diff changeset
   698
90d760fa8f34 clarified operations;
wenzelm
parents: 67446
diff changeset
   699
fun explode0 keywords = explode keywords Position.none;
59083
88b0b1f28adc tuned signature;
wenzelm
parents: 59081
diff changeset
   700
88b0b1f28adc tuned signature;
wenzelm
parents: 59081
diff changeset
   701
73691
2f9877db82a1 reimplemented Mirabelle as Isabelle/ML presentation hook + Isabelle/Scala tool, but sledgehammer is still inactive;
wenzelm
parents: 71675
diff changeset
   702
(* print names in parsable form *)
63640
c273583f0203 print name in parsable form;
wenzelm
parents: 63019
diff changeset
   703
c273583f0203 print name in parsable form;
wenzelm
parents: 63019
diff changeset
   704
fun print_name keywords name =
c273583f0203 print name in parsable form;
wenzelm
parents: 63019
diff changeset
   705
  ((case explode keywords Position.none name of
c273583f0203 print name in parsable form;
wenzelm
parents: 63019
diff changeset
   706
    [tok] => not (member (op =) [Ident, Long_Ident, Sym_Ident, Nat] (kind_of tok))
c273583f0203 print name in parsable form;
wenzelm
parents: 63019
diff changeset
   707
  | _ => true) ? Symbol_Pos.quote_string_qq) name;
c273583f0203 print name in parsable form;
wenzelm
parents: 63019
diff changeset
   708
73691
2f9877db82a1 reimplemented Mirabelle as Isabelle/ML presentation hook + Isabelle/Scala tool, but sledgehammer is still inactive;
wenzelm
parents: 71675
diff changeset
   709
fun print_properties keywords =
2f9877db82a1 reimplemented Mirabelle as Isabelle/ML presentation hook + Isabelle/Scala tool, but sledgehammer is still inactive;
wenzelm
parents: 71675
diff changeset
   710
  map (apply2 (print_name keywords) #> (fn (a, b) => a ^ " = " ^ b)) #> commas #> enclose "[" "]";
2f9877db82a1 reimplemented Mirabelle as Isabelle/ML presentation hook + Isabelle/Scala tool, but sledgehammer is still inactive;
wenzelm
parents: 71675
diff changeset
   711
63640
c273583f0203 print name in parsable form;
wenzelm
parents: 63019
diff changeset
   712
59085
08a6901eb035 clarified define_command: send tokens more directly, without requiring keywords in ML;
wenzelm
parents: 59083
diff changeset
   713
(* make *)
08a6901eb035 clarified define_command: send tokens more directly, without requiring keywords in ML;
wenzelm
parents: 59083
diff changeset
   714
08a6901eb035 clarified define_command: send tokens more directly, without requiring keywords in ML;
wenzelm
parents: 59083
diff changeset
   715
fun make ((k, n), s) pos =
08a6901eb035 clarified define_command: send tokens more directly, without requiring keywords in ML;
wenzelm
parents: 59083
diff changeset
   716
  let
68183
6560324b1e4d adjust position according to offset of command/exec id;
wenzelm
parents: 67652
diff changeset
   717
    val pos' = Position.advance_offsets n pos;
62797
e08c44eed27f tuned signature;
wenzelm
parents: 62782
diff changeset
   718
    val range = Position.range (pos, pos');
59085
08a6901eb035 clarified define_command: send tokens more directly, without requiring keywords in ML;
wenzelm
parents: 59083
diff changeset
   719
    val tok =
61814
1ca1142e1711 clarified type Token.src: plain token list, with usual implicit value assignment;
wenzelm
parents: 61614
diff changeset
   720
      if 0 <= k andalso k < Vector.length immediate_kinds then
59085
08a6901eb035 clarified define_command: send tokens more directly, without requiring keywords in ML;
wenzelm
parents: 59083
diff changeset
   721
        Token ((s, range), (Vector.sub (immediate_kinds, k), s), Slot)
08a6901eb035 clarified define_command: send tokens more directly, without requiring keywords in ML;
wenzelm
parents: 59083
diff changeset
   722
      else
08a6901eb035 clarified define_command: send tokens more directly, without requiring keywords in ML;
wenzelm
parents: 59083
diff changeset
   723
        (case explode Keyword.empty_keywords pos s of
08a6901eb035 clarified define_command: send tokens more directly, without requiring keywords in ML;
wenzelm
parents: 59083
diff changeset
   724
          [tok] => tok
08a6901eb035 clarified define_command: send tokens more directly, without requiring keywords in ML;
wenzelm
parents: 59083
diff changeset
   725
        | _ => Token ((s, range), (Error (err_prefix ^ "exactly one token expected"), s), Slot))
08a6901eb035 clarified define_command: send tokens more directly, without requiring keywords in ML;
wenzelm
parents: 59083
diff changeset
   726
  in (tok, pos') end;
08a6901eb035 clarified define_command: send tokens more directly, without requiring keywords in ML;
wenzelm
parents: 59083
diff changeset
   727
61814
1ca1142e1711 clarified type Token.src: plain token list, with usual implicit value assignment;
wenzelm
parents: 61614
diff changeset
   728
fun make_string (s, pos) =
62799
wenzelm
parents: 62797
diff changeset
   729
  let
wenzelm
parents: 62797
diff changeset
   730
    val Token ((x, _), y, z) = #1 (make ((~1, 0), Symbol_Pos.quote_string_qq s) Position.none);
62800
7ac100f86863 tuned signature;
wenzelm
parents: 62799
diff changeset
   731
    val pos' = Position.no_range_position pos;
62799
wenzelm
parents: 62797
diff changeset
   732
  in Token ((x, (pos', pos')), y, z) end;
61814
1ca1142e1711 clarified type Token.src: plain token list, with usual implicit value assignment;
wenzelm
parents: 61614
diff changeset
   733
63019
80ef19b51493 prefer internal attribute source;
wenzelm
parents: 62969
diff changeset
   734
val make_int = explode Keyword.empty_keywords Position.none o signed_string_of_int;
80ef19b51493 prefer internal attribute source;
wenzelm
parents: 62969
diff changeset
   735
61814
1ca1142e1711 clarified type Token.src: plain token list, with usual implicit value assignment;
wenzelm
parents: 61614
diff changeset
   736
fun make_src a args = make_string a :: args;
1ca1142e1711 clarified type Token.src: plain token list, with usual implicit value assignment;
wenzelm
parents: 61614
diff changeset
   737
59085
08a6901eb035 clarified define_command: send tokens more directly, without requiring keywords in ML;
wenzelm
parents: 59083
diff changeset
   738
58011
bc6bced136e5 tuned signature -- moved type src to Token, without aliases;
wenzelm
parents: 57944
diff changeset
   739
bc6bced136e5 tuned signature -- moved type src to Token, without aliases;
wenzelm
parents: 57944
diff changeset
   740
(** parsers **)
bc6bced136e5 tuned signature -- moved type src to Token, without aliases;
wenzelm
parents: 57944
diff changeset
   741
bc6bced136e5 tuned signature -- moved type src to Token, without aliases;
wenzelm
parents: 57944
diff changeset
   742
type 'a parser = T list -> 'a * T list;
bc6bced136e5 tuned signature -- moved type src to Token, without aliases;
wenzelm
parents: 57944
diff changeset
   743
type 'a context_parser = Context.generic * T list -> 'a * (Context.generic * T list);
bc6bced136e5 tuned signature -- moved type src to Token, without aliases;
wenzelm
parents: 57944
diff changeset
   744
58045
ab2483fad861 tuned signature;
wenzelm
parents: 58025
diff changeset
   745
67502
1be337a7584f clarified operations;
wenzelm
parents: 67501
diff changeset
   746
(* read body -- e.g. antiquotation source *)
58045
ab2483fad861 tuned signature;
wenzelm
parents: 58025
diff changeset
   747
67502
1be337a7584f clarified operations;
wenzelm
parents: 67501
diff changeset
   748
fun read_body keywords scan =
1be337a7584f clarified operations;
wenzelm
parents: 67501
diff changeset
   749
  tokenize (Keyword.no_command_keywords keywords) {strict = true}
1be337a7584f clarified operations;
wenzelm
parents: 67501
diff changeset
   750
  #> filter is_proper
67504
310114bec0d7 clarified signature;
wenzelm
parents: 67503
diff changeset
   751
  #> Scan.read stopper scan;
58045
ab2483fad861 tuned signature;
wenzelm
parents: 58025
diff changeset
   752
58903
38c72f5f6c2e explicit type Keyword.keywords;
wenzelm
parents: 58865
diff changeset
   753
fun read_antiq keywords scan (syms, pos) =
67502
1be337a7584f clarified operations;
wenzelm
parents: 67501
diff changeset
   754
  (case read_body keywords scan syms of
67504
310114bec0d7 clarified signature;
wenzelm
parents: 67503
diff changeset
   755
    SOME x => x
310114bec0d7 clarified signature;
wenzelm
parents: 67503
diff changeset
   756
  | NONE => error ("Malformed antiquotation" ^ Position.here pos));
58045
ab2483fad861 tuned signature;
wenzelm
parents: 58025
diff changeset
   757
ab2483fad861 tuned signature;
wenzelm
parents: 58025
diff changeset
   758
ab2483fad861 tuned signature;
wenzelm
parents: 58025
diff changeset
   759
(* wrapped syntax *)
ab2483fad861 tuned signature;
wenzelm
parents: 58025
diff changeset
   760
61814
1ca1142e1711 clarified type Token.src: plain token list, with usual implicit value assignment;
wenzelm
parents: 61614
diff changeset
   761
fun syntax_generic scan src context =
58011
bc6bced136e5 tuned signature -- moved type src to Token, without aliases;
wenzelm
parents: 57944
diff changeset
   762
  let
61814
1ca1142e1711 clarified type Token.src: plain token list, with usual implicit value assignment;
wenzelm
parents: 61614
diff changeset
   763
    val (name, pos) = name_of_src src;
64421
681fae6b00b5 more careful PIDE reports: avoid duplicates, notably in situation of backtracking loops;
wenzelm
parents: 63936
diff changeset
   764
    val old_reports = maps reports_of_value src;
61814
1ca1142e1711 clarified type Token.src: plain token list, with usual implicit value assignment;
wenzelm
parents: 61614
diff changeset
   765
    val args1 = map init_assignable (args_of_src src);
58011
bc6bced136e5 tuned signature -- moved type src to Token, without aliases;
wenzelm
parents: 57944
diff changeset
   766
    fun reported_text () =
71675
55cb4271858b less redundant markup reports;
wenzelm
parents: 69891
diff changeset
   767
      if Context_Position.reports_enabled_generic context then
64421
681fae6b00b5 more careful PIDE reports: avoid duplicates, notably in situation of backtracking loops;
wenzelm
parents: 63936
diff changeset
   768
        let val new_reports = maps (reports_of_value o closure) args1 in
681fae6b00b5 more careful PIDE reports: avoid duplicates, notably in situation of backtracking loops;
wenzelm
parents: 63936
diff changeset
   769
          if old_reports <> new_reports then
681fae6b00b5 more careful PIDE reports: avoid duplicates, notably in situation of backtracking loops;
wenzelm
parents: 63936
diff changeset
   770
            map (fn (p, m) => Position.reported_text p m "") new_reports
681fae6b00b5 more careful PIDE reports: avoid duplicates, notably in situation of backtracking loops;
wenzelm
parents: 63936
diff changeset
   771
          else []
681fae6b00b5 more careful PIDE reports: avoid duplicates, notably in situation of backtracking loops;
wenzelm
parents: 63936
diff changeset
   772
        end
58011
bc6bced136e5 tuned signature -- moved type src to Token, without aliases;
wenzelm
parents: 57944
diff changeset
   773
      else [];
bc6bced136e5 tuned signature -- moved type src to Token, without aliases;
wenzelm
parents: 57944
diff changeset
   774
  in
bc6bced136e5 tuned signature -- moved type src to Token, without aliases;
wenzelm
parents: 57944
diff changeset
   775
    (case Scan.error (Scan.finite' stopper (Scan.option scan)) (context, args1) of
bc6bced136e5 tuned signature -- moved type src to Token, without aliases;
wenzelm
parents: 57944
diff changeset
   776
      (SOME x, (context', [])) =>
bc6bced136e5 tuned signature -- moved type src to Token, without aliases;
wenzelm
parents: 57944
diff changeset
   777
        let val _ = Output.report (reported_text ())
bc6bced136e5 tuned signature -- moved type src to Token, without aliases;
wenzelm
parents: 57944
diff changeset
   778
        in (x, context') end
61814
1ca1142e1711 clarified type Token.src: plain token list, with usual implicit value assignment;
wenzelm
parents: 61614
diff changeset
   779
    | (_, (context', args2)) =>
58011
bc6bced136e5 tuned signature -- moved type src to Token, without aliases;
wenzelm
parents: 57944
diff changeset
   780
        let
bc6bced136e5 tuned signature -- moved type src to Token, without aliases;
wenzelm
parents: 57944
diff changeset
   781
          val print_name =
61814
1ca1142e1711 clarified type Token.src: plain token list, with usual implicit value assignment;
wenzelm
parents: 61614
diff changeset
   782
            (case get_name (hd src) of
58011
bc6bced136e5 tuned signature -- moved type src to Token, without aliases;
wenzelm
parents: 57944
diff changeset
   783
              NONE => quote name
61814
1ca1142e1711 clarified type Token.src: plain token list, with usual implicit value assignment;
wenzelm
parents: 61614
diff changeset
   784
            | SOME {kind, print, ...} =>
1ca1142e1711 clarified type Token.src: plain token list, with usual implicit value assignment;
wenzelm
parents: 61614
diff changeset
   785
                let
1ca1142e1711 clarified type Token.src: plain token list, with usual implicit value assignment;
wenzelm
parents: 61614
diff changeset
   786
                  val ctxt' = Context.proof_of context';
1ca1142e1711 clarified type Token.src: plain token list, with usual implicit value assignment;
wenzelm
parents: 61614
diff changeset
   787
                  val (markup, xname) = print ctxt';
1ca1142e1711 clarified type Token.src: plain token list, with usual implicit value assignment;
wenzelm
parents: 61614
diff changeset
   788
                in plain_words kind ^ " " ^ quote (Markup.markup markup xname) end);
58011
bc6bced136e5 tuned signature -- moved type src to Token, without aliases;
wenzelm
parents: 57944
diff changeset
   789
          val print_args =
bc6bced136e5 tuned signature -- moved type src to Token, without aliases;
wenzelm
parents: 57944
diff changeset
   790
            if null args2 then "" else ":\n  " ^ space_implode " " (map print args2);
bc6bced136e5 tuned signature -- moved type src to Token, without aliases;
wenzelm
parents: 57944
diff changeset
   791
        in
bc6bced136e5 tuned signature -- moved type src to Token, without aliases;
wenzelm
parents: 57944
diff changeset
   792
          error ("Bad arguments for " ^ print_name ^ Position.here pos ^ print_args ^
bc6bced136e5 tuned signature -- moved type src to Token, without aliases;
wenzelm
parents: 57944
diff changeset
   793
            Markup.markup_report (implode (reported_text ())))
bc6bced136e5 tuned signature -- moved type src to Token, without aliases;
wenzelm
parents: 57944
diff changeset
   794
        end)
bc6bced136e5 tuned signature -- moved type src to Token, without aliases;
wenzelm
parents: 57944
diff changeset
   795
  end;
bc6bced136e5 tuned signature -- moved type src to Token, without aliases;
wenzelm
parents: 57944
diff changeset
   796
bc6bced136e5 tuned signature -- moved type src to Token, without aliases;
wenzelm
parents: 57944
diff changeset
   797
fun syntax scan src = apsnd Context.the_proof o syntax_generic scan src o Context.Proof;
bc6bced136e5 tuned signature -- moved type src to Token, without aliases;
wenzelm
parents: 57944
diff changeset
   798
5825
24e4b1780d33 Outer lexical syntax for Isabelle/Isar.
wenzelm
parents:
diff changeset
   799
end;
58011
bc6bced136e5 tuned signature -- moved type src to Token, without aliases;
wenzelm
parents: 57944
diff changeset
   800
bc6bced136e5 tuned signature -- moved type src to Token, without aliases;
wenzelm
parents: 57944
diff changeset
   801
type 'a parser = 'a Token.parser;
bc6bced136e5 tuned signature -- moved type src to Token, without aliases;
wenzelm
parents: 57944
diff changeset
   802
type 'a context_parser = 'a Token.context_parser;