author | wenzelm |
Mon, 07 May 2007 00:49:59 +0200 | |
changeset 22846 | fb79144af9a3 |
parent 22669 | 62857ad97cca |
child 22932 | 53005f898665 |
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 |
5822
3f824514ad88
Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff
changeset
|
25 |
val stopper: T * (T -> bool) |
3f824514ad88
Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff
changeset
|
26 |
val not_eof: T -> bool |
15703 | 27 |
type src |
28 |
val src: (string * T list) * Position.T -> src |
|
29 |
val dest_src: src -> (string * T list) * Position.T |
|
21030 | 30 |
val pretty_src: Proof.context -> src -> Pretty.T |
15703 | 31 |
val map_name: (string -> string) -> src -> src |
21480 | 32 |
val morph_values: morphism -> src -> src |
20263 | 33 |
val maxidx_values: src -> int -> int |
15703 | 34 |
val assignable: src -> src |
35 |
val assign: value option -> T -> unit |
|
36 |
val closure: src -> src |
|
5878 | 37 |
val position: (T list -> 'a * 'b) -> T list -> ('a * Position.T) * 'b |
38 |
val !!! : (T list -> 'a) -> T list -> 'a |
|
5822
3f824514ad88
Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff
changeset
|
39 |
val $$$ : string -> T list -> string * T list |
10035 | 40 |
val add: T list -> string * T list |
41 |
val del: T list -> string * T list |
|
8803 | 42 |
val colon: T list -> string * T list |
10035 | 43 |
val query: T list -> string * T list |
44 |
val bang: T list -> string * T list |
|
45 |
val query_colon: T list -> string * T list |
|
46 |
val bang_colon: T list -> string * T list |
|
8803 | 47 |
val parens: (T list -> 'a * T list) -> T list -> 'a * T list |
10150 | 48 |
val bracks: (T list -> 'a * T list) -> T list -> 'a * T list |
9809 | 49 |
val mode: string -> 'a * T list -> bool * ('a * T list) |
15703 | 50 |
val maybe: (T list -> 'a * T list) -> T list -> 'a option * T list |
5822
3f824514ad88
Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff
changeset
|
51 |
val name: T list -> string * T list |
18037 | 52 |
val alt_name: T list -> string * T list |
16140 | 53 |
val symbol: T list -> string * T list |
17064 | 54 |
val liberal_name: T list -> string * T list |
5878 | 55 |
val nat: T list -> int * T list |
9538 | 56 |
val int: T list -> int * T list |
5878 | 57 |
val var: T list -> indexname * T list |
15703 | 58 |
val list: (T list -> 'a * T list) -> T list -> 'a list * T list |
59 |
val list1: (T list -> 'a * T list) -> T list -> 'a list * T list |
|
6447 | 60 |
val enum: string -> ('a * T list -> 'b * ('a * T list)) -> 'a * T list -> 'b list * ('a * T list) |
61 |
val enum1: string -> ('a * T list -> 'b * ('a * T list)) -> 'a * T list -> 'b list * ('a * T list) |
|
62 |
val and_list: ('a * T list -> 'b * ('a * T list)) -> 'a * T list -> 'b list * ('a * T list) |
|
63 |
val and_list1: ('a * T list -> 'b * ('a * T list)) -> 'a * T list -> 'b list * ('a * T list) |
|
15703 | 64 |
val ahead: T list -> T * T list |
21496
a3ac0c55393f
renamed Name value to Text, which is *not* a name in terms of morphisms;
wenzelm
parents:
21480
diff
changeset
|
65 |
val internal_text: T list -> string * T list |
15703 | 66 |
val internal_typ: T list -> typ * T list |
67 |
val internal_term: T list -> term * T list |
|
68 |
val internal_fact: T list -> thm list * T list |
|
21662 | 69 |
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
|
70 |
val named_text: (string -> string) -> T list -> string * T list |
15703 | 71 |
val named_typ: (string -> typ) -> T list -> typ * T list |
72 |
val named_term: (string -> term) -> T list -> term * T list |
|
73 |
val named_fact: (string -> thm list) -> T list -> thm list * T list |
|
18635 | 74 |
val typ_abbrev: Context.generic * T list -> typ * (Context.generic * T list) |
75 |
val typ: Context.generic * T list -> typ * (Context.generic * T list) |
|
76 |
val term: Context.generic * T list -> term * (Context.generic * T list) |
|
21724 | 77 |
val term_abbrev: Context.generic * T list -> term * (Context.generic * T list) |
18635 | 78 |
val prop: Context.generic * T list -> term * (Context.generic * T list) |
79 |
val tyname: Context.generic * T list -> string * (Context.generic * T list) |
|
80 |
val const: Context.generic * T list -> string * (Context.generic * T list) |
|
15703 | 81 |
val thm_sel: T list -> PureThy.interval list * T list |
18998 | 82 |
val bang_facts: Context.generic * T list -> thm list * (Context.generic * 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 |
|
21879 | 87 |
val syntax: string -> ('b * T list -> 'a * ('b * T list)) -> src -> 'b -> 'a * 'b |
18998 | 88 |
val context_syntax: string -> (Context.generic * T list -> 'a * (Context.generic * T list)) -> |
21879 | 89 |
src -> Proof.context -> 'a * Proof.context |
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 = |
21496
a3ac0c55393f
renamed Name value to Text, which is *not* a name in terms of morphisms;
wenzelm
parents:
21480
diff
changeset
|
108 |
Text of string | |
15703 | 109 |
Typ of typ | |
110 |
Term of term | |
|
111 |
Fact of thm list | |
|
21662 | 112 |
Attribute of morphism -> 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; |
21496
a3ac0c55393f
renamed Name value to Text, which is *not* a name in terms of morphisms;
wenzelm
parents:
21480
diff
changeset
|
140 |
val mk_text = mk_value "<text>" o Text; |
15703 | 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 |
||
21030 | 166 |
fun pretty_src ctxt src = |
167 |
let |
|
21697 | 168 |
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
|
169 |
fun prt (Arg (_, Value (SOME (Text s)))) = Pretty.str (quote s) |
21030 | 170 |
| prt (Arg (_, Value (SOME (Typ T)))) = ProofContext.pretty_typ ctxt T |
171 |
| prt (Arg (_, Value (SOME (Term t)))) = ProofContext.pretty_term ctxt t |
|
21697 | 172 |
| prt (Arg (_, Value (SOME (Fact ths)))) = |
173 |
Pretty.enclose "(" ")" (Pretty.breaks (map prt_thm ths)) |
|
21030 | 174 |
| prt arg = Pretty.str (string_of arg); |
175 |
val (s, args) = #1 (dest_src src); |
|
176 |
in Pretty.block (Pretty.breaks (Pretty.str s :: map prt args)) end; |
|
177 |
||
15703 | 178 |
fun map_name f (Src ((s, args), pos)) = Src ((f s, args), pos); |
179 |
fun map_args f (Src ((s, args), pos)) = Src ((s, map f args), pos); |
|
180 |
||
181 |
||
182 |
(* values *) |
|
183 |
||
184 |
fun map_value f (Arg (s, Value (SOME v))) = Arg (s, Value (SOME (f v))) |
|
185 |
| map_value _ arg = arg; |
|
186 |
||
21480 | 187 |
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
|
188 |
(fn Text s => Text s |
21480 | 189 |
| Typ T => Typ (Morphism.typ phi T) |
190 |
| Term t => Term (Morphism.term phi t) |
|
21976 | 191 |
| Fact ths => Fact (Morphism.fact phi ths) |
22669 | 192 |
| Attribute att => Attribute (Morphism.transform phi att))); |
15703 | 193 |
|
20263 | 194 |
fun maxidx_values (Src ((_, args), _)) = args |> fold |
195 |
(fn (Arg (_, Value (SOME (Typ T)))) => Term.maxidx_typ T |
|
196 |
| (Arg (_, Value (SOME (Term t)))) => Term.maxidx_term t |
|
197 |
| (Arg (_, Value (SOME (Fact ths)))) => fold Thm.maxidx_thm ths |
|
198 |
| _ => I); |
|
199 |
||
15703 | 200 |
|
201 |
(* static binding *) |
|
202 |
||
203 |
(*1st stage: make empty slots assignable*) |
|
204 |
val assignable = |
|
205 |
map_args (fn Arg (s, Empty) => Arg (s, Assignable (ref NONE)) | arg => arg); |
|
206 |
||
207 |
(*2nd stage: assign values as side-effect of scanning*) |
|
208 |
fun assign v (arg as Arg (_, Assignable r)) = r := v |
|
209 |
| assign _ _ = (); |
|
210 |
||
211 |
val ahead = Scan.ahead (Scan.one not_eof); |
|
212 |
fun touch scan = ahead -- scan >> (fn (arg, y) => (assign NONE arg; y)); |
|
213 |
||
214 |
(*3rd stage: static closure of final values*) |
|
215 |
val closure = |
|
216 |
map_args (fn Arg (s, Assignable (ref v)) => Arg (s, Value v) | arg => arg); |
|
217 |
||
218 |
||
219 |
||
5822
3f824514ad88
Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff
changeset
|
220 |
(** scanners **) |
3f824514ad88
Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff
changeset
|
221 |
|
5878 | 222 |
(* position *) |
223 |
||
15703 | 224 |
fun position scan = |
225 |
(Scan.ahead (Scan.one not_eof) >> pos_of) -- scan >> Library.swap; |
|
5878 | 226 |
|
227 |
||
228 |
(* cut *) |
|
229 |
||
230 |
fun !!! scan = |
|
231 |
let |
|
232 |
fun get_pos [] = " (past end-of-text!)" |
|
15703 | 233 |
| get_pos (arg :: _) = Position.str_of (pos_of arg); |
5878 | 234 |
|
15531 | 235 |
fun err (args, NONE) = "Argument syntax error" ^ get_pos args |
236 |
| err (args, SOME msg) = "Argument syntax error" ^ get_pos args ^ ": " ^ msg; |
|
5878 | 237 |
in Scan.!! err scan end; |
238 |
||
239 |
||
5822
3f824514ad88
Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff
changeset
|
240 |
(* basic *) |
3f824514ad88
Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff
changeset
|
241 |
|
15703 | 242 |
fun some_ident f = |
243 |
touch (Scan.some (fn Arg ((Ident, x, _), _) => f x | _ => NONE)); |
|
244 |
||
245 |
val named = |
|
246 |
touch (Scan.one (fn Arg ((k, _, _), _) => k = Ident orelse k = String)); |
|
247 |
||
18037 | 248 |
val alt_string = |
249 |
touch (Scan.one (fn Arg ((k, _, _), _) => k = AltString)); |
|
250 |
||
15703 | 251 |
val symbolic = |
252 |
touch (Scan.one (fn Arg ((k, x, _), _) => k = Keyword andalso OuterLex.is_sid x)); |
|
253 |
||
254 |
fun &&& x = |
|
255 |
touch (Scan.one (fn Arg ((k, y, _), _) => k = Keyword andalso x = y)); |
|
256 |
||
257 |
fun $$$ x = |
|
16140 | 258 |
touch (Scan.one (fn Arg ((k, y, _), _) => (k = Ident orelse k = Keyword) andalso x = y)) |
259 |
>> sym_of; |
|
5878 | 260 |
|
10035 | 261 |
val add = $$$ "add"; |
262 |
val del = $$$ "del"; |
|
8803 | 263 |
val colon = $$$ ":"; |
10035 | 264 |
val query = $$$ "?"; |
265 |
val bang = $$$ "!"; |
|
20111 | 266 |
val query_colon = $$$ "?" ^^ $$$ ":"; |
267 |
val bang_colon = $$$ "!" ^^ $$$ ":"; |
|
10035 | 268 |
|
8803 | 269 |
fun parens scan = $$$ "(" |-- scan --| $$$ ")"; |
10150 | 270 |
fun bracks scan = $$$ "[" |-- scan --| $$$ "]"; |
15703 | 271 |
fun mode s = Scan.lift (Scan.optional (parens ($$$ s) >> K true) false); |
272 |
fun maybe scan = $$$ "_" >> K NONE || scan >> SOME; |
|
5878 | 273 |
|
15703 | 274 |
val name = named >> sym_of; |
18037 | 275 |
val alt_name = alt_string >> sym_of; |
16140 | 276 |
val symbol = symbolic >> sym_of; |
17064 | 277 |
val liberal_name = symbol || name; |
8233 | 278 |
|
15703 | 279 |
val nat = some_ident Syntax.read_nat; |
9538 | 280 |
val int = Scan.optional ($$$ "-" >> K ~1) 1 -- nat >> op *; |
15987 | 281 |
val var = some_ident Syntax.read_variable; |
14563 | 282 |
|
5822
3f824514ad88
Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff
changeset
|
283 |
|
5878 | 284 |
(* enumerations *) |
285 |
||
15703 | 286 |
fun list1 scan = scan -- Scan.repeat ($$$ "," |-- scan) >> op ::; |
287 |
fun list scan = list1 scan || Scan.succeed []; |
|
288 |
||
6447 | 289 |
fun enum1 sep scan = scan -- Scan.repeat (Scan.lift ($$$ sep) |-- scan) >> op ::; |
5878 | 290 |
fun enum sep scan = enum1 sep scan || Scan.succeed []; |
291 |
||
6447 | 292 |
fun and_list1 scan = enum1 "and" scan; |
293 |
fun and_list scan = enum "and" scan; |
|
5878 | 294 |
|
5822
3f824514ad88
Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff
changeset
|
295 |
|
15703 | 296 |
(* values *) |
297 |
||
298 |
fun value dest = Scan.some (*no touch here*) |
|
299 |
(fn Arg (_, Value (SOME v)) => (SOME (dest v) handle Match => NONE) |
|
300 |
| Arg _ => NONE); |
|
301 |
||
302 |
fun evaluate mk eval arg = |
|
303 |
let val x = eval (sym_of arg) in (assign (SOME (mk x)) arg; x) end; |
|
304 |
||
21496
a3ac0c55393f
renamed Name value to Text, which is *not* a name in terms of morphisms;
wenzelm
parents:
21480
diff
changeset
|
305 |
val internal_text = value (fn Text s => s); |
15703 | 306 |
val internal_typ = value (fn Typ T => T); |
307 |
val internal_term = value (fn Term t => t); |
|
308 |
val internal_fact = value (fn Fact ths => ths); |
|
309 |
val internal_attribute = value (fn Attribute att => att); |
|
310 |
||
21496
a3ac0c55393f
renamed Name value to Text, which is *not* a name in terms of morphisms;
wenzelm
parents:
21480
diff
changeset
|
311 |
fun named_text intern = internal_text || named >> evaluate Text intern; |
15703 | 312 |
fun named_typ readT = internal_typ || named >> evaluate Typ readT; |
313 |
fun named_term read = internal_term || named >> evaluate Term read; |
|
18037 | 314 |
fun named_fact get = internal_fact || (alt_string || named) >> evaluate Fact get; |
15703 | 315 |
|
316 |
||
5878 | 317 |
(* terms and types *) |
318 |
||
18635 | 319 |
val typ_abbrev = Scan.peek (named_typ o ProofContext.read_typ_abbrev o Context.proof_of); |
320 |
val typ = Scan.peek (named_typ o ProofContext.read_typ o Context.proof_of); |
|
321 |
val term = Scan.peek (named_term o ProofContext.read_term o Context.proof_of); |
|
21724 | 322 |
val term_abbrev = Scan.peek (named_term o ProofContext.read_term_abbrev o Context.proof_of); |
18635 | 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 |
||
18998 | 328 |
val tyname = Scan.peek (named_typ o Context.cases Sign.read_tyname ProofContext.read_tyname) |
329 |
>> (fn Type (c, _) => c | TFree (a, _) => a | _ => ""); |
|
15703 | 330 |
|
18998 | 331 |
val const = Scan.peek (named_term o Context.cases Sign.read_const ProofContext.read_const) |
332 |
>> (fn Const (c, _) => c | Free (x, _) => x | _ => ""); |
|
7553 | 333 |
|
15703 | 334 |
|
335 |
(* misc *) |
|
336 |
||
337 |
val thm_sel = parens (list1 |
|
338 |
(nat --| $$$ "-" -- nat >> PureThy.FromTo || |
|
339 |
nat --| $$$ "-" >> PureThy.From || |
|
340 |
nat >> PureThy.Single)); |
|
341 |
||
18998 | 342 |
val bang_facts = Scan.peek (fn context => |
20224
9c40a144ee0e
moved basic assumption operations from structure ProofContext to Assumption;
wenzelm
parents:
20111
diff
changeset
|
343 |
$$$ "!" >> K (Assumption.prems_of (Context.proof_of context)) || Scan.succeed []); |
7553 | 344 |
|
345 |
||
8536 | 346 |
(* goal specification *) |
347 |
||
348 |
(* range *) |
|
8233 | 349 |
|
8536 | 350 |
val from_to = |
15703 | 351 |
nat -- ($$$ "-" |-- nat) >> (fn (i, j) => fn tac => Seq.INTERVAL tac i j) || |
352 |
nat --| $$$ "-" >> (fn i => fn tac => fn st => Seq.INTERVAL tac i (Thm.nprems_of st) st) || |
|
8549 | 353 |
nat >> (fn i => fn tac => tac i) || |
15703 | 354 |
$$$ "!" >> K ALLGOALS; |
8536 | 355 |
|
15703 | 356 |
val goal = $$$ "[" |-- !!! (from_to --| $$$ "]"); |
8536 | 357 |
fun goal_spec def = Scan.lift (Scan.optional goal def); |
8233 | 358 |
|
359 |
||
15703 | 360 |
|
361 |
(* attribs *) |
|
362 |
||
363 |
local |
|
5878 | 364 |
|
20664 | 365 |
val exclude = member (op =) (explode "()[],"); |
5822
3f824514ad88
Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff
changeset
|
366 |
|
15703 | 367 |
fun atomic blk = touch (Scan.one (fn Arg ((k, x, _), _) => |
20664 | 368 |
k <> Keyword orelse not (exclude x) orelse blk andalso x = ",")); |
5822
3f824514ad88
Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff
changeset
|
369 |
|
5878 | 370 |
fun args blk x = Scan.optional (args1 blk) [] x |
371 |
and args1 blk x = |
|
372 |
((Scan.repeat1 |
|
15703 | 373 |
(Scan.repeat1 (atomic blk) || |
374 |
argsp "(" ")" || |
|
19482
9f11af8f7ef9
tuned basic list operators (flat, maps, map_filter);
wenzelm
parents:
18998
diff
changeset
|
375 |
argsp "[" "]")) >> flat) x |
15703 | 376 |
and argsp l r x = |
377 |
(Scan.trace (&&& l -- !!! (args true -- &&& r)) >> #2) x; |
|
378 |
||
379 |
in |
|
5822
3f824514ad88
Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff
changeset
|
380 |
|
15703 | 381 |
fun attribs intern = |
382 |
let |
|
21496
a3ac0c55393f
renamed Name value to Text, which is *not* a name in terms of morphisms;
wenzelm
parents:
21480
diff
changeset
|
383 |
val attrib_name = internal_text || (symbolic || named) >> evaluate Text intern; |
15703 | 384 |
val attrib = position (attrib_name -- !!! (args false)) >> src; |
385 |
in $$$ "[" |-- !!! (list attrib --| $$$ "]") end; |
|
386 |
||
387 |
fun opt_attribs intern = Scan.optional (attribs intern) []; |
|
388 |
||
389 |
end; |
|
5822
3f824514ad88
Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff
changeset
|
390 |
|
3f824514ad88
Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff
changeset
|
391 |
|
15703 | 392 |
(* syntax interface *) |
5822
3f824514ad88
Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff
changeset
|
393 |
|
8282 | 394 |
fun syntax kind scan (src as Src ((s, args), pos)) st = |
9901 | 395 |
(case Scan.error (Scan.finite' stopper (Scan.option scan)) (st, args) of |
21879 | 396 |
(SOME x, (st', [])) => (x, st') |
15703 | 397 |
| (_, (_, args')) => |
398 |
error (kind ^ " " ^ quote s ^ Position.str_of pos ^ ": bad arguments\n " ^ |
|
399 |
space_implode " " (map string_of args'))); |
|
400 |
||
21879 | 401 |
fun context_syntax kind scan src = apsnd Context.the_proof o syntax kind scan src o Context.Proof; |
18998 | 402 |
|
5822
3f824514ad88
Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff
changeset
|
403 |
end; |