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