12 val !!! : (token list -> 'a) -> token list -> 'a |
12 val !!! : (token list -> 'a) -> token list -> 'a |
13 val !!!! : (token list -> 'a) -> token list -> 'a |
13 val !!!! : (token list -> 'a) -> token list -> 'a |
14 val triple1: ('a * 'b) * 'c -> 'a * 'b * 'c |
14 val triple1: ('a * 'b) * 'c -> 'a * 'b * 'c |
15 val triple2: '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 |
16 val triple_swap: ('a * 'b) * 'c -> ('a * 'c) * 'b |
17 val $$$ : string -> token list -> string * token list |
17 val not_eof: token list -> token * token list |
18 val semicolon: token list -> string * token list |
|
19 val underscore: token list -> string * token list |
|
20 val position: (token list -> 'a * 'b) -> token list -> ('a * Position.T) * 'b |
18 val position: (token list -> 'a * 'b) -> token list -> ('a * Position.T) * 'b |
21 val command: token list -> string * token list |
19 val command: token list -> string * token list |
22 val keyword: token list -> string * token list |
20 val keyword: token list -> string * token list |
23 val short_ident: token list -> string * token list |
21 val short_ident: token list -> string * token list |
24 val long_ident: token list -> string * token list |
22 val long_ident: token list -> string * token list |
29 val number: token list -> string * token list |
27 val number: token list -> string * token list |
30 val string: token list -> string * token list |
28 val string: token list -> string * token list |
31 val verbatim: token list -> string * token list |
29 val verbatim: token list -> string * token list |
32 val sync: token list -> string * token list |
30 val sync: token list -> string * token list |
33 val eof: token list -> string * token list |
31 val eof: token list -> string * token list |
34 val not_eof: token list -> token * token list |
32 val $$$ : string -> token list -> string * token list |
|
33 val semicolon: token list -> string * token list |
|
34 val underscore: token list -> string * token list |
|
35 val maybe: (token list -> 'a * token list) -> token list -> 'a option * token list |
35 val opt_unit: token list -> unit * token list |
36 val opt_unit: token list -> unit * token list |
36 val opt_keyword: string -> token list -> bool * token list |
37 val opt_keyword: string -> token list -> bool * token list |
37 val nat: token list -> int * token list |
38 val nat: token list -> int * token list |
38 val enum: string -> (token list -> 'a * token list) -> token list -> 'a list * token list |
39 val enum: string -> (token list -> 'a * token list) -> token list -> 'a list * token list |
39 val enum1: string -> (token list -> 'a * token list) -> token list -> 'a list * token list |
40 val enum1: string -> (token list -> 'a * token list) -> token list -> 'a list * token list |
43 val and_list1: (token list -> 'a * token list) -> token list -> 'a list * token list |
44 val and_list1: (token list -> 'a * token list) -> token list -> 'a list * token list |
44 val name: token list -> bstring * token list |
45 val name: token list -> bstring * token list |
45 val xname: token list -> xstring * token list |
46 val xname: token list -> xstring * token list |
46 val text: token list -> string * token list |
47 val text: token list -> string * token list |
47 val path: token list -> Path.T * token list |
48 val path: token list -> Path.T * token list |
48 val uname: token list -> string option * token list |
|
49 val sort: token list -> string * token list |
49 val sort: token list -> string * token list |
50 val arity: token list -> (string list * string) * token list |
50 val arity: token list -> (string list * string) * token list |
51 val type_args: token list -> string list * token list |
51 val type_args: token list -> string list * token list |
52 val typ: token list -> string * token list |
52 val typ: token list -> string * token list |
53 val opt_infix: token list -> Syntax.mixfix * token list |
53 val opt_infix: token list -> Syntax.mixfix * token list |
59 val term: token list -> string * token list |
59 val term: token list -> string * token list |
60 val prop: token list -> string * token list |
60 val prop: token list -> string * token list |
61 val propp: token list -> (string * (string list * string list)) * token list |
61 val propp: token list -> (string * (string list * string list)) * token list |
62 val termp: token list -> (string * string list) * token list |
62 val termp: token list -> (string * string list) * token list |
63 val arguments: token list -> Args.T list * token list |
63 val arguments: token list -> Args.T list * token list |
64 val attribs: token list -> Args.src list * token list |
64 val attribs: token list -> Attrib.src list * token list |
65 val opt_attribs: token list -> Args.src list * token list |
65 val opt_attribs: token list -> Attrib.src list * token list |
66 val thm_name: string -> token list -> (bstring * Args.src list) * token list |
66 val thm_name: string -> token list -> (bstring * Attrib.src list) * token list |
67 val opt_thm_name: string -> token list -> (bstring * Args.src list) * token list |
67 val opt_thm_name: string -> token list -> (bstring * Attrib.src list) * token list |
68 val spec_name: token list -> ((bstring * string) * Args.src list) * token list |
68 val spec_name: token list -> ((bstring * string) * Attrib.src list) * token list |
69 val spec_opt_name: token list -> ((bstring * string) * Args.src list) * token list |
69 val spec_opt_name: token list -> ((bstring * string) * Attrib.src list) * token list |
70 val xthm: token list -> (thmref * Args.src list) * token list |
70 val xthm: token list -> (thmref * Attrib.src list) * token list |
71 val xthms1: token list -> (thmref * Args.src list) list * token list |
71 val xthms1: token list -> (thmref * Attrib.src list) list * token list |
72 val locale_target: token list -> xstring option * token list |
72 val locale_target: token list -> xstring option * token list |
73 val locale_expr: token list -> Locale.expr * token list |
73 val locale_expr: token list -> Locale.expr * token list |
74 val locale_keyword: token list -> string * token list |
74 val locale_keyword: token list -> string * token list |
75 val locale_element: token list -> Args.src Locale.element * token list |
75 val locale_element: token list -> Locale.element * token list |
76 val locale_elem_or_expr: token list -> Args.src Locale.element Locale.elem_expr * token list |
76 val locale_elem_or_expr: token list -> Locale.element Locale.elem_expr * token list |
77 val method: token list -> Method.text * token list |
77 val method: token list -> Method.text * token list |
78 end; |
78 end; |
79 |
79 |
80 structure OuterParse: OUTER_PARSE = |
80 structure OuterParse: OUTER_PARSE = |
81 struct |
81 struct |
120 fun triple_swap ((x, y), z) = ((x, z), y); |
120 fun triple_swap ((x, y), z) = ((x, z), y); |
121 |
121 |
122 |
122 |
123 (* tokens *) |
123 (* tokens *) |
124 |
124 |
125 fun position scan = |
125 val not_eof = Scan.one T.not_eof; |
126 (Scan.ahead (Scan.one T.not_eof) >> T.position_of) -- scan >> Library.swap; |
126 |
|
127 fun position scan = (Scan.ahead not_eof >> T.position_of) -- scan >> Library.swap; |
127 |
128 |
128 fun kind k = |
129 fun kind k = |
129 group (T.str_of_kind k) (Scan.one (T.is_kind k) >> T.val_of); |
130 group (T.str_of_kind k) (Scan.one (T.is_kind k) >> T.val_of); |
130 |
131 |
131 val command = kind T.Command; |
132 val command = kind T.Command; |
146 group (T.str_of_kind T.Keyword ^ " " ^ quote x) |
147 group (T.str_of_kind T.Keyword ^ " " ^ quote x) |
147 (Scan.one (T.keyword_with (equal x)) >> T.val_of); |
148 (Scan.one (T.keyword_with (equal x)) >> T.val_of); |
148 |
149 |
149 val semicolon = $$$ ";"; |
150 val semicolon = $$$ ";"; |
150 |
151 |
|
152 val minus = sym_ident :-- (fn "-" => Scan.succeed () | _ => Scan.fail) >> #1; |
151 val underscore = sym_ident :-- (fn "_" => Scan.succeed () | _ => Scan.fail) >> #1; |
153 val underscore = sym_ident :-- (fn "_" => Scan.succeed () | _ => Scan.fail) >> #1; |
152 val minus = sym_ident :-- (fn "-" => Scan.succeed () | _ => Scan.fail) >> #1; |
154 fun maybe scan = underscore >> K NONE || scan >> SOME; |
153 |
155 |
154 val nat = number >> (#1 o Library.read_int o Symbol.explode); |
156 val nat = number >> (#1 o Library.read_int o Symbol.explode); |
155 |
|
156 val not_eof = Scan.one T.not_eof; |
|
157 |
157 |
158 val opt_unit = Scan.optional ($$$ "(" -- $$$ ")" >> (K ())) (); |
158 val opt_unit = Scan.optional ($$$ "(" -- $$$ ")" >> (K ())) (); |
159 |
159 |
160 fun opt_keyword s = Scan.optional ($$$ "(" |-- !!! (($$$ s >> K true) --| $$$ ")")) false; |
160 fun opt_keyword s = Scan.optional ($$$ "(" |-- !!! (($$$ s >> K true) --| $$$ ")")) false; |
161 |
161 |
176 |
176 |
177 val name = group "name declaration" (short_ident || sym_ident || string || number); |
177 val name = group "name declaration" (short_ident || sym_ident || string || number); |
178 val xname = group "name reference" (short_ident || long_ident || sym_ident || string || number); |
178 val xname = group "name reference" (short_ident || long_ident || sym_ident || string || number); |
179 val text = group "text" (short_ident || long_ident || sym_ident || string || number || verbatim); |
179 val text = group "text" (short_ident || long_ident || sym_ident || string || number || verbatim); |
180 val path = group "file name/path specification" name >> Path.unpack; |
180 val path = group "file name/path specification" name >> Path.unpack; |
181 |
|
182 val uname = underscore >> K NONE || name >> SOME; |
|
183 |
181 |
184 |
182 |
185 (* sorts and arities *) |
183 (* sorts and arities *) |
186 |
184 |
187 val sort = group "sort" xname; |
185 val sort = group "sort" xname; |
263 val keyword_sid = keyword_symid T.is_sid; |
261 val keyword_sid = keyword_symid T.is_sid; |
264 |
262 |
265 fun atom_arg is_symid blk = |
263 fun atom_arg is_symid blk = |
266 group "argument" |
264 group "argument" |
267 (position (short_ident || long_ident || sym_ident || term_var || |
265 (position (short_ident || long_ident || sym_ident || term_var || |
268 type_ident || type_var || number) >> Args.ident || |
266 type_ident || type_var || number) >> Args.mk_ident || |
269 position (keyword_symid is_symid) >> Args.keyword || |
267 position (keyword_symid is_symid) >> Args.mk_keyword || |
270 position (string || verbatim) >> Args.string || |
268 position (string || verbatim) >> Args.mk_string || |
271 position (if blk then $$$ "," else Scan.fail) >> Args.keyword); |
269 position (if blk then $$$ "," else Scan.fail) >> Args.mk_keyword); |
272 |
270 |
273 fun paren_args l r scan = position ($$$ l) -- !!! (scan true -- position ($$$ r)) |
271 fun paren_args l r scan = position ($$$ l) -- !!! (scan true -- position ($$$ r)) |
274 >> (fn (x, (ys, z)) => Args.keyword x :: ys @ [Args.keyword z]); |
272 >> (fn (x, (ys, z)) => Args.mk_keyword x :: ys @ [Args.mk_keyword z]); |
275 |
273 |
276 fun args is_symid blk x = Scan.optional (args1 is_symid blk) [] x |
274 fun args is_symid blk x = Scan.optional (args1 is_symid blk) [] x |
277 and args1 is_symid blk x = |
275 and args1 is_symid blk x = |
278 ((Scan.repeat1 |
276 ((Scan.repeat1 |
279 (Scan.repeat1 (atom_arg is_symid blk) || |
277 (Scan.repeat1 (atom_arg is_symid blk) || |
295 |
293 |
296 val spec_name = thm_name ":" -- prop >> (fn ((x, y), z) => ((x, z), y)); |
294 val spec_name = thm_name ":" -- prop >> (fn ((x, y), z) => ((x, z), y)); |
297 val spec_opt_name = opt_thm_name ":" -- prop >> (fn ((x, y), z) => ((x, z), y)); |
295 val spec_opt_name = opt_thm_name ":" -- prop >> (fn ((x, y), z) => ((x, z), y)); |
298 |
296 |
299 val thm_sel = $$$ "(" |-- list1 |
297 val thm_sel = $$$ "(" |-- list1 |
300 ( nat --| minus -- nat >> op upto |
298 (nat --| minus -- nat >> PureThy.FromTo || |
301 || nat >> single) --| $$$ ")" >> List.concat; |
299 nat --| minus >> PureThy.From || |
|
300 nat >> PureThy.Single) --| $$$ ")"; |
302 |
301 |
303 val xthm = xname -- Scan.option thm_sel -- opt_attribs; |
302 val xthm = xname -- Scan.option thm_sel -- opt_attribs; |
304 val xthms1 = Scan.repeat1 xthm; |
303 val xthms1 = Scan.repeat1 xthm; |
305 |
304 |
306 |
305 |
323 |
322 |
324 fun plus1 scan = |
323 fun plus1 scan = |
325 scan -- Scan.repeat ($$$ "+" |-- Scan.unless loc_keyword (!!! scan)) >> op ::; |
324 scan -- Scan.repeat ($$$ "+" |-- Scan.unless loc_keyword (!!! scan)) >> op ::; |
326 |
325 |
327 fun expr2 x = (xname >> Locale.Locale || $$$ "(" |-- !!! (expr0 --| $$$ ")")) x |
326 fun expr2 x = (xname >> Locale.Locale || $$$ "(" |-- !!! (expr0 --| $$$ ")")) x |
328 and expr1 x = (expr2 -- Scan.repeat1 uname >> Locale.Rename || expr2) x |
327 and expr1 x = (expr2 -- Scan.repeat1 (maybe name) >> Locale.Rename || expr2) x |
329 and expr0 x = (plus1 expr1 >> (fn [e] => e | es => Locale.Merge es)) x; |
328 and expr0 x = (plus1 expr1 >> (fn [e] => e | es => Locale.Merge es)) x; |
330 |
329 |
331 in |
330 in |
332 |
331 |
333 val locale_target = Scan.option (($$$ "(" -- $$$ "in") |-- !!! (xname --| $$$ ")")); |
332 val locale_target = Scan.option (($$$ "(" -- $$$ "in") |-- !!! (xname --| $$$ ")")); |