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