author | wenzelm |
Tue, 14 Nov 2006 22:17:03 +0100 | |
changeset 21371 | 6717630f080b |
parent 21314 | 6d709b9bea1a |
child 21400 | 4788fc8e66ea |
permissions | -rw-r--r-- |
5826 | 1 |
(* Title: Pure/Isar/outer_parse.ML |
2 |
ID: $Id$ |
|
3 |
Author: Markus Wenzel, TU Muenchen |
|
4 |
||
5 |
Generic parsers for Isabelle/Isar outer syntax. |
|
6 |
*) |
|
7 |
||
8 |
signature OUTER_PARSE = |
|
9 |
sig |
|
10 |
type token |
|
11 |
val group: string -> (token list -> 'a) -> token list -> 'a |
|
12 |
val !!! : (token list -> 'a) -> token list -> 'a |
|
8581
5c7ed2af8bfb
!!!! = cut "Corrupted outer syntax in presentation";
wenzelm
parents:
8350
diff
changeset
|
13 |
val !!!! : (token list -> 'a) -> token 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 |
|
15703 | 17 |
val not_eof: token list -> token * token list |
5826 | 18 |
val position: (token list -> 'a * 'b) -> token list -> ('a * Position.T) * 'b |
7026 | 19 |
val command: token list -> string * token list |
5826 | 20 |
val keyword: token list -> string * token list |
21 |
val short_ident: token list -> string * token list |
|
22 |
val long_ident: token list -> string * token list |
|
23 |
val sym_ident: token list -> string * token list |
|
15963 | 24 |
val minus: token list -> string * token list |
5826 | 25 |
val term_var: token list -> string * token list |
26 |
val type_ident: token list -> string * token list |
|
27 |
val type_var: token list -> string * token list |
|
28 |
val number: token list -> string * token list |
|
29 |
val string: token list -> string * token list |
|
30 |
val verbatim: token list -> string * token list |
|
6860 | 31 |
val sync: token list -> string * token list |
5826 | 32 |
val eof: token list -> string * token list |
15703 | 33 |
val $$$ : string -> token list -> string * token list |
16030 | 34 |
val reserved : string -> token list -> string * token list |
15703 | 35 |
val semicolon: token list -> string * token list |
36 |
val underscore: token list -> string * token list |
|
37 |
val maybe: (token list -> 'a * token list) -> token list -> 'a option * token list |
|
17070 | 38 |
val tag_name: token list -> string * token list |
39 |
val tags: token list -> string list * token list |
|
7930 | 40 |
val opt_unit: token list -> unit * token list |
14646 | 41 |
val opt_keyword: string -> token list -> bool * token list |
20983 | 42 |
val begin: token list -> string * token list |
20961 | 43 |
val opt_begin: token list -> bool * token list |
5826 | 44 |
val nat: token list -> int * token list |
45 |
val enum: string -> (token list -> 'a * token list) -> token list -> 'a list * token list |
|
46 |
val enum1: string -> (token list -> 'a * token list) -> token list -> 'a list * token list |
|
47 |
val list: (token list -> 'a * token list) -> token list -> 'a list * token list |
|
48 |
val list1: (token list -> 'a * token list) -> token list -> 'a list * token list |
|
6013 | 49 |
val and_list: (token list -> 'a * token list) -> token list -> 'a list * token list |
50 |
val and_list1: (token list -> 'a * token list) -> token list -> 'a list * token list |
|
5826 | 51 |
val name: token list -> bstring * token list |
52 |
val xname: token list -> xstring * token list |
|
53 |
val text: token list -> string * token list |
|
14949 | 54 |
val path: token list -> Path.T * token list |
18898 | 55 |
val parname: token list -> string * token list |
8897 | 56 |
val sort: token list -> string * token list |
57 |
val arity: token list -> (string list * string) * token list |
|
5826 | 58 |
val type_args: token list -> string list * token list |
59 |
val typ: token list -> string * token list |
|
18669 | 60 |
val mixfix: token list -> mixfix * token list |
61 |
val opt_infix: token list -> mixfix * token list |
|
62 |
val opt_mixfix: token list -> mixfix * token list |
|
63 |
val opt_infix': token list -> mixfix * token list |
|
64 |
val opt_mixfix': token list -> mixfix * token list |
|
65 |
val const: token list -> (string * string * mixfix) * token list |
|
19845 | 66 |
val simple_fixes: token list -> (string * string option) list * token list |
18669 | 67 |
val fixes: token list -> (string * string option * mixfix) list * token list |
19845 | 68 |
val for_fixes: token list -> (string * string option * mixfix) list * token list |
21371 | 69 |
val for_simple_fixes: token list -> (string * string option) list * token list |
5826 | 70 |
val term: token list -> string * token list |
71 |
val prop: token list -> string * token list |
|
19585 | 72 |
val propp: token list -> (string * string list) * token list |
6949 | 73 |
val termp: token list -> (string * string list) * token list |
9131 | 74 |
val arguments: token list -> Args.T list * token list |
20273 | 75 |
val attrib: token list -> Attrib.src * token list |
15703 | 76 |
val attribs: token list -> Attrib.src list * token list |
77 |
val opt_attribs: token list -> Attrib.src list * token list |
|
78 |
val thm_name: string -> token list -> (bstring * Attrib.src list) * token list |
|
79 |
val opt_thm_name: string -> token list -> (bstring * Attrib.src list) * token list |
|
18618 | 80 |
val spec: token list -> ((bstring * Attrib.src list) * string list) * token list |
81 |
val named_spec: token list -> ((bstring * Attrib.src list) * string list) * token list |
|
15703 | 82 |
val spec_name: token list -> ((bstring * string) * Attrib.src list) * token list |
83 |
val spec_opt_name: token list -> ((bstring * string) * Attrib.src list) * token list |
|
84 |
val xthm: token list -> (thmref * Attrib.src list) * token list |
|
85 |
val xthms1: token list -> (thmref * Attrib.src list) list * token list |
|
17358 | 86 |
val name_facts: token list -> |
87 |
((bstring * Attrib.src list) * (thmref * Attrib.src list) list) list * token list |
|
18669 | 88 |
val locale_mixfix: token list -> mixfix * token list |
89 |
val locale_fixes: token list -> (string * string option * mixfix) list * token list |
|
19811 | 90 |
val locale_insts: token list -> string option list * token list |
16736
1e792b32abef
Preparations for interpretation of locales in locales.
ballarin
parents:
16498
diff
changeset
|
91 |
val locale_target: token list -> xstring * token list |
1e792b32abef
Preparations for interpretation of locales in locales.
ballarin
parents:
16498
diff
changeset
|
92 |
val opt_locale_target: token list -> xstring option * token list |
12272 | 93 |
val locale_expr: token list -> Locale.expr * token list |
21371 | 94 |
val locale_expr_unless: (token list -> 'a * token list) -> |
95 |
token list -> Locale.expr * token list |
|
12942 | 96 |
val locale_keyword: token list -> string * token list |
18136 | 97 |
val locale_element: token list -> Element.context Locale.element * token list |
98 |
val context_element: token list -> Element.context * token list |
|
18898 | 99 |
val statement: token list -> |
19585 | 100 |
((bstring * Attrib.src list) * (string * string list) list) list * token list |
18898 | 101 |
val general_statement: token list -> |
102 |
(Element.context Locale.element list * Element.statement) * OuterLex.token list |
|
103 |
val statement_keyword: token list -> string * token list |
|
21371 | 104 |
val specification: token list -> |
105 |
(string * |
|
106 |
(((bstring * Attrib.src list) * string list) list * (string * string option) list)) list * |
|
107 |
token list |
|
5826 | 108 |
val method: token list -> Method.text * token list |
109 |
end; |
|
110 |
||
111 |
structure OuterParse: OUTER_PARSE = |
|
112 |
struct |
|
113 |
||
9131 | 114 |
structure T = OuterLex; |
115 |
type token = T.token; |
|
5826 | 116 |
|
117 |
||
118 |
(** error handling **) |
|
119 |
||
120 |
(* group atomic parsers (no cuts!) *) |
|
121 |
||
122 |
fun fail_with s = Scan.fail_with |
|
123 |
(fn [] => s ^ " expected (past end-of-file!)" |
|
9155 | 124 |
| (tok :: _) => s ^ " expected,\nbut " ^ T.name_of tok ^ T.pos_of tok ^ " was found"); |
5826 | 125 |
|
126 |
fun group s scan = scan || fail_with s; |
|
127 |
||
128 |
||
5877 | 129 |
(* cut *) |
5826 | 130 |
|
8581
5c7ed2af8bfb
!!!! = cut "Corrupted outer syntax in presentation";
wenzelm
parents:
8350
diff
changeset
|
131 |
fun cut kind scan = |
5826 | 132 |
let |
133 |
fun get_pos [] = " (past end-of-file!)" |
|
9131 | 134 |
| get_pos (tok :: _) = T.pos_of tok; |
5826 | 135 |
|
15531 | 136 |
fun err (toks, NONE) = kind ^ get_pos toks |
137 |
| err (toks, SOME msg) = kind ^ get_pos toks ^ ": " ^ msg; |
|
5826 | 138 |
in Scan.!! err scan end; |
139 |
||
8586 | 140 |
fun !!! scan = cut "Outer syntax error" scan; |
141 |
fun !!!! scan = cut "Corrupted outer syntax in presentation" scan; |
|
8581
5c7ed2af8bfb
!!!! = cut "Corrupted outer syntax in presentation";
wenzelm
parents:
8350
diff
changeset
|
142 |
|
5826 | 143 |
|
144 |
||
145 |
(** basic parsers **) |
|
146 |
||
147 |
(* utils *) |
|
148 |
||
149 |
fun triple1 ((x, y), z) = (x, y, z); |
|
150 |
fun triple2 (x, (y, z)) = (x, y, z); |
|
6430 | 151 |
fun triple_swap ((x, y), z) = ((x, z), y); |
5826 | 152 |
|
153 |
||
154 |
(* tokens *) |
|
155 |
||
15703 | 156 |
val not_eof = Scan.one T.not_eof; |
157 |
||
158 |
fun position scan = (Scan.ahead not_eof >> T.position_of) -- scan >> Library.swap; |
|
5826 | 159 |
|
160 |
fun kind k = |
|
9131 | 161 |
group (T.str_of_kind k) (Scan.one (T.is_kind k) >> T.val_of); |
5826 | 162 |
|
9131 | 163 |
val command = kind T.Command; |
164 |
val keyword = kind T.Keyword; |
|
165 |
val short_ident = kind T.Ident; |
|
166 |
val long_ident = kind T.LongIdent; |
|
167 |
val sym_ident = kind T.SymIdent; |
|
168 |
val term_var = kind T.Var; |
|
169 |
val type_ident = kind T.TypeIdent; |
|
170 |
val type_var = kind T.TypeVar; |
|
171 |
val number = kind T.Nat; |
|
172 |
val string = kind T.String; |
|
17165 | 173 |
val alt_string = kind T.AltString; |
9131 | 174 |
val verbatim = kind T.Verbatim; |
175 |
val sync = kind T.Sync; |
|
176 |
val eof = kind T.EOF; |
|
5826 | 177 |
|
178 |
fun $$$ x = |
|
9131 | 179 |
group (T.str_of_kind T.Keyword ^ " " ^ quote x) |
180 |
(Scan.one (T.keyword_with (equal x)) >> T.val_of); |
|
181 |
||
16030 | 182 |
fun reserved x = |
183 |
group ("Reserved identifier " ^ quote x) |
|
184 |
(Scan.one (T.ident_with (equal x)) >> T.val_of); |
|
185 |
||
9131 | 186 |
val semicolon = $$$ ";"; |
5826 | 187 |
|
15703 | 188 |
val minus = sym_ident :-- (fn "-" => Scan.succeed () | _ => Scan.fail) >> #1; |
11792
311eee3d63b6
parser for underscore (actually a symbolic identifier!);
wenzelm
parents:
11651
diff
changeset
|
189 |
val underscore = sym_ident :-- (fn "_" => Scan.succeed () | _ => Scan.fail) >> #1; |
15703 | 190 |
fun maybe scan = underscore >> K NONE || scan >> SOME; |
11792
311eee3d63b6
parser for underscore (actually a symbolic identifier!);
wenzelm
parents:
11651
diff
changeset
|
191 |
|
14835 | 192 |
val nat = number >> (#1 o Library.read_int o Symbol.explode); |
5826 | 193 |
|
17070 | 194 |
val tag_name = group "tag name" (short_ident || string); |
195 |
val tags = Scan.repeat ($$$ "%" |-- !!! tag_name); |
|
196 |
||
7930 | 197 |
val opt_unit = Scan.optional ($$$ "(" -- $$$ ")" >> (K ())) (); |
14646 | 198 |
fun opt_keyword s = Scan.optional ($$$ "(" |-- !!! (($$$ s >> K true) --| $$$ ")")) false; |
199 |
||
20983 | 200 |
val begin = $$$ "begin"; |
201 |
val opt_begin = Scan.optional (begin >> K true) false; |
|
20961 | 202 |
|
5826 | 203 |
|
204 |
(* enumerations *) |
|
205 |
||
6003 | 206 |
fun enum1 sep scan = scan -- Scan.repeat ($$$ sep |-- !!! scan) >> op ::; |
5826 | 207 |
fun enum sep scan = enum1 sep scan || Scan.succeed []; |
208 |
||
209 |
fun list1 scan = enum1 "," scan; |
|
210 |
fun list scan = enum "," scan; |
|
211 |
||
6013 | 212 |
fun and_list1 scan = enum1 "and" scan; |
213 |
fun and_list scan = enum "and" scan; |
|
214 |
||
5826 | 215 |
|
5960 | 216 |
(* names and text *) |
5826 | 217 |
|
8146 | 218 |
val name = group "name declaration" (short_ident || sym_ident || string || number); |
219 |
val xname = group "name reference" (short_ident || long_ident || sym_ident || string || number); |
|
220 |
val text = group "text" (short_ident || long_ident || sym_ident || string || number || verbatim); |
|
14949 | 221 |
val path = group "file name/path specification" name >> Path.unpack; |
6553 | 222 |
|
18898 | 223 |
val parname = Scan.optional ($$$ "(" |-- name --| $$$ ")") ""; |
224 |
||
6553 | 225 |
|
6372 | 226 |
(* sorts and arities *) |
5826 | 227 |
|
8897 | 228 |
val sort = group "sort" xname; |
5826 | 229 |
|
21314 | 230 |
val arity = Scan.optional ($$$ "(" |-- !!! (list1 sort --| $$$ ")")) [] -- sort; |
5826 | 231 |
|
232 |
||
233 |
(* types *) |
|
234 |
||
8146 | 235 |
val typ = group "type" |
236 |
(short_ident || long_ident || sym_ident || type_ident || type_var || string || number); |
|
5826 | 237 |
|
238 |
val type_args = |
|
239 |
type_ident >> single || |
|
240 |
$$$ "(" |-- !!! (list1 type_ident --| $$$ ")") || |
|
241 |
Scan.succeed []; |
|
242 |
||
243 |
||
244 |
(* mixfix annotations *) |
|
245 |
||
18669 | 246 |
val mfix = string -- |
247 |
!!! (Scan.optional ($$$ "[" |-- !!! (list nat --| $$$ "]")) [] -- |
|
248 |
Scan.optional nat Syntax.max_pri) >> (Mixfix o triple2); |
|
249 |
||
250 |
val infx = $$$ "infix" |-- !!! (nat >> Infix || string -- nat >> InfixName); |
|
251 |
val infxl = $$$ "infixl" |-- !!! (nat >> Infixl || string -- nat >> InfixlName); |
|
252 |
val infxr = $$$ "infixr" |-- !!! (nat >> Infixr || string -- nat >> InfixrName); |
|
5826 | 253 |
|
18669 | 254 |
val binder = $$$ "binder" |-- |
255 |
!!! (string -- ($$$ "[" |-- nat --| $$$ "]" -- nat || nat >> (fn n => (n, n)))) |
|
256 |
>> (Binder o triple2); |
|
257 |
||
258 |
fun annotation guard fix = $$$ "(" |-- guard (fix --| $$$ ")"); |
|
259 |
fun opt_annotation guard fix = Scan.optional (annotation guard fix) NoSyn; |
|
260 |
||
261 |
val mixfix = annotation !!! (mfix || binder || infxl || infxr || infx); |
|
262 |
val opt_infix = opt_annotation !!! (infxl || infxr || infx); |
|
263 |
val opt_mixfix = opt_annotation !!! (mfix || binder || infxl || infxr || infx); |
|
264 |
val opt_infix' = opt_annotation I (infxl || infxr || infx); |
|
265 |
val opt_mixfix' = opt_annotation I (mfix || binder || infxl || infxr || infx); |
|
5826 | 266 |
|
267 |
||
18669 | 268 |
(* fixes *) |
5826 | 269 |
|
18618 | 270 |
val const = name -- ($$$ "::" |-- !!! typ) -- opt_mixfix >> triple1; |
18669 | 271 |
|
272 |
val params = Scan.repeat1 name -- Scan.option ($$$ "::" |-- !!! typ) |
|
273 |
>> (fn (xs, T) => map (rpair T) xs); |
|
274 |
||
19482
9f11af8f7ef9
tuned basic list operators (flat, maps, map_filter);
wenzelm
parents:
19284
diff
changeset
|
275 |
val simple_fixes = and_list1 params >> flat; |
18669 | 276 |
|
277 |
val fixes = |
|
278 |
and_list1 (name -- Scan.option ($$$ "::" |-- typ) -- mixfix >> (single o triple1) || |
|
19482
9f11af8f7ef9
tuned basic list operators (flat, maps, map_filter);
wenzelm
parents:
19284
diff
changeset
|
279 |
params >> map Syntax.no_syn) >> flat; |
5826 | 280 |
|
19845 | 281 |
val for_fixes = Scan.optional ($$$ "for" |-- !!! fixes) []; |
21371 | 282 |
val for_simple_fixes = Scan.optional ($$$ "for" |-- !!! simple_fixes) []; |
19845 | 283 |
|
5826 | 284 |
|
285 |
(* terms *) |
|
286 |
||
7477 | 287 |
val trm = short_ident || long_ident || sym_ident || term_var || number || string; |
5826 | 288 |
|
289 |
val term = group "term" trm; |
|
290 |
val prop = group "proposition" trm; |
|
291 |
||
292 |
||
6949 | 293 |
(* patterns *) |
6935 | 294 |
|
6949 | 295 |
val is_terms = Scan.repeat1 ($$$ "is" |-- term); |
6935 | 296 |
val is_props = Scan.repeat1 ($$$ "is" |-- prop); |
297 |
||
19585 | 298 |
val propp = prop -- Scan.optional ($$$ "(" |-- !!! (is_props --| $$$ ")")) []; |
6949 | 299 |
val termp = term -- Scan.optional ($$$ "(" |-- !!! (is_terms --| $$$ ")")) []; |
6935 | 300 |
|
301 |
||
5826 | 302 |
(* arguments *) |
303 |
||
9131 | 304 |
fun keyword_symid is_symid = Scan.one (T.keyword_with is_symid) >> T.val_of; |
305 |
val keyword_sid = keyword_symid T.is_sid; |
|
5826 | 306 |
|
6983 | 307 |
fun atom_arg is_symid blk = |
5826 | 308 |
group "argument" |
7477 | 309 |
(position (short_ident || long_ident || sym_ident || term_var || |
15703 | 310 |
type_ident || type_var || number) >> Args.mk_ident || |
311 |
position (keyword_symid is_symid) >> Args.mk_keyword || |
|
312 |
position (string || verbatim) >> Args.mk_string || |
|
18037 | 313 |
position alt_string >> Args.mk_alt_string || |
15703 | 314 |
position (if blk then $$$ "," else Scan.fail) >> Args.mk_keyword); |
5826 | 315 |
|
5877 | 316 |
fun paren_args l r scan = position ($$$ l) -- !!! (scan true -- position ($$$ r)) |
15703 | 317 |
>> (fn (x, (ys, z)) => Args.mk_keyword x :: ys @ [Args.mk_keyword z]); |
5826 | 318 |
|
6983 | 319 |
fun args is_symid blk x = Scan.optional (args1 is_symid blk) [] x |
320 |
and args1 is_symid blk x = |
|
5826 | 321 |
((Scan.repeat1 |
6983 | 322 |
(Scan.repeat1 (atom_arg is_symid blk) || |
323 |
paren_args "(" ")" (args is_symid) || |
|
19482
9f11af8f7ef9
tuned basic list operators (flat, maps, map_filter);
wenzelm
parents:
19284
diff
changeset
|
324 |
paren_args "[" "]" (args is_symid))) >> flat) x; |
5826 | 325 |
|
9131 | 326 |
val arguments = args T.is_sid false; |
327 |
||
5826 | 328 |
|
6372 | 329 |
(* theorem specifications *) |
5826 | 330 |
|
9131 | 331 |
val attrib = position ((keyword_sid || xname) -- !!! arguments) >> Args.src; |
5826 | 332 |
val attribs = $$$ "[" |-- !!! (list attrib --| $$$ "]"); |
333 |
val opt_attribs = Scan.optional attribs []; |
|
334 |
||
6398 | 335 |
fun thm_name s = name -- opt_attribs --| $$$ s; |
6511 | 336 |
fun opt_thm_name s = |
17756 | 337 |
Scan.optional ((name -- opt_attribs || (attribs >> pair "")) --| $$$ s) ("", []); |
5917 | 338 |
|
18618 | 339 |
val spec = opt_thm_name ":" -- Scan.repeat1 prop; |
340 |
val named_spec = thm_name ":" -- Scan.repeat1 prop; |
|
341 |
||
6372 | 342 |
val spec_name = thm_name ":" -- prop >> (fn ((x, y), z) => ((x, z), y)); |
343 |
val spec_opt_name = opt_thm_name ":" -- prop >> (fn ((x, y), z) => ((x, z), y)); |
|
344 |
||
15456
956d6acacf89
Specific theorems in a named list of theorems can now be referred to
berghofe
parents:
15206
diff
changeset
|
345 |
val thm_sel = $$$ "(" |-- list1 |
15703 | 346 |
(nat --| minus -- nat >> PureThy.FromTo || |
347 |
nat --| minus >> PureThy.From || |
|
348 |
nat >> PureThy.Single) --| $$$ ")"; |
|
15456
956d6acacf89
Specific theorems in a named list of theorems can now be referred to
berghofe
parents:
15206
diff
changeset
|
349 |
|
18037 | 350 |
val xthm = (alt_string >> Fact || xname -- thm_sel >> NameSelection || xname >> Name) |
351 |
-- opt_attribs; |
|
6372 | 352 |
val xthms1 = Scan.repeat1 xthm; |
5826 | 353 |
|
17358 | 354 |
val name_facts = and_list1 (opt_thm_name "=" -- xthms1); |
355 |
||
5826 | 356 |
|
18136 | 357 |
(* locale and context elements *) |
12047 | 358 |
|
18669 | 359 |
val locale_mixfix = $$$ "(" -- $$$ "structure" -- !!! ($$$ ")") >> K Structure || mixfix; |
360 |
||
361 |
val locale_fixes = |
|
362 |
and_list1 (name -- Scan.option ($$$ "::" |-- typ) -- locale_mixfix >> (single o triple1) || |
|
19482
9f11af8f7ef9
tuned basic list operators (flat, maps, map_filter);
wenzelm
parents:
19284
diff
changeset
|
363 |
params >> map Syntax.no_syn) >> flat; |
18669 | 364 |
|
19811 | 365 |
val locale_insts = |
366 |
Scan.optional ($$$ "[" |-- !!! (Scan.repeat1 (maybe term) --| $$$ "]")) []; |
|
367 |
||
12272 | 368 |
local |
369 |
||
16169
b59202511b8a
Locales: new element constrains, parameter renaming with syntax,
ballarin
parents:
16102
diff
changeset
|
370 |
val loc_keyword = $$$ "fixes" || $$$ "constrains" || $$$ "assumes" || |
b59202511b8a
Locales: new element constrains, parameter renaming with syntax,
ballarin
parents:
16102
diff
changeset
|
371 |
$$$ "defines" || $$$ "notes" || $$$ "includes"; |
12272 | 372 |
|
15127 | 373 |
val loc_element = |
18669 | 374 |
$$$ "fixes" |-- !!! locale_fixes >> Element.Fixes || |
16169
b59202511b8a
Locales: new element constrains, parameter renaming with syntax,
ballarin
parents:
16102
diff
changeset
|
375 |
$$$ "constrains" |-- !!! (and_list1 (name -- ($$$ "::" |-- typ))) |
18136 | 376 |
>> Element.Constrains || |
15127 | 377 |
$$$ "assumes" |-- !!! (and_list1 (opt_thm_name ":" -- Scan.repeat1 propp)) |
18136 | 378 |
>> Element.Assumes || |
19585 | 379 |
$$$ "defines" |-- !!! (and_list1 (opt_thm_name ":" -- propp)) |
18136 | 380 |
>> Element.Defines || |
15127 | 381 |
$$$ "notes" |-- !!! (and_list1 (opt_thm_name "=" -- xthms1)) |
18136 | 382 |
>> Element.Notes; |
15127 | 383 |
|
19284 | 384 |
fun plus1 test scan = |
385 |
scan -- Scan.repeat ($$$ "+" |-- Scan.unless test (!!! scan)) >> op ::; |
|
12272 | 386 |
|
18669 | 387 |
val rename = name -- Scan.option mixfix; |
16102
c5f6726d9bb1
Locale expressions: rename with optional mixfix syntax.
ballarin
parents:
16030
diff
changeset
|
388 |
|
19284 | 389 |
fun expr test = |
21371 | 390 |
let |
19284 | 391 |
fun expr2 x = (xname >> Locale.Locale || $$$ "(" |-- !!! (expr0 --| $$$ ")")) x |
392 |
and expr1 x = (expr2 -- Scan.repeat1 (maybe rename) >> Locale.Rename || expr2) x |
|
393 |
and expr0 x = (plus1 test expr1 >> (fn [e] => e | es => Locale.Merge es)) x; |
|
394 |
in expr0 end; |
|
12272 | 395 |
in |
396 |
||
16736
1e792b32abef
Preparations for interpretation of locales in locales.
ballarin
parents:
16498
diff
changeset
|
397 |
val locale_target = ($$$ "(" -- $$$ "in") |-- !!! (xname --| $$$ ")"); |
1e792b32abef
Preparations for interpretation of locales in locales.
ballarin
parents:
16498
diff
changeset
|
398 |
val opt_locale_target = Scan.option locale_target; |
19284 | 399 |
val locale_expr_unless = expr |
400 |
val locale_expr = expr loc_keyword; |
|
12942 | 401 |
val locale_keyword = loc_keyword; |
12047 | 402 |
|
18136 | 403 |
val locale_element = group "locale element" |
404 |
(loc_element >> Locale.Elem || $$$ "includes" |-- !!! locale_expr >> Locale.Expr); |
|
15127 | 405 |
|
18136 | 406 |
val context_element = group "context element" loc_element; |
12272 | 407 |
|
408 |
end; |
|
12047 | 409 |
|
410 |
||
18898 | 411 |
(* statements *) |
412 |
||
413 |
val statement = and_list1 (opt_thm_name ":" -- Scan.repeat1 propp); |
|
414 |
||
415 |
val obtain_case = |
|
416 |
parname -- (Scan.optional (simple_fixes --| $$$ "where") [] -- |
|
19482
9f11af8f7ef9
tuned basic list operators (flat, maps, map_filter);
wenzelm
parents:
19284
diff
changeset
|
417 |
(and_list1 (Scan.repeat1 prop) >> flat)); |
18898 | 418 |
|
419 |
val general_statement = |
|
420 |
statement >> (fn x => ([], Element.Shows x)) || |
|
421 |
Scan.repeat locale_element -- |
|
19007 | 422 |
($$$ "obtains" |-- !!! (enum1 "|" obtain_case) >> Element.Obtains || |
423 |
$$$ "shows" |-- !!! statement >> Element.Shows); |
|
18898 | 424 |
|
19007 | 425 |
val statement_keyword = $$$ "obtains" || $$$ "shows"; |
18898 | 426 |
|
427 |
||
21371 | 428 |
(* specifications *) |
429 |
||
430 |
val specification = enum1 "|" (parname -- (and_list1 spec -- for_simple_fixes)); |
|
431 |
||
432 |
||
5826 | 433 |
(* proof methods *) |
434 |
||
6983 | 435 |
fun is_symid_meth s = |
9131 | 436 |
s <> "|" andalso s <> "?" andalso s <> "+" andalso T.is_sid s; |
6983 | 437 |
|
5826 | 438 |
fun meth4 x = |
5877 | 439 |
(position (xname >> rpair []) >> (Method.Source o Args.src) || |
6983 | 440 |
$$$ "(" |-- !!! (meth0 --| $$$ ")")) x |
5826 | 441 |
and meth3 x = |
442 |
(meth4 --| $$$ "?" >> Method.Try || |
|
443 |
meth4 --| $$$ "+" >> Method.Repeat1 || |
|
19223 | 444 |
meth4 -- ($$$ "[" |-- Scan.optional nat 1 --| $$$ "]") >> (Method.SelectGoals o swap) || |
5940 | 445 |
meth4) x |
446 |
and meth2 x = |
|
6983 | 447 |
(position (xname -- args1 is_symid_meth false) >> (Method.Source o Args.src) || |
5826 | 448 |
meth3) x |
449 |
and meth1 x = (enum1 "," meth2 >> (fn [m] => m | ms => Method.Then ms)) x |
|
450 |
and meth0 x = (enum1 "|" meth1 >> (fn [m] => m | ms => Method.Orelse ms)) x; |
|
451 |
||
6558 | 452 |
val method = meth3; |
5826 | 453 |
|
454 |
||
455 |
end; |