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