author | wenzelm |
Tue, 21 Nov 2006 20:48:06 +0100 | |
changeset 21449 | 0413b46ee5ef |
parent 21030 | 8b21407de526 |
child 21480 | e2cc70e70b2f |
permissions | -rw-r--r-- |
5822
3f824514ad88
Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff
changeset
|
1 |
(* Title: Pure/Isar/args.ML |
3f824514ad88
Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff
changeset
|
2 |
ID: $Id$ |
3f824514ad88
Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff
changeset
|
3 |
Author: Markus Wenzel, TU Muenchen |
3f824514ad88
Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff
changeset
|
4 |
|
15703 | 5 |
Concrete argument syntax of attributes, methods etc. -- with special |
6 |
support for embedded values and static binding. |
|
5822
3f824514ad88
Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff
changeset
|
7 |
*) |
3f824514ad88
Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff
changeset
|
8 |
|
3f824514ad88
Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff
changeset
|
9 |
signature ARGS = |
3f824514ad88
Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff
changeset
|
10 |
sig |
18728 | 11 |
datatype value = |
12 |
Name of string | Typ of typ | Term of term | Fact of thm list | Attribute of attribute |
|
5822
3f824514ad88
Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff
changeset
|
13 |
type T |
9748 | 14 |
val string_of: T -> string |
15703 | 15 |
val mk_ident: string * Position.T -> T |
16 |
val mk_string: string * Position.T -> T |
|
18037 | 17 |
val mk_alt_string: string * Position.T -> T |
15703 | 18 |
val mk_keyword: string * Position.T -> T |
19 |
val mk_name: string -> T |
|
20 |
val mk_typ: typ -> T |
|
21 |
val mk_term: term -> T |
|
22 |
val mk_fact: thm list -> T |
|
18728 | 23 |
val mk_attribute: attribute -> T |
5822
3f824514ad88
Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff
changeset
|
24 |
val stopper: T * (T -> bool) |
3f824514ad88
Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff
changeset
|
25 |
val not_eof: T -> bool |
15703 | 26 |
type src |
27 |
val src: (string * T list) * Position.T -> src |
|
28 |
val dest_src: src -> (string * T list) * Position.T |
|
21030 | 29 |
val pretty_src: Proof.context -> src -> Pretty.T |
15703 | 30 |
val map_name: (string -> string) -> src -> src |
31 |
val map_values: (string -> string) -> (typ -> typ) -> (term -> term) -> (thm -> thm) |
|
32 |
-> src -> src |
|
20263 | 33 |
val maxidx_values: src -> int -> int |
15703 | 34 |
val assignable: src -> src |
35 |
val assign: value option -> T -> unit |
|
36 |
val closure: src -> src |
|
5878 | 37 |
val position: (T list -> 'a * 'b) -> T list -> ('a * Position.T) * 'b |
38 |
val !!! : (T list -> 'a) -> T list -> 'a |
|
5822
3f824514ad88
Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff
changeset
|
39 |
val $$$ : string -> T list -> string * T list |
10035 | 40 |
val add: T list -> string * T list |
41 |
val del: T list -> string * T list |
|
8803 | 42 |
val colon: T list -> string * T list |
10035 | 43 |
val query: T list -> string * T list |
44 |
val bang: T list -> string * T list |
|
45 |
val query_colon: T list -> string * T list |
|
46 |
val bang_colon: T list -> string * T list |
|
8803 | 47 |
val parens: (T list -> 'a * T list) -> T list -> 'a * T list |
10150 | 48 |
val bracks: (T list -> 'a * T list) -> T list -> 'a * T list |
9809 | 49 |
val mode: string -> 'a * T list -> bool * ('a * T list) |
15703 | 50 |
val maybe: (T list -> 'a * T list) -> T list -> 'a option * T list |
5822
3f824514ad88
Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff
changeset
|
51 |
val name: T list -> string * T list |
18037 | 52 |
val alt_name: T list -> string * T list |
16140 | 53 |
val symbol: T list -> string * T list |
17064 | 54 |
val liberal_name: T list -> string * T list |
5878 | 55 |
val nat: T list -> int * T list |
9538 | 56 |
val int: T list -> int * T list |
5878 | 57 |
val var: T list -> indexname * T list |
15703 | 58 |
val list: (T list -> 'a * T list) -> T list -> 'a list * T list |
59 |
val list1: (T list -> 'a * T list) -> T list -> 'a list * T list |
|
6447 | 60 |
val enum: string -> ('a * T list -> 'b * ('a * T list)) -> 'a * T list -> 'b list * ('a * T list) |
61 |
val enum1: string -> ('a * T list -> 'b * ('a * T list)) -> 'a * T list -> 'b list * ('a * T list) |
|
62 |
val and_list: ('a * T list -> 'b * ('a * T list)) -> 'a * T list -> 'b list * ('a * T list) |
|
63 |
val and_list1: ('a * T list -> 'b * ('a * T list)) -> 'a * T list -> 'b list * ('a * T list) |
|
15703 | 64 |
val ahead: T list -> T * T list |
65 |
val internal_name: T list -> string * T list |
|
66 |
val internal_typ: T list -> typ * T list |
|
67 |
val internal_term: T list -> term * T list |
|
68 |
val internal_fact: T list -> thm list * T list |
|
18728 | 69 |
val internal_attribute: T list -> attribute * T list |
15703 | 70 |
val named_name: (string -> string) -> T list -> string * T list |
71 |
val named_typ: (string -> typ) -> T list -> typ * T list |
|
72 |
val named_term: (string -> term) -> T list -> term * T list |
|
73 |
val named_fact: (string -> thm list) -> T list -> thm list * T list |
|
18635 | 74 |
val typ_abbrev: Context.generic * T list -> typ * (Context.generic * T list) |
75 |
val typ: Context.generic * T list -> typ * (Context.generic * T list) |
|
76 |
val term: Context.generic * T list -> term * (Context.generic * T list) |
|
77 |
val prop: Context.generic * T list -> term * (Context.generic * T list) |
|
78 |
val tyname: Context.generic * T list -> string * (Context.generic * T list) |
|
79 |
val const: Context.generic * T list -> string * (Context.generic * T list) |
|
15703 | 80 |
val thm_sel: T list -> PureThy.interval list * T list |
18998 | 81 |
val bang_facts: Context.generic * T list -> thm list * (Context.generic * T list) |
8536 | 82 |
val goal_spec: ((int -> tactic) -> tactic) -> ('a * T list) |
83 |
-> ((int -> tactic) -> tactic) * ('a * T list) |
|
15703 | 84 |
val attribs: (string -> string) -> T list -> src list * T list |
85 |
val opt_attribs: (string -> string) -> T list -> src list * T list |
|
18998 | 86 |
val syntax: string -> ('b * T list -> 'a * ('b * T list)) -> src -> 'b -> 'b * 'a |
87 |
val context_syntax: string -> (Context.generic * T list -> 'a * (Context.generic * T list)) -> |
|
20289 | 88 |
src -> Proof.context -> Proof.context * 'a |
5822
3f824514ad88
Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff
changeset
|
89 |
end; |
3f824514ad88
Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff
changeset
|
90 |
|
3f824514ad88
Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff
changeset
|
91 |
structure Args: ARGS = |
3f824514ad88
Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff
changeset
|
92 |
struct |
3f824514ad88
Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff
changeset
|
93 |
|
3f824514ad88
Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff
changeset
|
94 |
|
3f824514ad88
Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff
changeset
|
95 |
(** datatype T **) |
3f824514ad88
Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff
changeset
|
96 |
|
15703 | 97 |
(*An argument token is a symbol (with raw string value), together with |
98 |
an optional assigned internal value. Note that an assignable ref |
|
99 |
designates an intermediate state of internalization -- it is NOT |
|
100 |
meant to persist.*) |
|
101 |
||
18037 | 102 |
datatype kind = Ident | String | AltString | Keyword | EOF; |
15703 | 103 |
|
104 |
type symbol = kind * string * Position.T; |
|
5822
3f824514ad88
Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff
changeset
|
105 |
|
15703 | 106 |
datatype value = |
107 |
Name of string | |
|
108 |
Typ of typ | |
|
109 |
Term of term | |
|
110 |
Fact of thm list | |
|
18728 | 111 |
Attribute of attribute; |
15703 | 112 |
|
113 |
datatype slot = |
|
114 |
Empty | |
|
115 |
Value of value option | |
|
116 |
Assignable of value option ref; |
|
117 |
||
118 |
datatype T = Arg of symbol * slot; |
|
5822
3f824514ad88
Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff
changeset
|
119 |
|
15703 | 120 |
fun string_of (Arg ((Ident, x, _), _)) = x |
18037 | 121 |
| string_of (Arg ((String, x, _), _)) = quote x |
122 |
| string_of (Arg ((AltString, x, _), _)) = enclose "`" "`" x |
|
15703 | 123 |
| string_of (Arg ((Keyword, x, _), _)) = x |
124 |
| string_of (Arg ((EOF, _, _), _)) = ""; |
|
125 |
||
126 |
fun sym_of (Arg ((_, x, _), _)) = x; |
|
127 |
fun pos_of (Arg ((_, _, pos), _)) = pos; |
|
128 |
||
129 |
||
130 |
(* basic constructors *) |
|
5822
3f824514ad88
Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff
changeset
|
131 |
|
15703 | 132 |
fun mk_symbol k (x, p) = Arg ((k, x, p), Empty); |
133 |
fun mk_value k v = Arg ((Keyword, k, Position.none), Value (SOME v)); |
|
9748 | 134 |
|
15703 | 135 |
val mk_ident = mk_symbol Ident; |
136 |
val mk_string = mk_symbol String; |
|
18037 | 137 |
val mk_alt_string = mk_symbol AltString; |
15703 | 138 |
val mk_keyword = mk_symbol Keyword; |
139 |
val mk_name = mk_value "<name>" o Name; |
|
140 |
val mk_typ = mk_value "<typ>" o Typ; |
|
141 |
val mk_term = mk_value "<term>" o Term; |
|
142 |
val mk_fact = mk_value "<fact>" o Fact; |
|
143 |
val mk_attribute = mk_value "<attribute>" o Attribute; |
|
5822
3f824514ad88
Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff
changeset
|
144 |
|
3f824514ad88
Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff
changeset
|
145 |
|
3f824514ad88
Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff
changeset
|
146 |
(* eof *) |
3f824514ad88
Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff
changeset
|
147 |
|
15703 | 148 |
val eof = mk_symbol EOF ("", Position.none); |
5822
3f824514ad88
Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff
changeset
|
149 |
|
15703 | 150 |
fun is_eof (Arg ((EOF, _, _), _)) = true |
5822
3f824514ad88
Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff
changeset
|
151 |
| is_eof _ = false; |
3f824514ad88
Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff
changeset
|
152 |
|
3f824514ad88
Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff
changeset
|
153 |
val stopper = (eof, is_eof); |
3f824514ad88
Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff
changeset
|
154 |
val not_eof = not o is_eof; |
3f824514ad88
Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff
changeset
|
155 |
|
3f824514ad88
Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff
changeset
|
156 |
|
3f824514ad88
Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff
changeset
|
157 |
|
15703 | 158 |
(** datatype src **) |
159 |
||
160 |
datatype src = Src of (string * T list) * Position.T; |
|
161 |
||
162 |
val src = Src; |
|
163 |
fun dest_src (Src src) = src; |
|
164 |
||
21030 | 165 |
fun pretty_src ctxt src = |
166 |
let |
|
167 |
fun prt (Arg (_, Value (SOME (Name s)))) = Pretty.str (quote s) |
|
168 |
| prt (Arg (_, Value (SOME (Typ T)))) = ProofContext.pretty_typ ctxt T |
|
169 |
| prt (Arg (_, Value (SOME (Term t)))) = ProofContext.pretty_term ctxt t |
|
170 |
| prt (Arg (_, Value (SOME (Fact ths)))) = ProofContext.pretty_thms ctxt ths |
|
171 |
| prt arg = Pretty.str (string_of arg); |
|
172 |
val (s, args) = #1 (dest_src src); |
|
173 |
in Pretty.block (Pretty.breaks (Pretty.str s :: map prt args)) end; |
|
174 |
||
15703 | 175 |
fun map_name f (Src ((s, args), pos)) = Src ((f s, args), pos); |
176 |
fun map_args f (Src ((s, args), pos)) = Src ((s, map f args), pos); |
|
177 |
||
178 |
||
179 |
(* values *) |
|
180 |
||
181 |
fun map_value f (Arg (s, Value (SOME v))) = Arg (s, Value (SOME (f v))) |
|
182 |
| map_value _ arg = arg; |
|
183 |
||
184 |
fun map_values f g h i = map_args (map_value |
|
185 |
(fn Name s => Name (f s) |
|
186 |
| Typ T => Typ (g T) |
|
187 |
| Term t => Term (h t) |
|
188 |
| Fact ths => Fact (map i ths) |
|
189 |
| Attribute att => Attribute att)); |
|
190 |
||
20263 | 191 |
fun maxidx_values (Src ((_, args), _)) = args |> fold |
192 |
(fn (Arg (_, Value (SOME (Typ T)))) => Term.maxidx_typ T |
|
193 |
| (Arg (_, Value (SOME (Term t)))) => Term.maxidx_term t |
|
194 |
| (Arg (_, Value (SOME (Fact ths)))) => fold Thm.maxidx_thm ths |
|
195 |
| _ => I); |
|
196 |
||
15703 | 197 |
|
198 |
(* static binding *) |
|
199 |
||
200 |
(*1st stage: make empty slots assignable*) |
|
201 |
val assignable = |
|
202 |
map_args (fn Arg (s, Empty) => Arg (s, Assignable (ref NONE)) | arg => arg); |
|
203 |
||
204 |
(*2nd stage: assign values as side-effect of scanning*) |
|
205 |
fun assign v (arg as Arg (_, Assignable r)) = r := v |
|
206 |
| assign _ _ = (); |
|
207 |
||
208 |
val ahead = Scan.ahead (Scan.one not_eof); |
|
209 |
fun touch scan = ahead -- scan >> (fn (arg, y) => (assign NONE arg; y)); |
|
210 |
||
211 |
(*3rd stage: static closure of final values*) |
|
212 |
val closure = |
|
213 |
map_args (fn Arg (s, Assignable (ref v)) => Arg (s, Value v) | arg => arg); |
|
214 |
||
215 |
||
216 |
||
5822
3f824514ad88
Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff
changeset
|
217 |
(** scanners **) |
3f824514ad88
Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff
changeset
|
218 |
|
5878 | 219 |
(* position *) |
220 |
||
15703 | 221 |
fun position scan = |
222 |
(Scan.ahead (Scan.one not_eof) >> pos_of) -- scan >> Library.swap; |
|
5878 | 223 |
|
224 |
||
225 |
(* cut *) |
|
226 |
||
227 |
fun !!! scan = |
|
228 |
let |
|
229 |
fun get_pos [] = " (past end-of-text!)" |
|
15703 | 230 |
| get_pos (arg :: _) = Position.str_of (pos_of arg); |
5878 | 231 |
|
15531 | 232 |
fun err (args, NONE) = "Argument syntax error" ^ get_pos args |
233 |
| err (args, SOME msg) = "Argument syntax error" ^ get_pos args ^ ": " ^ msg; |
|
5878 | 234 |
in Scan.!! err scan end; |
235 |
||
236 |
||
5822
3f824514ad88
Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff
changeset
|
237 |
(* basic *) |
3f824514ad88
Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff
changeset
|
238 |
|
15703 | 239 |
fun some_ident f = |
240 |
touch (Scan.some (fn Arg ((Ident, x, _), _) => f x | _ => NONE)); |
|
241 |
||
242 |
val named = |
|
243 |
touch (Scan.one (fn Arg ((k, _, _), _) => k = Ident orelse k = String)); |
|
244 |
||
18037 | 245 |
val alt_string = |
246 |
touch (Scan.one (fn Arg ((k, _, _), _) => k = AltString)); |
|
247 |
||
15703 | 248 |
val symbolic = |
249 |
touch (Scan.one (fn Arg ((k, x, _), _) => k = Keyword andalso OuterLex.is_sid x)); |
|
250 |
||
251 |
fun &&& x = |
|
252 |
touch (Scan.one (fn Arg ((k, y, _), _) => k = Keyword andalso x = y)); |
|
253 |
||
254 |
fun $$$ x = |
|
16140 | 255 |
touch (Scan.one (fn Arg ((k, y, _), _) => (k = Ident orelse k = Keyword) andalso x = y)) |
256 |
>> sym_of; |
|
5878 | 257 |
|
10035 | 258 |
val add = $$$ "add"; |
259 |
val del = $$$ "del"; |
|
8803 | 260 |
val colon = $$$ ":"; |
10035 | 261 |
val query = $$$ "?"; |
262 |
val bang = $$$ "!"; |
|
20111 | 263 |
val query_colon = $$$ "?" ^^ $$$ ":"; |
264 |
val bang_colon = $$$ "!" ^^ $$$ ":"; |
|
10035 | 265 |
|
8803 | 266 |
fun parens scan = $$$ "(" |-- scan --| $$$ ")"; |
10150 | 267 |
fun bracks scan = $$$ "[" |-- scan --| $$$ "]"; |
15703 | 268 |
fun mode s = Scan.lift (Scan.optional (parens ($$$ s) >> K true) false); |
269 |
fun maybe scan = $$$ "_" >> K NONE || scan >> SOME; |
|
5878 | 270 |
|
15703 | 271 |
val name = named >> sym_of; |
18037 | 272 |
val alt_name = alt_string >> sym_of; |
16140 | 273 |
val symbol = symbolic >> sym_of; |
17064 | 274 |
val liberal_name = symbol || name; |
8233 | 275 |
|
15703 | 276 |
val nat = some_ident Syntax.read_nat; |
9538 | 277 |
val int = Scan.optional ($$$ "-" >> K ~1) 1 -- nat >> op *; |
15987 | 278 |
val var = some_ident Syntax.read_variable; |
14563 | 279 |
|
5822
3f824514ad88
Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff
changeset
|
280 |
|
5878 | 281 |
(* enumerations *) |
282 |
||
15703 | 283 |
fun list1 scan = scan -- Scan.repeat ($$$ "," |-- scan) >> op ::; |
284 |
fun list scan = list1 scan || Scan.succeed []; |
|
285 |
||
6447 | 286 |
fun enum1 sep scan = scan -- Scan.repeat (Scan.lift ($$$ sep) |-- scan) >> op ::; |
5878 | 287 |
fun enum sep scan = enum1 sep scan || Scan.succeed []; |
288 |
||
6447 | 289 |
fun and_list1 scan = enum1 "and" scan; |
290 |
fun and_list scan = enum "and" scan; |
|
5878 | 291 |
|
5822
3f824514ad88
Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff
changeset
|
292 |
|
15703 | 293 |
(* values *) |
294 |
||
295 |
fun value dest = Scan.some (*no touch here*) |
|
296 |
(fn Arg (_, Value (SOME v)) => (SOME (dest v) handle Match => NONE) |
|
297 |
| Arg _ => NONE); |
|
298 |
||
299 |
fun evaluate mk eval arg = |
|
300 |
let val x = eval (sym_of arg) in (assign (SOME (mk x)) arg; x) end; |
|
301 |
||
302 |
val internal_name = value (fn Name s => s); |
|
303 |
val internal_typ = value (fn Typ T => T); |
|
304 |
val internal_term = value (fn Term t => t); |
|
305 |
val internal_fact = value (fn Fact ths => ths); |
|
306 |
val internal_attribute = value (fn Attribute att => att); |
|
307 |
||
308 |
fun named_name intern = internal_name || named >> evaluate Name intern; |
|
309 |
fun named_typ readT = internal_typ || named >> evaluate Typ readT; |
|
310 |
fun named_term read = internal_term || named >> evaluate Term read; |
|
18037 | 311 |
fun named_fact get = internal_fact || (alt_string || named) >> evaluate Fact get; |
15703 | 312 |
|
313 |
||
5878 | 314 |
(* terms and types *) |
315 |
||
18635 | 316 |
val typ_abbrev = Scan.peek (named_typ o ProofContext.read_typ_abbrev o Context.proof_of); |
317 |
val typ = Scan.peek (named_typ o ProofContext.read_typ o Context.proof_of); |
|
318 |
val term = Scan.peek (named_term o ProofContext.read_term o Context.proof_of); |
|
319 |
val prop = Scan.peek (named_term o ProofContext.read_prop o Context.proof_of); |
|
320 |
||
5878 | 321 |
|
15703 | 322 |
(* type and constant names *) |
323 |
||
18998 | 324 |
val tyname = Scan.peek (named_typ o Context.cases Sign.read_tyname ProofContext.read_tyname) |
325 |
>> (fn Type (c, _) => c | TFree (a, _) => a | _ => ""); |
|
15703 | 326 |
|
18998 | 327 |
val const = Scan.peek (named_term o Context.cases Sign.read_const ProofContext.read_const) |
328 |
>> (fn Const (c, _) => c | Free (x, _) => x | _ => ""); |
|
7553 | 329 |
|
15703 | 330 |
|
331 |
(* misc *) |
|
332 |
||
333 |
val thm_sel = parens (list1 |
|
334 |
(nat --| $$$ "-" -- nat >> PureThy.FromTo || |
|
335 |
nat --| $$$ "-" >> PureThy.From || |
|
336 |
nat >> PureThy.Single)); |
|
337 |
||
18998 | 338 |
val bang_facts = Scan.peek (fn context => |
20224
9c40a144ee0e
moved basic assumption operations from structure ProofContext to Assumption;
wenzelm
parents:
20111
diff
changeset
|
339 |
$$$ "!" >> K (Assumption.prems_of (Context.proof_of context)) || Scan.succeed []); |
7553 | 340 |
|
341 |
||
8536 | 342 |
(* goal specification *) |
343 |
||
344 |
(* range *) |
|
8233 | 345 |
|
8536 | 346 |
val from_to = |
15703 | 347 |
nat -- ($$$ "-" |-- nat) >> (fn (i, j) => fn tac => Seq.INTERVAL tac i j) || |
348 |
nat --| $$$ "-" >> (fn i => fn tac => fn st => Seq.INTERVAL tac i (Thm.nprems_of st) st) || |
|
8549 | 349 |
nat >> (fn i => fn tac => tac i) || |
15703 | 350 |
$$$ "!" >> K ALLGOALS; |
8536 | 351 |
|
15703 | 352 |
val goal = $$$ "[" |-- !!! (from_to --| $$$ "]"); |
8536 | 353 |
fun goal_spec def = Scan.lift (Scan.optional goal def); |
8233 | 354 |
|
355 |
||
15703 | 356 |
|
357 |
(* attribs *) |
|
358 |
||
359 |
local |
|
5878 | 360 |
|
20664 | 361 |
val exclude = member (op =) (explode "()[],"); |
5822
3f824514ad88
Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff
changeset
|
362 |
|
15703 | 363 |
fun atomic blk = touch (Scan.one (fn Arg ((k, x, _), _) => |
20664 | 364 |
k <> Keyword orelse not (exclude x) orelse blk andalso x = ",")); |
5822
3f824514ad88
Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff
changeset
|
365 |
|
5878 | 366 |
fun args blk x = Scan.optional (args1 blk) [] x |
367 |
and args1 blk x = |
|
368 |
((Scan.repeat1 |
|
15703 | 369 |
(Scan.repeat1 (atomic blk) || |
370 |
argsp "(" ")" || |
|
19482
9f11af8f7ef9
tuned basic list operators (flat, maps, map_filter);
wenzelm
parents:
18998
diff
changeset
|
371 |
argsp "[" "]")) >> flat) x |
15703 | 372 |
and argsp l r x = |
373 |
(Scan.trace (&&& l -- !!! (args true -- &&& r)) >> #2) x; |
|
374 |
||
375 |
in |
|
5822
3f824514ad88
Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff
changeset
|
376 |
|
15703 | 377 |
fun attribs intern = |
378 |
let |
|
379 |
val attrib_name = internal_name || (symbolic || named) >> evaluate Name intern; |
|
380 |
val attrib = position (attrib_name -- !!! (args false)) >> src; |
|
381 |
in $$$ "[" |-- !!! (list attrib --| $$$ "]") end; |
|
382 |
||
383 |
fun opt_attribs intern = Scan.optional (attribs intern) []; |
|
384 |
||
385 |
end; |
|
5822
3f824514ad88
Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff
changeset
|
386 |
|
3f824514ad88
Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff
changeset
|
387 |
|
15703 | 388 |
(* syntax interface *) |
5822
3f824514ad88
Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff
changeset
|
389 |
|
8282 | 390 |
fun syntax kind scan (src as Src ((s, args), pos)) st = |
9901 | 391 |
(case Scan.error (Scan.finite' stopper (Scan.option scan)) (st, args) of |
15531 | 392 |
(SOME x, (st', [])) => (st', x) |
15703 | 393 |
| (_, (_, args')) => |
394 |
error (kind ^ " " ^ quote s ^ Position.str_of pos ^ ": bad arguments\n " ^ |
|
395 |
space_implode " " (map string_of args'))); |
|
396 |
||
18998 | 397 |
fun context_syntax kind scan src = apfst Context.the_proof o syntax kind scan src o Context.Proof; |
398 |
||
5822
3f824514ad88
Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff
changeset
|
399 |
end; |