author | blanchet |
Mon, 06 Dec 2010 13:29:23 +0100 | |
changeset 40996 | 63112be4a469 |
parent 40800 | 330eb65c9469 |
child 42287 | d98eb048a2e4 |
permissions | -rw-r--r-- |
36949
080e85d46108
renamed structure OuterKeyword to Keyword and OuterParse to Parse, keeping the old names as legacy aliases for some time;
wenzelm
parents:
35838
diff
changeset
|
1 |
(* Title: Pure/Isar/parse.ML |
5826 | 2 |
Author: Markus Wenzel, TU Muenchen |
3 |
||
4 |
Generic parsers for Isabelle/Isar outer syntax. |
|
5 |
*) |
|
6 |
||
36949
080e85d46108
renamed structure OuterKeyword to Keyword and OuterParse to Parse, keeping the old names as legacy aliases for some time;
wenzelm
parents:
35838
diff
changeset
|
7 |
signature PARSE = |
5826 | 8 |
sig |
36959
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents:
36955
diff
changeset
|
9 |
type 'a parser = Token.T list -> 'a * Token.T list |
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents:
36955
diff
changeset
|
10 |
type 'a context_parser = Context.generic * Token.T list -> 'a * (Context.generic * Token.T list) |
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents:
36955
diff
changeset
|
11 |
val group: string -> (Token.T list -> 'a) -> Token.T list -> 'a |
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents:
36955
diff
changeset
|
12 |
val !!! : (Token.T list -> 'a) -> Token.T list -> 'a |
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents:
36955
diff
changeset
|
13 |
val !!!! : (Token.T list -> 'a) -> Token.T list -> 'a |
12047 | 14 |
val triple1: ('a * 'b) * 'c -> 'a * 'b * 'c |
15 |
val triple2: 'a * ('b * 'c) -> 'a * 'b * 'c |
|
16 |
val triple_swap: ('a * 'b) * 'c -> ('a * 'c) * 'b |
|
36959
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents:
36955
diff
changeset
|
17 |
val not_eof: Token.T parser |
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents:
36955
diff
changeset
|
18 |
val position: (Token.T list -> 'a * 'b) -> Token.T list -> ('a * Position.T) * 'b |
29310 | 19 |
val command: string parser |
20 |
val keyword: string parser |
|
21 |
val short_ident: string parser |
|
22 |
val long_ident: string parser |
|
23 |
val sym_ident: string parser |
|
24 |
val minus: string parser |
|
25 |
val term_var: string parser |
|
26 |
val type_ident: string parser |
|
27 |
val type_var: string parser |
|
28 |
val number: string parser |
|
40290
47f572aff50a
support for floating-point tokens in outer syntax (coinciding with inner syntax version);
wenzelm
parents:
36959
diff
changeset
|
29 |
val float_number: string parser |
29310 | 30 |
val string: string parser |
31 |
val alt_string: string parser |
|
32 |
val verbatim: string parser |
|
33 |
val sync: string parser |
|
34 |
val eof: string parser |
|
35 |
val keyword_with: (string -> bool) -> string parser |
|
36 |
val keyword_ident_or_symbolic: string parser |
|
37 |
val $$$ : string -> string parser |
|
38 |
val reserved: string -> string parser |
|
39 |
val semicolon: string parser |
|
40 |
val underscore: string parser |
|
41 |
val maybe: 'a parser -> 'a option parser |
|
42 |
val tag_name: string parser |
|
43 |
val tags: string list parser |
|
44 |
val opt_unit: unit parser |
|
45 |
val opt_keyword: string -> bool parser |
|
46 |
val begin: string parser |
|
47 |
val opt_begin: bool parser |
|
48 |
val nat: int parser |
|
49 |
val int: int parser |
|
40290
47f572aff50a
support for floating-point tokens in outer syntax (coinciding with inner syntax version);
wenzelm
parents:
36959
diff
changeset
|
50 |
val real: real parser |
29310 | 51 |
val enum: string -> 'a parser -> 'a list parser |
52 |
val enum1: string -> 'a parser -> 'a list parser |
|
53 |
val and_list: 'a parser -> 'a list parser |
|
54 |
val and_list1: 'a parser -> 'a list parser |
|
30511 | 55 |
val enum': string -> 'a context_parser -> 'a list context_parser |
56 |
val enum1': string -> 'a context_parser -> 'a list context_parser |
|
57 |
val and_list': 'a context_parser -> 'a list context_parser |
|
58 |
val and_list1': 'a context_parser -> 'a list context_parser |
|
29310 | 59 |
val list: 'a parser -> 'a list parser |
60 |
val list1: 'a parser -> 'a list parser |
|
61 |
val name: bstring parser |
|
29581 | 62 |
val binding: binding parser |
29310 | 63 |
val xname: xstring parser |
64 |
val text: string parser |
|
65 |
val path: Path.T parser |
|
40800
330eb65c9469
Parse.liberal_name for document antiquotations and attributes;
wenzelm
parents:
40793
diff
changeset
|
66 |
val liberal_name: xstring parser |
29310 | 67 |
val parname: string parser |
29581 | 68 |
val parbinding: binding parser |
29310 | 69 |
val sort: string parser |
70 |
val arity: (string * string list * string) parser |
|
71 |
val multi_arity: (string list * string list * string) parser |
|
72 |
val type_args: string list parser |
|
35838 | 73 |
val type_args_constrained: (string * string option) list parser |
29310 | 74 |
val typ_group: string parser |
75 |
val typ: string parser |
|
76 |
val mixfix: mixfix parser |
|
77 |
val mixfix': mixfix parser |
|
78 |
val opt_mixfix: mixfix parser |
|
79 |
val opt_mixfix': mixfix parser |
|
80 |
val where_: string parser |
|
81 |
val const: (string * string * mixfix) parser |
|
30339 | 82 |
val const_binding: (binding * string * mixfix) parser |
29581 | 83 |
val params: (binding * string option) list parser |
84 |
val simple_fixes: (binding * string option) list parser |
|
85 |
val fixes: (binding * string option * mixfix) list parser |
|
86 |
val for_fixes: (binding * string option * mixfix) list parser |
|
87 |
val for_simple_fixes: (binding * string option) list parser |
|
30573 | 88 |
val ML_source: (Symbol_Pos.text * Position.T) parser |
89 |
val doc_source: (Symbol_Pos.text * Position.T) parser |
|
29310 | 90 |
val term_group: string parser |
91 |
val prop_group: string parser |
|
92 |
val term: string parser |
|
93 |
val prop: string parser |
|
40793
d21aedaa91e7
added Parse.literal_fact with proper inner_syntax markup (source position);
wenzelm
parents:
40296
diff
changeset
|
94 |
val literal_fact: string parser |
29310 | 95 |
val propp: (string * string list) parser |
96 |
val termp: (string * string list) parser |
|
97 |
val target: xstring parser |
|
98 |
val opt_target: xstring option parser |
|
5826 | 99 |
end; |
100 |
||
36949
080e85d46108
renamed structure OuterKeyword to Keyword and OuterParse to Parse, keeping the old names as legacy aliases for some time;
wenzelm
parents:
35838
diff
changeset
|
101 |
structure Parse: PARSE = |
5826 | 102 |
struct |
103 |
||
36959
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents:
36955
diff
changeset
|
104 |
type 'a parser = Token.T list -> 'a * Token.T list; |
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents:
36955
diff
changeset
|
105 |
type 'a context_parser = Context.generic * Token.T list -> 'a * (Context.generic * Token.T list); |
29310 | 106 |
|
5826 | 107 |
|
108 |
(** error handling **) |
|
109 |
||
110 |
(* group atomic parsers (no cuts!) *) |
|
111 |
||
112 |
fun fail_with s = Scan.fail_with |
|
113 |
(fn [] => s ^ " expected (past end-of-file!)" |
|
23789
1993b865c5ac
replaced OuterLex.name_of by more sophisticated OuterLex.text_of;
wenzelm
parents:
22331
diff
changeset
|
114 |
| (tok :: _) => |
36959
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents:
36955
diff
changeset
|
115 |
(case Token.text_of tok of |
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents:
36955
diff
changeset
|
116 |
(txt, "") => |
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents:
36955
diff
changeset
|
117 |
s ^ " expected,\nbut " ^ txt ^ Token.pos_of tok ^ " was found" |
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents:
36955
diff
changeset
|
118 |
| (txt1, txt2) => |
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents:
36955
diff
changeset
|
119 |
s ^ " expected,\nbut " ^ txt1 ^ Token.pos_of tok ^ " was found:\n" ^ txt2)); |
5826 | 120 |
|
121 |
fun group s scan = scan || fail_with s; |
|
122 |
||
123 |
||
5877 | 124 |
(* cut *) |
5826 | 125 |
|
8581
5c7ed2af8bfb
!!!! = cut "Corrupted outer syntax in presentation";
wenzelm
parents:
8350
diff
changeset
|
126 |
fun cut kind scan = |
5826 | 127 |
let |
128 |
fun get_pos [] = " (past end-of-file!)" |
|
36959
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents:
36955
diff
changeset
|
129 |
| get_pos (tok :: _) = Token.pos_of tok; |
5826 | 130 |
|
15531 | 131 |
fun err (toks, NONE) = kind ^ get_pos toks |
25625 | 132 |
| err (toks, SOME msg) = |
133 |
if String.isPrefix kind msg then msg |
|
134 |
else kind ^ get_pos toks ^ ": " ^ msg; |
|
5826 | 135 |
in Scan.!! err scan end; |
136 |
||
8586 | 137 |
fun !!! scan = cut "Outer syntax error" scan; |
138 |
fun !!!! scan = cut "Corrupted outer syntax in presentation" scan; |
|
8581
5c7ed2af8bfb
!!!! = cut "Corrupted outer syntax in presentation";
wenzelm
parents:
8350
diff
changeset
|
139 |
|
5826 | 140 |
|
141 |
||
142 |
(** basic parsers **) |
|
143 |
||
144 |
(* utils *) |
|
145 |
||
146 |
fun triple1 ((x, y), z) = (x, y, z); |
|
147 |
fun triple2 (x, (y, z)) = (x, y, z); |
|
6430 | 148 |
fun triple_swap ((x, y), z) = ((x, z), y); |
5826 | 149 |
|
150 |
||
151 |
(* tokens *) |
|
152 |
||
27815 | 153 |
fun RESET_VALUE atom = (*required for all primitive parsers*) |
36959
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents:
36955
diff
changeset
|
154 |
Scan.ahead (Scan.one (K true)) -- atom >> (fn (arg, x) => (Token.assign NONE arg; x)); |
27815 | 155 |
|
156 |
||
36959
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents:
36955
diff
changeset
|
157 |
val not_eof = RESET_VALUE (Scan.one Token.not_eof); |
15703 | 158 |
|
36959
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents:
36955
diff
changeset
|
159 |
fun position scan = (Scan.ahead not_eof >> Token.position_of) -- scan >> Library.swap; |
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents:
36955
diff
changeset
|
160 |
fun source_position atom = Scan.ahead atom |-- not_eof >> Token.source_position_of; |
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents:
36955
diff
changeset
|
161 |
fun inner_syntax atom = Scan.ahead atom |-- not_eof >> Token.source_of; |
5826 | 162 |
|
163 |
fun kind k = |
|
36959
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents:
36955
diff
changeset
|
164 |
group (Token.str_of_kind k) (RESET_VALUE (Scan.one (Token.is_kind k) >> Token.content_of)); |
5826 | 165 |
|
36959
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents:
36955
diff
changeset
|
166 |
val command = kind Token.Command; |
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents:
36955
diff
changeset
|
167 |
val keyword = kind Token.Keyword; |
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents:
36955
diff
changeset
|
168 |
val short_ident = kind Token.Ident; |
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents:
36955
diff
changeset
|
169 |
val long_ident = kind Token.LongIdent; |
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents:
36955
diff
changeset
|
170 |
val sym_ident = kind Token.SymIdent; |
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents:
36955
diff
changeset
|
171 |
val term_var = kind Token.Var; |
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents:
36955
diff
changeset
|
172 |
val type_ident = kind Token.TypeIdent; |
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents:
36955
diff
changeset
|
173 |
val type_var = kind Token.TypeVar; |
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents:
36955
diff
changeset
|
174 |
val number = kind Token.Nat; |
40290
47f572aff50a
support for floating-point tokens in outer syntax (coinciding with inner syntax version);
wenzelm
parents:
36959
diff
changeset
|
175 |
val float_number = kind Token.Float; |
36959
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents:
36955
diff
changeset
|
176 |
val string = kind Token.String; |
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents:
36955
diff
changeset
|
177 |
val alt_string = kind Token.AltString; |
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents:
36955
diff
changeset
|
178 |
val verbatim = kind Token.Verbatim; |
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents:
36955
diff
changeset
|
179 |
val sync = kind Token.Sync; |
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents:
36955
diff
changeset
|
180 |
val eof = kind Token.EOF; |
5826 | 181 |
|
36959
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents:
36955
diff
changeset
|
182 |
fun keyword_with pred = RESET_VALUE (Scan.one (Token.keyword_with pred) >> Token.content_of); |
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents:
36955
diff
changeset
|
183 |
val keyword_ident_or_symbolic = keyword_with Token.ident_or_symbolic; |
27815 | 184 |
|
5826 | 185 |
fun $$$ x = |
36959
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents:
36955
diff
changeset
|
186 |
group (Token.str_of_kind Token.Keyword ^ " " ^ quote x) (keyword_with (fn y => x = y)); |
9131 | 187 |
|
16030 | 188 |
fun reserved x = |
27753
94b672153b49
sort/typ/term/prop: inner_syntax markup encodes original source position;
wenzelm
parents:
27737
diff
changeset
|
189 |
group ("reserved identifier " ^ quote x) |
36959
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents:
36955
diff
changeset
|
190 |
(RESET_VALUE (Scan.one (Token.ident_with (fn y => x = y)) >> Token.content_of)); |
16030 | 191 |
|
9131 | 192 |
val semicolon = $$$ ";"; |
5826 | 193 |
|
15703 | 194 |
val minus = sym_ident :-- (fn "-" => Scan.succeed () | _ => Scan.fail) >> #1; |
11792
311eee3d63b6
parser for underscore (actually a symbolic identifier!);
wenzelm
parents:
11651
diff
changeset
|
195 |
val underscore = sym_ident :-- (fn "_" => Scan.succeed () | _ => Scan.fail) >> #1; |
15703 | 196 |
fun maybe scan = underscore >> K NONE || scan >> SOME; |
11792
311eee3d63b6
parser for underscore (actually a symbolic identifier!);
wenzelm
parents:
11651
diff
changeset
|
197 |
|
14835 | 198 |
val nat = number >> (#1 o Library.read_int o Symbol.explode); |
27815 | 199 |
val int = Scan.optional (minus >> K ~1) 1 -- nat >> op *; |
40296 | 200 |
val real = float_number >> (the o Real.fromString) || int >> Real.fromInt; |
5826 | 201 |
|
17070 | 202 |
val tag_name = group "tag name" (short_ident || string); |
203 |
val tags = Scan.repeat ($$$ "%" |-- !!! tag_name); |
|
204 |
||
7930 | 205 |
val opt_unit = Scan.optional ($$$ "(" -- $$$ ")" >> (K ())) (); |
14646 | 206 |
fun opt_keyword s = Scan.optional ($$$ "(" |-- !!! (($$$ s >> K true) --| $$$ ")")) false; |
207 |
||
20983 | 208 |
val begin = $$$ "begin"; |
209 |
val opt_begin = Scan.optional (begin >> K true) false; |
|
20961 | 210 |
|
5826 | 211 |
|
212 |
(* enumerations *) |
|
213 |
||
25999 | 214 |
fun enum1 sep scan = scan ::: Scan.repeat ($$$ sep |-- !!! scan); |
5826 | 215 |
fun enum sep scan = enum1 sep scan || Scan.succeed []; |
216 |
||
27815 | 217 |
fun enum1' sep scan = scan ::: Scan.repeat (Scan.lift ($$$ sep) |-- scan); |
218 |
fun enum' sep scan = enum1' sep scan || Scan.succeed []; |
|
5826 | 219 |
|
6013 | 220 |
fun and_list1 scan = enum1 "and" scan; |
221 |
fun and_list scan = enum "and" scan; |
|
222 |
||
27815 | 223 |
fun and_list1' scan = enum1' "and" scan; |
224 |
fun and_list' scan = enum' "and" scan; |
|
225 |
||
226 |
fun list1 scan = enum1 "," scan; |
|
227 |
fun list scan = enum "," scan; |
|
228 |
||
5826 | 229 |
|
5960 | 230 |
(* names and text *) |
5826 | 231 |
|
8146 | 232 |
val name = group "name declaration" (short_ident || sym_ident || string || number); |
30223
24d975352879
renamed Binding.name_pos to Binding.make, renamed Binding.base_name to Binding.name_of, renamed Binding.map_base to Binding.map_name, added mandatory flag to Binding.qualify;
wenzelm
parents:
29581
diff
changeset
|
233 |
val binding = position name >> Binding.make; |
8146 | 234 |
val xname = group "name reference" (short_ident || long_ident || sym_ident || string || number); |
235 |
val text = group "text" (short_ident || long_ident || sym_ident || string || number || verbatim); |
|
21858
05f57309170c
avoid conflict with Alice keywords: renamed pack -> implode, unpack -> explode, any -> many, avoided assert;
wenzelm
parents:
21609
diff
changeset
|
236 |
val path = group "file name/path specification" name >> Path.explode; |
6553 | 237 |
|
40800
330eb65c9469
Parse.liberal_name for document antiquotations and attributes;
wenzelm
parents:
40793
diff
changeset
|
238 |
val liberal_name = keyword_ident_or_symbolic || xname; |
330eb65c9469
Parse.liberal_name for document antiquotations and attributes;
wenzelm
parents:
40793
diff
changeset
|
239 |
|
18898 | 240 |
val parname = Scan.optional ($$$ "(" |-- name --| $$$ ")") ""; |
28965 | 241 |
val parbinding = Scan.optional ($$$ "(" |-- binding --| $$$ ")") Binding.empty; |
18898 | 242 |
|
6553 | 243 |
|
6372 | 244 |
(* sorts and arities *) |
5826 | 245 |
|
27753
94b672153b49
sort/typ/term/prop: inner_syntax markup encodes original source position;
wenzelm
parents:
27737
diff
changeset
|
246 |
val sort = group "sort" (inner_syntax xname); |
5826 | 247 |
|
22331 | 248 |
val arity = xname -- ($$$ "::" |-- !!! |
249 |
(Scan.optional ($$$ "(" |-- !!! (list1 sort --| $$$ ")")) [] -- sort)) >> triple2; |
|
5826 | 250 |
|
25541 | 251 |
val multi_arity = and_list1 xname -- ($$$ "::" |-- !!! |
252 |
(Scan.optional ($$$ "(" |-- !!! (list1 sort --| $$$ ")")) [] -- sort)) >> triple2; |
|
253 |
||
5826 | 254 |
|
255 |
(* types *) |
|
256 |
||
27753
94b672153b49
sort/typ/term/prop: inner_syntax markup encodes original source position;
wenzelm
parents:
27737
diff
changeset
|
257 |
val typ_group = group "type" |
8146 | 258 |
(short_ident || long_ident || sym_ident || type_ident || type_var || string || number); |
5826 | 259 |
|
27753
94b672153b49
sort/typ/term/prop: inner_syntax markup encodes original source position;
wenzelm
parents:
27737
diff
changeset
|
260 |
val typ = inner_syntax typ_group; |
94b672153b49
sort/typ/term/prop: inner_syntax markup encodes original source position;
wenzelm
parents:
27737
diff
changeset
|
261 |
|
35838 | 262 |
fun type_arguments arg = |
263 |
arg >> single || |
|
264 |
$$$ "(" |-- !!! (list1 arg --| $$$ ")") || |
|
5826 | 265 |
Scan.succeed []; |
266 |
||
35838 | 267 |
val type_args = type_arguments type_ident; |
268 |
val type_args_constrained = type_arguments (type_ident -- Scan.option ($$$ "::" |-- !!! sort)); |
|
269 |
||
5826 | 270 |
|
271 |
(* mixfix annotations *) |
|
272 |
||
18669 | 273 |
val mfix = string -- |
274 |
!!! (Scan.optional ($$$ "[" |-- !!! (list nat --| $$$ "]")) [] -- |
|
275 |
Scan.optional nat Syntax.max_pri) >> (Mixfix o triple2); |
|
276 |
||
35130 | 277 |
val infx = $$$ "infix" |-- !!! (string -- nat >> Infix); |
278 |
val infxl = $$$ "infixl" |-- !!! (string -- nat >> Infixl); |
|
279 |
val infxr = $$$ "infixr" |-- !!! (string -- nat >> Infixr); |
|
5826 | 280 |
|
18669 | 281 |
val binder = $$$ "binder" |-- |
282 |
!!! (string -- ($$$ "[" |-- nat --| $$$ "]" -- nat || nat >> (fn n => (n, n)))) |
|
283 |
>> (Binder o triple2); |
|
284 |
||
285 |
fun annotation guard fix = $$$ "(" |-- guard (fix --| $$$ ")"); |
|
286 |
fun opt_annotation guard fix = Scan.optional (annotation guard fix) NoSyn; |
|
287 |
||
288 |
val mixfix = annotation !!! (mfix || binder || infxl || infxr || infx); |
|
21609 | 289 |
val mixfix' = annotation I (mfix || binder || infxl || infxr || infx); |
18669 | 290 |
val opt_mixfix = opt_annotation !!! (mfix || binder || infxl || infxr || infx); |
291 |
val opt_mixfix' = opt_annotation I (mfix || binder || infxl || infxr || infx); |
|
5826 | 292 |
|
293 |
||
18669 | 294 |
(* fixes *) |
5826 | 295 |
|
21400 | 296 |
val where_ = $$$ "where"; |
297 |
||
18618 | 298 |
val const = name -- ($$$ "::" |-- !!! typ) -- opt_mixfix >> triple1; |
30339 | 299 |
val const_binding = binding -- ($$$ "::" |-- !!! typ) -- opt_mixfix >> triple1; |
18669 | 300 |
|
28081
d664b2c1dfe6
explicit type Name.binding for higher-specification elements;
wenzelm
parents:
28017
diff
changeset
|
301 |
val params = Scan.repeat1 binding -- Scan.option ($$$ "::" |-- !!! typ) |
18669 | 302 |
>> (fn (xs, T) => map (rpair T) xs); |
303 |
||
19482
9f11af8f7ef9
tuned basic list operators (flat, maps, map_filter);
wenzelm
parents:
19284
diff
changeset
|
304 |
val simple_fixes = and_list1 params >> flat; |
18669 | 305 |
|
306 |
val fixes = |
|
28081
d664b2c1dfe6
explicit type Name.binding for higher-specification elements;
wenzelm
parents:
28017
diff
changeset
|
307 |
and_list1 (binding -- Scan.option ($$$ "::" |-- typ) -- mixfix >> (single o triple1) || |
19482
9f11af8f7ef9
tuned basic list operators (flat, maps, map_filter);
wenzelm
parents:
19284
diff
changeset
|
308 |
params >> map Syntax.no_syn) >> flat; |
5826 | 309 |
|
19845 | 310 |
val for_fixes = Scan.optional ($$$ "for" |-- !!! fixes) []; |
21371 | 311 |
val for_simple_fixes = Scan.optional ($$$ "for" |-- !!! simple_fixes) []; |
19845 | 312 |
|
5826 | 313 |
|
27877 | 314 |
(* embedded source text *) |
27872
631371a02b8c
P.doc_source and P.ml_sorce for proper SymbolPos.text;
wenzelm
parents:
27815
diff
changeset
|
315 |
|
27877 | 316 |
val ML_source = source_position (group "ML source" text); |
27872
631371a02b8c
P.doc_source and P.ml_sorce for proper SymbolPos.text;
wenzelm
parents:
27815
diff
changeset
|
317 |
val doc_source = source_position (group "document source" text); |
631371a02b8c
P.doc_source and P.ml_sorce for proper SymbolPos.text;
wenzelm
parents:
27815
diff
changeset
|
318 |
|
631371a02b8c
P.doc_source and P.ml_sorce for proper SymbolPos.text;
wenzelm
parents:
27815
diff
changeset
|
319 |
|
5826 | 320 |
(* terms *) |
321 |
||
40793
d21aedaa91e7
added Parse.literal_fact with proper inner_syntax markup (source position);
wenzelm
parents:
40296
diff
changeset
|
322 |
val tm = short_ident || long_ident || sym_ident || term_var || number || string; |
5826 | 323 |
|
40793
d21aedaa91e7
added Parse.literal_fact with proper inner_syntax markup (source position);
wenzelm
parents:
40296
diff
changeset
|
324 |
val term_group = group "term" tm; |
d21aedaa91e7
added Parse.literal_fact with proper inner_syntax markup (source position);
wenzelm
parents:
40296
diff
changeset
|
325 |
val prop_group = group "proposition" tm; |
27753
94b672153b49
sort/typ/term/prop: inner_syntax markup encodes original source position;
wenzelm
parents:
27737
diff
changeset
|
326 |
|
94b672153b49
sort/typ/term/prop: inner_syntax markup encodes original source position;
wenzelm
parents:
27737
diff
changeset
|
327 |
val term = inner_syntax term_group; |
94b672153b49
sort/typ/term/prop: inner_syntax markup encodes original source position;
wenzelm
parents:
27737
diff
changeset
|
328 |
val prop = inner_syntax prop_group; |
5826 | 329 |
|
40793
d21aedaa91e7
added Parse.literal_fact with proper inner_syntax markup (source position);
wenzelm
parents:
40296
diff
changeset
|
330 |
val literal_fact = inner_syntax (group "literal fact" alt_string); |
d21aedaa91e7
added Parse.literal_fact with proper inner_syntax markup (source position);
wenzelm
parents:
40296
diff
changeset
|
331 |
|
5826 | 332 |
|
6949 | 333 |
(* patterns *) |
6935 | 334 |
|
6949 | 335 |
val is_terms = Scan.repeat1 ($$$ "is" |-- term); |
6935 | 336 |
val is_props = Scan.repeat1 ($$$ "is" |-- prop); |
337 |
||
19585 | 338 |
val propp = prop -- Scan.optional ($$$ "(" |-- !!! (is_props --| $$$ ")")) []; |
6949 | 339 |
val termp = term -- Scan.optional ($$$ "(" |-- !!! (is_terms --| $$$ ")")) []; |
6935 | 340 |
|
341 |
||
22119 | 342 |
(* targets *) |
19811 | 343 |
|
22119 | 344 |
val target = ($$$ "(" -- $$$ "in") |-- !!! (xname --| $$$ ")"); |
345 |
val opt_target = Scan.option target; |
|
12272 | 346 |
|
347 |
end; |
|
30511 | 348 |
|
36949
080e85d46108
renamed structure OuterKeyword to Keyword and OuterParse to Parse, keeping the old names as legacy aliases for some time;
wenzelm
parents:
35838
diff
changeset
|
349 |
type 'a parser = 'a Parse.parser; |
080e85d46108
renamed structure OuterKeyword to Keyword and OuterParse to Parse, keeping the old names as legacy aliases for some time;
wenzelm
parents:
35838
diff
changeset
|
350 |
type 'a context_parser = 'a Parse.context_parser; |
30511 | 351 |