author | wenzelm |
Wed, 07 Jun 2006 02:01:34 +0200 | |
changeset 19811 | 46abcbb2da9d |
parent 19585 | 70a1ce3b23ae |
child 19845 | b8985bf2ce8b |
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 |
|
19585 | 68 |
val propp: token list -> (string * 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 |
|
19811 | 85 |
val locale_insts: token list -> string option list * token list |
16736
1e792b32abef
Preparations for interpretation of locales in locales.
ballarin
parents:
16498
diff
changeset
|
86 |
val locale_target: token list -> xstring * token list |
1e792b32abef
Preparations for interpretation of locales in locales.
ballarin
parents:
16498
diff
changeset
|
87 |
val opt_locale_target: token list -> xstring option * token list |
12272 | 88 |
val locale_expr: token list -> Locale.expr * token list |
19284 | 89 |
val locale_expr_unless: (token list -> 'a * token list) -> |
90 |
token list -> Locale.expr * token list |
|
12942 | 91 |
val locale_keyword: token list -> string * token list |
18136 | 92 |
val locale_element: token list -> Element.context Locale.element * token list |
93 |
val context_element: token list -> Element.context * token list |
|
18898 | 94 |
val statement: token list -> |
19585 | 95 |
((bstring * Attrib.src list) * (string * string list) list) list * token list |
18898 | 96 |
val general_statement: token list -> |
97 |
(Element.context Locale.element list * Element.statement) * OuterLex.token list |
|
98 |
val statement_keyword: token list -> string * token list |
|
5826 | 99 |
val method: token list -> Method.text * token list |
100 |
end; |
|
101 |
||
102 |
structure OuterParse: OUTER_PARSE = |
|
103 |
struct |
|
104 |
||
9131 | 105 |
structure T = OuterLex; |
106 |
type token = T.token; |
|
5826 | 107 |
|
108 |
||
109 |
(** error handling **) |
|
110 |
||
111 |
(* group atomic parsers (no cuts!) *) |
|
112 |
||
113 |
fun fail_with s = Scan.fail_with |
|
114 |
(fn [] => s ^ " expected (past end-of-file!)" |
|
9155 | 115 |
| (tok :: _) => s ^ " expected,\nbut " ^ T.name_of tok ^ T.pos_of tok ^ " was found"); |
5826 | 116 |
|
117 |
fun group s scan = scan || fail_with s; |
|
118 |
||
119 |
||
5877 | 120 |
(* cut *) |
5826 | 121 |
|
8581
5c7ed2af8bfb
!!!! = cut "Corrupted outer syntax in presentation";
wenzelm
parents:
8350
diff
changeset
|
122 |
fun cut kind scan = |
5826 | 123 |
let |
124 |
fun get_pos [] = " (past end-of-file!)" |
|
9131 | 125 |
| get_pos (tok :: _) = T.pos_of tok; |
5826 | 126 |
|
15531 | 127 |
fun err (toks, NONE) = kind ^ get_pos toks |
128 |
| err (toks, SOME msg) = kind ^ get_pos toks ^ ": " ^ msg; |
|
5826 | 129 |
in Scan.!! err scan end; |
130 |
||
8586 | 131 |
fun !!! scan = cut "Outer syntax error" scan; |
132 |
fun !!!! scan = cut "Corrupted outer syntax in presentation" scan; |
|
8581
5c7ed2af8bfb
!!!! = cut "Corrupted outer syntax in presentation";
wenzelm
parents:
8350
diff
changeset
|
133 |
|
5826 | 134 |
|
135 |
||
136 |
(** basic parsers **) |
|
137 |
||
138 |
(* utils *) |
|
139 |
||
140 |
fun triple1 ((x, y), z) = (x, y, z); |
|
141 |
fun triple2 (x, (y, z)) = (x, y, z); |
|
6430 | 142 |
fun triple_swap ((x, y), z) = ((x, z), y); |
5826 | 143 |
|
144 |
||
145 |
(* tokens *) |
|
146 |
||
15703 | 147 |
val not_eof = Scan.one T.not_eof; |
148 |
||
149 |
fun position scan = (Scan.ahead not_eof >> T.position_of) -- scan >> Library.swap; |
|
5826 | 150 |
|
151 |
fun kind k = |
|
9131 | 152 |
group (T.str_of_kind k) (Scan.one (T.is_kind k) >> T.val_of); |
5826 | 153 |
|
9131 | 154 |
val command = kind T.Command; |
155 |
val keyword = kind T.Keyword; |
|
156 |
val short_ident = kind T.Ident; |
|
157 |
val long_ident = kind T.LongIdent; |
|
158 |
val sym_ident = kind T.SymIdent; |
|
159 |
val term_var = kind T.Var; |
|
160 |
val type_ident = kind T.TypeIdent; |
|
161 |
val type_var = kind T.TypeVar; |
|
162 |
val number = kind T.Nat; |
|
163 |
val string = kind T.String; |
|
17165 | 164 |
val alt_string = kind T.AltString; |
9131 | 165 |
val verbatim = kind T.Verbatim; |
166 |
val sync = kind T.Sync; |
|
167 |
val eof = kind T.EOF; |
|
5826 | 168 |
|
169 |
fun $$$ x = |
|
9131 | 170 |
group (T.str_of_kind T.Keyword ^ " " ^ quote x) |
171 |
(Scan.one (T.keyword_with (equal x)) >> T.val_of); |
|
172 |
||
16030 | 173 |
fun reserved x = |
174 |
group ("Reserved identifier " ^ quote x) |
|
175 |
(Scan.one (T.ident_with (equal x)) >> T.val_of); |
|
176 |
||
9131 | 177 |
val semicolon = $$$ ";"; |
5826 | 178 |
|
15703 | 179 |
val minus = sym_ident :-- (fn "-" => Scan.succeed () | _ => Scan.fail) >> #1; |
11792
311eee3d63b6
parser for underscore (actually a symbolic identifier!);
wenzelm
parents:
11651
diff
changeset
|
180 |
val underscore = sym_ident :-- (fn "_" => Scan.succeed () | _ => Scan.fail) >> #1; |
15703 | 181 |
fun maybe scan = underscore >> K NONE || scan >> SOME; |
11792
311eee3d63b6
parser for underscore (actually a symbolic identifier!);
wenzelm
parents:
11651
diff
changeset
|
182 |
|
14835 | 183 |
val nat = number >> (#1 o Library.read_int o Symbol.explode); |
5826 | 184 |
|
17070 | 185 |
val tag_name = group "tag name" (short_ident || string); |
186 |
val tags = Scan.repeat ($$$ "%" |-- !!! tag_name); |
|
187 |
||
7930 | 188 |
val opt_unit = Scan.optional ($$$ "(" -- $$$ ")" >> (K ())) (); |
14646 | 189 |
fun opt_keyword s = Scan.optional ($$$ "(" |-- !!! (($$$ s >> K true) --| $$$ ")")) false; |
190 |
||
5826 | 191 |
|
192 |
(* enumerations *) |
|
193 |
||
6003 | 194 |
fun enum1 sep scan = scan -- Scan.repeat ($$$ sep |-- !!! scan) >> op ::; |
5826 | 195 |
fun enum sep scan = enum1 sep scan || Scan.succeed []; |
196 |
||
197 |
fun list1 scan = enum1 "," scan; |
|
198 |
fun list scan = enum "," scan; |
|
199 |
||
6013 | 200 |
fun and_list1 scan = enum1 "and" scan; |
201 |
fun and_list scan = enum "and" scan; |
|
202 |
||
5826 | 203 |
|
5960 | 204 |
(* names and text *) |
5826 | 205 |
|
8146 | 206 |
val name = group "name declaration" (short_ident || sym_ident || string || number); |
207 |
val xname = group "name reference" (short_ident || long_ident || sym_ident || string || number); |
|
208 |
val text = group "text" (short_ident || long_ident || sym_ident || string || number || verbatim); |
|
14949 | 209 |
val path = group "file name/path specification" name >> Path.unpack; |
6553 | 210 |
|
18898 | 211 |
val parname = Scan.optional ($$$ "(" |-- name --| $$$ ")") ""; |
212 |
||
6553 | 213 |
|
6372 | 214 |
(* sorts and arities *) |
5826 | 215 |
|
8897 | 216 |
val sort = group "sort" xname; |
5826 | 217 |
|
6372 | 218 |
fun gen_arity cod = |
7352 | 219 |
Scan.optional ($$$ "(" |-- !!! (list1 sort --| $$$ ")")) [] -- cod; |
6372 | 220 |
|
221 |
val arity = gen_arity sort; |
|
5826 | 222 |
|
223 |
||
224 |
(* types *) |
|
225 |
||
8146 | 226 |
val typ = group "type" |
227 |
(short_ident || long_ident || sym_ident || type_ident || type_var || string || number); |
|
5826 | 228 |
|
229 |
val type_args = |
|
230 |
type_ident >> single || |
|
231 |
$$$ "(" |-- !!! (list1 type_ident --| $$$ ")") || |
|
232 |
Scan.succeed []; |
|
233 |
||
234 |
||
235 |
(* mixfix annotations *) |
|
236 |
||
18669 | 237 |
val mfix = string -- |
238 |
!!! (Scan.optional ($$$ "[" |-- !!! (list nat --| $$$ "]")) [] -- |
|
239 |
Scan.optional nat Syntax.max_pri) >> (Mixfix o triple2); |
|
240 |
||
241 |
val infx = $$$ "infix" |-- !!! (nat >> Infix || string -- nat >> InfixName); |
|
242 |
val infxl = $$$ "infixl" |-- !!! (nat >> Infixl || string -- nat >> InfixlName); |
|
243 |
val infxr = $$$ "infixr" |-- !!! (nat >> Infixr || string -- nat >> InfixrName); |
|
5826 | 244 |
|
18669 | 245 |
val binder = $$$ "binder" |-- |
246 |
!!! (string -- ($$$ "[" |-- nat --| $$$ "]" -- nat || nat >> (fn n => (n, n)))) |
|
247 |
>> (Binder o triple2); |
|
248 |
||
249 |
fun annotation guard fix = $$$ "(" |-- guard (fix --| $$$ ")"); |
|
250 |
fun opt_annotation guard fix = Scan.optional (annotation guard fix) NoSyn; |
|
251 |
||
252 |
val mixfix = annotation !!! (mfix || binder || infxl || infxr || infx); |
|
253 |
val opt_infix = opt_annotation !!! (infxl || infxr || infx); |
|
254 |
val opt_mixfix = opt_annotation !!! (mfix || binder || infxl || infxr || infx); |
|
255 |
val opt_infix' = opt_annotation I (infxl || infxr || infx); |
|
256 |
val opt_mixfix' = opt_annotation I (mfix || binder || infxl || infxr || infx); |
|
5826 | 257 |
|
258 |
||
18669 | 259 |
(* fixes *) |
5826 | 260 |
|
18618 | 261 |
val const = name -- ($$$ "::" |-- !!! typ) -- opt_mixfix >> triple1; |
18669 | 262 |
|
263 |
val params = Scan.repeat1 name -- Scan.option ($$$ "::" |-- !!! typ) |
|
264 |
>> (fn (xs, T) => map (rpair T) xs); |
|
265 |
||
19482
9f11af8f7ef9
tuned basic list operators (flat, maps, map_filter);
wenzelm
parents:
19284
diff
changeset
|
266 |
val simple_fixes = and_list1 params >> flat; |
18669 | 267 |
|
268 |
val fixes = |
|
269 |
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
|
270 |
params >> map Syntax.no_syn) >> flat; |
5826 | 271 |
|
272 |
||
273 |
(* terms *) |
|
274 |
||
7477 | 275 |
val trm = short_ident || long_ident || sym_ident || term_var || number || string; |
5826 | 276 |
|
277 |
val term = group "term" trm; |
|
278 |
val prop = group "proposition" trm; |
|
279 |
||
280 |
||
6949 | 281 |
(* patterns *) |
6935 | 282 |
|
6949 | 283 |
val is_terms = Scan.repeat1 ($$$ "is" |-- term); |
6935 | 284 |
val is_props = Scan.repeat1 ($$$ "is" |-- prop); |
285 |
||
19585 | 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) || |
|
19482
9f11af8f7ef9
tuned basic list operators (flat, maps, map_filter);
wenzelm
parents:
19284
diff
changeset
|
312 |
paren_args "[" "]" (args is_symid))) >> flat) 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) || |
|
19482
9f11af8f7ef9
tuned basic list operators (flat, maps, map_filter);
wenzelm
parents:
19284
diff
changeset
|
351 |
params >> map Syntax.no_syn) >> flat; |
18669 | 352 |
|
19811 | 353 |
val locale_insts = |
354 |
Scan.optional ($$$ "[" |-- !!! (Scan.repeat1 (maybe term) --| $$$ "]")) []; |
|
355 |
||
12272 | 356 |
local |
357 |
||
16169
b59202511b8a
Locales: new element constrains, parameter renaming with syntax,
ballarin
parents:
16102
diff
changeset
|
358 |
val loc_keyword = $$$ "fixes" || $$$ "constrains" || $$$ "assumes" || |
b59202511b8a
Locales: new element constrains, parameter renaming with syntax,
ballarin
parents:
16102
diff
changeset
|
359 |
$$$ "defines" || $$$ "notes" || $$$ "includes"; |
12272 | 360 |
|
15127 | 361 |
val loc_element = |
18669 | 362 |
$$$ "fixes" |-- !!! locale_fixes >> Element.Fixes || |
16169
b59202511b8a
Locales: new element constrains, parameter renaming with syntax,
ballarin
parents:
16102
diff
changeset
|
363 |
$$$ "constrains" |-- !!! (and_list1 (name -- ($$$ "::" |-- typ))) |
18136 | 364 |
>> Element.Constrains || |
15127 | 365 |
$$$ "assumes" |-- !!! (and_list1 (opt_thm_name ":" -- Scan.repeat1 propp)) |
18136 | 366 |
>> Element.Assumes || |
19585 | 367 |
$$$ "defines" |-- !!! (and_list1 (opt_thm_name ":" -- propp)) |
18136 | 368 |
>> Element.Defines || |
15127 | 369 |
$$$ "notes" |-- !!! (and_list1 (opt_thm_name "=" -- xthms1)) |
18136 | 370 |
>> Element.Notes; |
15127 | 371 |
|
19284 | 372 |
fun plus1 test scan = |
373 |
scan -- Scan.repeat ($$$ "+" |-- Scan.unless test (!!! scan)) >> op ::; |
|
12272 | 374 |
|
18669 | 375 |
val rename = name -- Scan.option mixfix; |
16102
c5f6726d9bb1
Locale expressions: rename with optional mixfix syntax.
ballarin
parents:
16030
diff
changeset
|
376 |
|
19284 | 377 |
fun expr test = |
378 |
let |
|
379 |
fun expr2 x = (xname >> Locale.Locale || $$$ "(" |-- !!! (expr0 --| $$$ ")")) x |
|
380 |
and expr1 x = (expr2 -- Scan.repeat1 (maybe rename) >> Locale.Rename || expr2) x |
|
381 |
and expr0 x = (plus1 test expr1 >> (fn [e] => e | es => Locale.Merge es)) x; |
|
382 |
in expr0 end; |
|
12272 | 383 |
in |
384 |
||
16736
1e792b32abef
Preparations for interpretation of locales in locales.
ballarin
parents:
16498
diff
changeset
|
385 |
val locale_target = ($$$ "(" -- $$$ "in") |-- !!! (xname --| $$$ ")"); |
1e792b32abef
Preparations for interpretation of locales in locales.
ballarin
parents:
16498
diff
changeset
|
386 |
val opt_locale_target = Scan.option locale_target; |
19284 | 387 |
val locale_expr_unless = expr |
388 |
val locale_expr = expr loc_keyword; |
|
12942 | 389 |
val locale_keyword = loc_keyword; |
12047 | 390 |
|
18136 | 391 |
val locale_element = group "locale element" |
392 |
(loc_element >> Locale.Elem || $$$ "includes" |-- !!! locale_expr >> Locale.Expr); |
|
15127 | 393 |
|
18136 | 394 |
val context_element = group "context element" loc_element; |
12272 | 395 |
|
396 |
end; |
|
12047 | 397 |
|
398 |
||
18898 | 399 |
(* statements *) |
400 |
||
401 |
val statement = and_list1 (opt_thm_name ":" -- Scan.repeat1 propp); |
|
402 |
||
403 |
val obtain_case = |
|
404 |
parname -- (Scan.optional (simple_fixes --| $$$ "where") [] -- |
|
19482
9f11af8f7ef9
tuned basic list operators (flat, maps, map_filter);
wenzelm
parents:
19284
diff
changeset
|
405 |
(and_list1 (Scan.repeat1 prop) >> flat)); |
18898 | 406 |
|
407 |
val general_statement = |
|
408 |
statement >> (fn x => ([], Element.Shows x)) || |
|
409 |
Scan.repeat locale_element -- |
|
19007 | 410 |
($$$ "obtains" |-- !!! (enum1 "|" obtain_case) >> Element.Obtains || |
411 |
$$$ "shows" |-- !!! statement >> Element.Shows); |
|
18898 | 412 |
|
19007 | 413 |
val statement_keyword = $$$ "obtains" || $$$ "shows"; |
18898 | 414 |
|
415 |
||
5826 | 416 |
(* proof methods *) |
417 |
||
6983 | 418 |
fun is_symid_meth s = |
9131 | 419 |
s <> "|" andalso s <> "?" andalso s <> "+" andalso T.is_sid s; |
6983 | 420 |
|
5826 | 421 |
fun meth4 x = |
5877 | 422 |
(position (xname >> rpair []) >> (Method.Source o Args.src) || |
6983 | 423 |
$$$ "(" |-- !!! (meth0 --| $$$ ")")) x |
5826 | 424 |
and meth3 x = |
425 |
(meth4 --| $$$ "?" >> Method.Try || |
|
426 |
meth4 --| $$$ "+" >> Method.Repeat1 || |
|
19223 | 427 |
meth4 -- ($$$ "[" |-- Scan.optional nat 1 --| $$$ "]") >> (Method.SelectGoals o swap) || |
5940 | 428 |
meth4) x |
429 |
and meth2 x = |
|
6983 | 430 |
(position (xname -- args1 is_symid_meth false) >> (Method.Source o Args.src) || |
5826 | 431 |
meth3) x |
432 |
and meth1 x = (enum1 "," meth2 >> (fn [m] => m | ms => Method.Then ms)) x |
|
433 |
and meth0 x = (enum1 "|" meth1 >> (fn [m] => m | ms => Method.Orelse ms)) x; |
|
434 |
||
6558 | 435 |
val method = meth3; |
5826 | 436 |
|
437 |
||
438 |
end; |