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