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