author | wenzelm |
Tue, 17 May 2005 18:10:40 +0200 | |
changeset 15987 | 35ec4802c66c |
parent 15726 | 67e9ed435df7 |
child 16140 | fc51e61d45fb |
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 |
15703 | 11 |
datatype value = Name of string | Typ of typ | Term of term | Fact of thm list | |
12 |
Attribute of theory attribute * ProofContext.context 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 |
|
17 |
val mk_keyword: string * Position.T -> T |
|
18 |
val mk_name: string -> T |
|
19 |
val mk_typ: typ -> T |
|
20 |
val mk_term: term -> T |
|
21 |
val mk_fact: thm list -> T |
|
22 |
val mk_attribute: theory attribute * ProofContext.context attribute -> T |
|
5822
3f824514ad88
Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff
changeset
|
23 |
val stopper: T * (T -> bool) |
3f824514ad88
Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff
changeset
|
24 |
val not_eof: T -> bool |
15703 | 25 |
type src |
26 |
val src: (string * T list) * Position.T -> src |
|
27 |
val dest_src: src -> (string * T list) * Position.T |
|
28 |
val map_name: (string -> string) -> src -> src |
|
29 |
val map_values: (string -> string) -> (typ -> typ) -> (term -> term) -> (thm -> thm) |
|
30 |
-> src -> src |
|
31 |
val assignable: src -> src |
|
32 |
val assign: value option -> T -> unit |
|
33 |
val closure: src -> src |
|
5878 | 34 |
val position: (T list -> 'a * 'b) -> T list -> ('a * Position.T) * 'b |
35 |
val !!! : (T list -> 'a) -> T list -> 'a |
|
5822
3f824514ad88
Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff
changeset
|
36 |
val $$$ : string -> T list -> string * T list |
10035 | 37 |
val add: T list -> string * T list |
38 |
val del: T list -> string * T list |
|
8803 | 39 |
val colon: T list -> string * T list |
10035 | 40 |
val query: T list -> string * T list |
41 |
val bang: T list -> string * T list |
|
42 |
val query_colon: T list -> string * T list |
|
43 |
val bang_colon: T list -> string * T list |
|
8803 | 44 |
val parens: (T list -> 'a * T list) -> T list -> 'a * T list |
10150 | 45 |
val bracks: (T list -> 'a * T list) -> T list -> 'a * T list |
9809 | 46 |
val mode: string -> 'a * T list -> bool * ('a * T list) |
15703 | 47 |
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
|
48 |
val name: T list -> string * T list |
5878 | 49 |
val nat: T list -> int * T list |
9538 | 50 |
val int: T list -> int * T list |
5878 | 51 |
val var: T list -> indexname * T list |
15703 | 52 |
val list: (T list -> 'a * T list) -> T list -> 'a list * T list |
53 |
val list1: (T list -> 'a * T list) -> T list -> 'a list * T list |
|
6447 | 54 |
val enum: string -> ('a * T list -> 'b * ('a * T list)) -> 'a * T list -> 'b list * ('a * T list) |
55 |
val enum1: string -> ('a * T list -> 'b * ('a * T list)) -> 'a * T list -> 'b list * ('a * T list) |
|
56 |
val and_list: ('a * T list -> 'b * ('a * T list)) -> 'a * T list -> 'b list * ('a * T list) |
|
57 |
val and_list1: ('a * T list -> 'b * ('a * T list)) -> 'a * T list -> 'b list * ('a * T list) |
|
15703 | 58 |
val ahead: T list -> T * T list |
59 |
val internal_name: T list -> string * T list |
|
60 |
val internal_typ: T list -> typ * T list |
|
61 |
val internal_term: T list -> term * T list |
|
62 |
val internal_fact: T list -> thm list * T list |
|
63 |
val internal_attribute: T list -> |
|
64 |
(theory attribute * ProofContext.context attribute) * T list |
|
65 |
val named_name: (string -> string) -> T list -> string * T list |
|
66 |
val named_typ: (string -> typ) -> T list -> typ * T list |
|
67 |
val named_term: (string -> term) -> T list -> term * T list |
|
68 |
val named_fact: (string -> thm list) -> T list -> thm list * T list |
|
14780 | 69 |
val global_typ_raw: theory * T list -> typ * (theory * T list) |
5878 | 70 |
val global_typ: theory * T list -> typ * (theory * T list) |
71 |
val global_term: theory * T list -> term * (theory * T list) |
|
72 |
val global_prop: theory * T list -> term * (theory * T list) |
|
15596 | 73 |
val local_typ_raw: ProofContext.context * T list -> typ * (ProofContext.context * T list) |
74 |
val local_typ: ProofContext.context * T list -> typ * (ProofContext.context * T list) |
|
75 |
val local_term: ProofContext.context * T list -> term * (ProofContext.context * T list) |
|
76 |
val local_prop: ProofContext.context * T list -> term * (ProofContext.context * T list) |
|
15703 | 77 |
val global_tyname: theory * T list -> string * (theory * T list) |
78 |
val global_const: theory * T list -> string * (theory * T list) |
|
79 |
val local_tyname: ProofContext.context * T list -> string * (ProofContext.context * T list) |
|
80 |
val local_const: ProofContext.context * T list -> string * (ProofContext.context * T list) |
|
81 |
val thm_sel: T list -> PureThy.interval list * T list |
|
15596 | 82 |
val bang_facts: ProofContext.context * T list -> thm list * (ProofContext.context * T list) |
8536 | 83 |
val goal_spec: ((int -> tactic) -> tactic) -> ('a * T list) |
84 |
-> ((int -> tactic) -> tactic) * ('a * T list) |
|
15703 | 85 |
val attribs: (string -> string) -> T list -> src list * T list |
86 |
val opt_attribs: (string -> string) -> T list -> src list * T list |
|
8282 | 87 |
val syntax: string -> ('a * T list -> 'b * ('a * T list)) -> src -> 'a -> 'a * 'b |
15703 | 88 |
val pretty_src: ProofContext.context -> src -> Pretty.T |
89 |
val pretty_attribs: ProofContext.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 |
||
5822
3f824514ad88
Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff
changeset
|
103 |
datatype kind = Ident | String | 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 | |
|
112 |
Attribute of theory attribute * ProofContext.context attribute; |
|
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 |
122 |
| string_of (Arg ((String, x, _), _)) = Library.quote x |
|
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; |
|
137 |
val mk_keyword = mk_symbol Keyword; |
|
138 |
val mk_name = mk_value "<name>" o Name; |
|
139 |
val mk_typ = mk_value "<typ>" o Typ; |
|
140 |
val mk_term = mk_value "<term>" o Term; |
|
141 |
val mk_fact = mk_value "<fact>" o Fact; |
|
142 |
val mk_attribute = mk_value "<attribute>" o Attribute; |
|
5822
3f824514ad88
Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff
changeset
|
143 |
|
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 |
(* eof *) |
3f824514ad88
Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff
changeset
|
146 |
|
15703 | 147 |
val eof = mk_symbol EOF ("", Position.none); |
5822
3f824514ad88
Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff
changeset
|
148 |
|
15703 | 149 |
fun is_eof (Arg ((EOF, _, _), _)) = true |
5822
3f824514ad88
Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff
changeset
|
150 |
| is_eof _ = false; |
3f824514ad88
Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff
changeset
|
151 |
|
3f824514ad88
Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff
changeset
|
152 |
val stopper = (eof, is_eof); |
3f824514ad88
Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff
changeset
|
153 |
val not_eof = not o is_eof; |
3f824514ad88
Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff
changeset
|
154 |
|
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 |
|
15703 | 157 |
(** datatype src **) |
158 |
||
159 |
datatype src = Src of (string * T list) * Position.T; |
|
160 |
||
161 |
val src = Src; |
|
162 |
fun dest_src (Src src) = src; |
|
163 |
||
164 |
fun map_name f (Src ((s, args), pos)) = Src ((f s, args), pos); |
|
165 |
fun map_args f (Src ((s, args), pos)) = Src ((s, map f args), pos); |
|
166 |
||
167 |
||
168 |
(* values *) |
|
169 |
||
170 |
fun map_value f (Arg (s, Value (SOME v))) = Arg (s, Value (SOME (f v))) |
|
171 |
| map_value _ arg = arg; |
|
172 |
||
173 |
fun map_values f g h i = map_args (map_value |
|
174 |
(fn Name s => Name (f s) |
|
175 |
| Typ T => Typ (g T) |
|
176 |
| Term t => Term (h t) |
|
177 |
| Fact ths => Fact (map i ths) |
|
178 |
| Attribute att => Attribute att)); |
|
179 |
||
180 |
||
181 |
(* static binding *) |
|
182 |
||
183 |
(*1st stage: make empty slots assignable*) |
|
184 |
val assignable = |
|
185 |
map_args (fn Arg (s, Empty) => Arg (s, Assignable (ref NONE)) | arg => arg); |
|
186 |
||
187 |
(*2nd stage: assign values as side-effect of scanning*) |
|
188 |
fun assign v (arg as Arg (_, Assignable r)) = r := v |
|
189 |
| assign _ _ = (); |
|
190 |
||
191 |
val ahead = Scan.ahead (Scan.one not_eof); |
|
192 |
fun touch scan = ahead -- scan >> (fn (arg, y) => (assign NONE arg; y)); |
|
193 |
||
194 |
(*3rd stage: static closure of final values*) |
|
195 |
val closure = |
|
196 |
map_args (fn Arg (s, Assignable (ref v)) => Arg (s, Value v) | arg => arg); |
|
197 |
||
198 |
||
199 |
||
5822
3f824514ad88
Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff
changeset
|
200 |
(** scanners **) |
3f824514ad88
Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff
changeset
|
201 |
|
5878 | 202 |
(* position *) |
203 |
||
15703 | 204 |
fun position scan = |
205 |
(Scan.ahead (Scan.one not_eof) >> pos_of) -- scan >> Library.swap; |
|
5878 | 206 |
|
207 |
||
208 |
(* cut *) |
|
209 |
||
210 |
fun !!! scan = |
|
211 |
let |
|
212 |
fun get_pos [] = " (past end-of-text!)" |
|
15703 | 213 |
| get_pos (arg :: _) = Position.str_of (pos_of arg); |
5878 | 214 |
|
15531 | 215 |
fun err (args, NONE) = "Argument syntax error" ^ get_pos args |
216 |
| err (args, SOME msg) = "Argument syntax error" ^ get_pos args ^ ": " ^ msg; |
|
5878 | 217 |
in Scan.!! err scan end; |
218 |
||
219 |
||
5822
3f824514ad88
Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff
changeset
|
220 |
(* basic *) |
3f824514ad88
Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff
changeset
|
221 |
|
15703 | 222 |
fun some_ident f = |
223 |
touch (Scan.some (fn Arg ((Ident, x, _), _) => f x | _ => NONE)); |
|
224 |
||
225 |
val named = |
|
226 |
touch (Scan.one (fn Arg ((k, _, _), _) => k = Ident orelse k = String)); |
|
227 |
||
228 |
val symbolic = |
|
229 |
touch (Scan.one (fn Arg ((k, x, _), _) => k = Keyword andalso OuterLex.is_sid x)); |
|
230 |
||
231 |
fun &&& x = |
|
232 |
touch (Scan.one (fn Arg ((k, y, _), _) => k = Keyword andalso x = y)); |
|
233 |
||
234 |
fun $$$ x = |
|
235 |
touch (Scan.one (fn Arg ((k, y, _), _) => (k = Ident orelse k = Keyword) andalso x = y) >> sym_of); |
|
5878 | 236 |
|
10035 | 237 |
val add = $$$ "add"; |
238 |
val del = $$$ "del"; |
|
8803 | 239 |
val colon = $$$ ":"; |
10035 | 240 |
val query = $$$ "?"; |
241 |
val bang = $$$ "!"; |
|
242 |
val query_colon = $$$ "?:"; |
|
243 |
val bang_colon = $$$ "!:"; |
|
244 |
||
8803 | 245 |
fun parens scan = $$$ "(" |-- scan --| $$$ ")"; |
10150 | 246 |
fun bracks scan = $$$ "[" |-- scan --| $$$ "]"; |
15703 | 247 |
fun mode s = Scan.lift (Scan.optional (parens ($$$ s) >> K true) false); |
248 |
fun maybe scan = $$$ "_" >> K NONE || scan >> SOME; |
|
5878 | 249 |
|
15703 | 250 |
val name = named >> sym_of; |
8233 | 251 |
|
15703 | 252 |
val nat = some_ident Syntax.read_nat; |
9538 | 253 |
val int = Scan.optional ($$$ "-" >> K ~1) 1 -- nat >> op *; |
15987 | 254 |
val var = some_ident Syntax.read_variable; |
14563 | 255 |
|
5822
3f824514ad88
Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff
changeset
|
256 |
|
5878 | 257 |
(* enumerations *) |
258 |
||
15703 | 259 |
fun list1 scan = scan -- Scan.repeat ($$$ "," |-- scan) >> op ::; |
260 |
fun list scan = list1 scan || Scan.succeed []; |
|
261 |
||
6447 | 262 |
fun enum1 sep scan = scan -- Scan.repeat (Scan.lift ($$$ sep) |-- scan) >> op ::; |
5878 | 263 |
fun enum sep scan = enum1 sep scan || Scan.succeed []; |
264 |
||
6447 | 265 |
fun and_list1 scan = enum1 "and" scan; |
266 |
fun and_list scan = enum "and" scan; |
|
5878 | 267 |
|
5822
3f824514ad88
Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff
changeset
|
268 |
|
15703 | 269 |
(* values *) |
270 |
||
271 |
fun value dest = Scan.some (*no touch here*) |
|
272 |
(fn Arg (_, Value (SOME v)) => (SOME (dest v) handle Match => NONE) |
|
273 |
| Arg _ => NONE); |
|
274 |
||
275 |
fun evaluate mk eval arg = |
|
276 |
let val x = eval (sym_of arg) in (assign (SOME (mk x)) arg; x) end; |
|
277 |
||
278 |
val internal_name = value (fn Name s => s); |
|
279 |
val internal_typ = value (fn Typ T => T); |
|
280 |
val internal_term = value (fn Term t => t); |
|
281 |
val internal_fact = value (fn Fact ths => ths); |
|
282 |
val internal_attribute = value (fn Attribute att => att); |
|
283 |
||
284 |
fun named_name intern = internal_name || named >> evaluate Name intern; |
|
285 |
fun named_typ readT = internal_typ || named >> evaluate Typ readT; |
|
286 |
fun named_term read = internal_term || named >> evaluate Term read; |
|
287 |
fun named_fact get = internal_fact || named >> evaluate Fact get; |
|
288 |
||
289 |
||
5878 | 290 |
(* terms and types *) |
291 |
||
15703 | 292 |
val global_typ_raw = Scan.peek (named_typ o ProofContext.read_typ_raw o ProofContext.init); |
293 |
val global_typ = Scan.peek (named_typ o ProofContext.read_typ o ProofContext.init); |
|
294 |
val global_term = Scan.peek (named_term o ProofContext.read_term o ProofContext.init); |
|
295 |
val global_prop = Scan.peek (named_term o ProofContext.read_prop o ProofContext.init); |
|
5878 | 296 |
|
15703 | 297 |
val local_typ_raw = Scan.peek (named_typ o ProofContext.read_typ_raw); |
298 |
val local_typ = Scan.peek (named_typ o ProofContext.read_typ); |
|
299 |
val local_term = Scan.peek (named_term o ProofContext.read_term); |
|
300 |
val local_prop = Scan.peek (named_term o ProofContext.read_prop); |
|
5878 | 301 |
|
302 |
||
15703 | 303 |
(* type and constant names *) |
304 |
||
305 |
val dest_tyname = fn Type (c, _) => c | TFree (a, _) => a | _ => ""; |
|
306 |
val dest_const = fn Const (c, _) => c | Free (x, _) => x | _ => ""; |
|
307 |
||
308 |
val global_tyname = Scan.peek (named_typ o Sign.read_tyname o Theory.sign_of) >> dest_tyname; |
|
309 |
val global_const = Scan.peek (named_term o Sign.read_const o Theory.sign_of) >> dest_const; |
|
310 |
val local_tyname = Scan.peek (named_typ o ProofContext.read_tyname) >> dest_tyname; |
|
311 |
val local_const = Scan.peek (named_term o ProofContext.read_const) >> dest_const; |
|
7553 | 312 |
|
15703 | 313 |
|
314 |
(* misc *) |
|
315 |
||
316 |
val thm_sel = parens (list1 |
|
317 |
(nat --| $$$ "-" -- nat >> PureThy.FromTo || |
|
318 |
nat --| $$$ "-" >> PureThy.From || |
|
319 |
nat >> PureThy.Single)); |
|
320 |
||
321 |
val bang_facts = Scan.peek (fn ctxt => |
|
322 |
$$$ "!" >> K (ProofContext.prems_of ctxt) || Scan.succeed []); |
|
7553 | 323 |
|
324 |
||
8536 | 325 |
(* goal specification *) |
326 |
||
327 |
(* range *) |
|
8233 | 328 |
|
8536 | 329 |
val from_to = |
15703 | 330 |
nat -- ($$$ "-" |-- nat) >> (fn (i, j) => fn tac => Seq.INTERVAL tac i j) || |
331 |
nat --| $$$ "-" >> (fn i => fn tac => fn st => Seq.INTERVAL tac i (Thm.nprems_of st) st) || |
|
8549 | 332 |
nat >> (fn i => fn tac => tac i) || |
15703 | 333 |
$$$ "!" >> K ALLGOALS; |
8536 | 334 |
|
15703 | 335 |
val goal = $$$ "[" |-- !!! (from_to --| $$$ "]"); |
8536 | 336 |
fun goal_spec def = Scan.lift (Scan.optional goal def); |
8233 | 337 |
|
338 |
||
15703 | 339 |
|
340 |
(* attribs *) |
|
341 |
||
342 |
local |
|
5878 | 343 |
|
9126 | 344 |
val exclude = explode "()[],"; |
5822
3f824514ad88
Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff
changeset
|
345 |
|
15703 | 346 |
fun atomic blk = touch (Scan.one (fn Arg ((k, x, _), _) => |
347 |
k <> Keyword orelse not (x mem exclude) orelse blk andalso x = ",")); |
|
5822
3f824514ad88
Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff
changeset
|
348 |
|
5878 | 349 |
fun args blk x = Scan.optional (args1 blk) [] x |
350 |
and args1 blk x = |
|
351 |
((Scan.repeat1 |
|
15703 | 352 |
(Scan.repeat1 (atomic blk) || |
353 |
argsp "(" ")" || |
|
354 |
argsp "[" "]")) >> List.concat) x |
|
355 |
and argsp l r x = |
|
356 |
(Scan.trace (&&& l -- !!! (args true -- &&& r)) >> #2) x; |
|
357 |
||
358 |
in |
|
5822
3f824514ad88
Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff
changeset
|
359 |
|
15703 | 360 |
fun attribs intern = |
361 |
let |
|
362 |
val attrib_name = internal_name || (symbolic || named) >> evaluate Name intern; |
|
363 |
val attrib = position (attrib_name -- !!! (args false)) >> src; |
|
364 |
in $$$ "[" |-- !!! (list attrib --| $$$ "]") end; |
|
365 |
||
366 |
fun opt_attribs intern = Scan.optional (attribs intern) []; |
|
367 |
||
368 |
end; |
|
5822
3f824514ad88
Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff
changeset
|
369 |
|
3f824514ad88
Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff
changeset
|
370 |
|
15703 | 371 |
(* syntax interface *) |
5822
3f824514ad88
Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff
changeset
|
372 |
|
8282 | 373 |
fun syntax kind scan (src as Src ((s, args), pos)) st = |
9901 | 374 |
(case Scan.error (Scan.finite' stopper (Scan.option scan)) (st, args) of |
15531 | 375 |
(SOME x, (st', [])) => (st', x) |
15703 | 376 |
| (_, (_, args')) => |
377 |
error (kind ^ " " ^ quote s ^ Position.str_of pos ^ ": bad arguments\n " ^ |
|
378 |
space_implode " " (map string_of args'))); |
|
379 |
||
5878 | 380 |
|
381 |
||
15703 | 382 |
(** pretty printing **) |
6447 | 383 |
|
15703 | 384 |
fun pretty_src ctxt src = |
385 |
let |
|
386 |
fun prt (Arg (_, Value (SOME (Name s)))) = Pretty.str (quote s) |
|
387 |
| prt (Arg (_, Value (SOME (Typ T)))) = ProofContext.pretty_typ ctxt T |
|
388 |
| prt (Arg (_, Value (SOME (Term t)))) = ProofContext.pretty_term ctxt t |
|
389 |
| prt (Arg (_, Value (SOME (Fact ths)))) = ProofContext.pretty_thms ctxt ths |
|
390 |
| prt arg = Pretty.str (string_of arg); |
|
391 |
val (s, args) = #1 (dest_src src); |
|
392 |
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
|
393 |
|
15703 | 394 |
fun pretty_attribs _ [] = [] |
395 |
| pretty_attribs ctxt srcs = |
|
396 |
[Pretty.enclose "[" "]" (Pretty.commas (map (pretty_src ctxt) srcs))]; |
|
5822
3f824514ad88
Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff
changeset
|
397 |
|
3f824514ad88
Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff
changeset
|
398 |
end; |