author | paulson |
Mon, 30 May 2011 16:15:37 +0100 | |
changeset 43078 | e2631aaf1e1e |
parent 42464 | ae16b8abf1a8 |
child 44357 | 5f5649ac8235 |
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 |
Author: Markus Wenzel, TU Muenchen |
3f824514ad88
Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff
changeset
|
3 |
|
35013 | 4 |
Parsing with implicit value assignment. Concrete argument syntax of |
27811 | 5 |
attributes, methods etc. |
5822
3f824514ad88
Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff
changeset
|
6 |
*) |
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 |
signature ARGS = |
3f824514ad88
Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff
changeset
|
9 |
sig |
15703 | 10 |
type src |
36959
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents:
36950
diff
changeset
|
11 |
val src: (string * Token.T list) * Position.T -> src |
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents:
36950
diff
changeset
|
12 |
val dest_src: src -> (string * Token.T list) * Position.T |
21030 | 13 |
val pretty_src: Proof.context -> src -> Pretty.T |
15703 | 14 |
val map_name: (string -> string) -> src -> src |
21480 | 15 |
val morph_values: morphism -> src -> src |
15703 | 16 |
val assignable: src -> src |
17 |
val closure: src -> src |
|
30513 | 18 |
val context: Proof.context context_parser |
19 |
val theory: theory context_parser |
|
20 |
val $$$ : string -> string parser |
|
21 |
val add: string parser |
|
22 |
val del: string parser |
|
23 |
val colon: string parser |
|
24 |
val query: string parser |
|
25 |
val bang: string parser |
|
26 |
val query_colon: string parser |
|
27 |
val bang_colon: string parser |
|
28 |
val parens: ('a parser) -> 'a parser |
|
29 |
val bracks: ('a parser) -> 'a parser |
|
30 |
val mode: string -> bool context_parser |
|
31 |
val maybe: 'a parser -> 'a option parser |
|
32 |
val name_source: string parser |
|
30573 | 33 |
val name_source_position: (Symbol_Pos.text * Position.T) parser |
30513 | 34 |
val name: string parser |
35 |
val binding: binding parser |
|
36 |
val alt_name: string parser |
|
37 |
val symbol: string parser |
|
38 |
val liberal_name: string parser |
|
39 |
val var: indexname parser |
|
40 |
val internal_text: string parser |
|
41 |
val internal_typ: typ parser |
|
42 |
val internal_term: term parser |
|
43 |
val internal_fact: thm list parser |
|
44 |
val internal_attribute: (morphism -> attribute) parser |
|
45 |
val named_text: (string -> string) -> string parser |
|
46 |
val named_typ: (string -> typ) -> typ parser |
|
47 |
val named_term: (string -> term) -> term parser |
|
48 |
val named_fact: (string -> thm list) -> thm list parser |
|
42464 | 49 |
val named_attribute: |
50 |
(string * Position.T -> morphism -> attribute) -> (morphism -> attribute) parser |
|
30513 | 51 |
val typ_abbrev: typ context_parser |
52 |
val typ: typ context_parser |
|
53 |
val term: term context_parser |
|
54 |
val term_abbrev: term context_parser |
|
55 |
val prop: term context_parser |
|
35360
df2b2168e43a
clarified ProofContext.read_type_name/Args.type_name wrt strict logical constructors;
wenzelm
parents:
35013
diff
changeset
|
56 |
val type_name: bool -> string context_parser |
35399
3881972fcfca
clarified ProofContext.read_const(_proper)/Args.const(_proper) wrt. strict logical consts;
wenzelm
parents:
35360
diff
changeset
|
57 |
val const: bool -> string context_parser |
3881972fcfca
clarified ProofContext.read_const(_proper)/Args.const(_proper) wrt. strict logical consts;
wenzelm
parents:
35360
diff
changeset
|
58 |
val const_proper: bool -> string context_parser |
30514 | 59 |
val goal_spec: ((int -> tactic) -> tactic) context_parser |
36959
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents:
36950
diff
changeset
|
60 |
val parse: Token.T list parser |
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents:
36950
diff
changeset
|
61 |
val parse1: (string -> bool) -> Token.T list parser |
30513 | 62 |
val attribs: (string -> string) -> src list parser |
63 |
val opt_attribs: (string -> string) -> src list parser |
|
64 |
val thm_name: (string -> string) -> string -> (binding * src list) parser |
|
65 |
val opt_thm_name: (string -> string) -> string -> (binding * src list) parser |
|
66 |
val syntax: string -> 'a context_parser -> src -> Context.generic -> 'a * Context.generic |
|
67 |
val context_syntax: string -> 'a context_parser -> src -> Proof.context -> 'a * Proof.context |
|
5822
3f824514ad88
Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff
changeset
|
68 |
end; |
3f824514ad88
Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff
changeset
|
69 |
|
3f824514ad88
Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff
changeset
|
70 |
structure Args: ARGS = |
3f824514ad88
Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff
changeset
|
71 |
struct |
3f824514ad88
Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff
changeset
|
72 |
|
15703 | 73 |
(** datatype src **) |
74 |
||
36959
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents:
36950
diff
changeset
|
75 |
datatype src = Src of (string * Token.T list) * Position.T; |
15703 | 76 |
|
77 |
val src = Src; |
|
78 |
fun dest_src (Src src) = src; |
|
79 |
||
21030 | 80 |
fun pretty_src ctxt src = |
81 |
let |
|
32091
30e2ffbba718
proper context for Display.pretty_thm etc. or old-style versions Display.pretty_thm_global, Display.pretty_thm_without_context etc.;
wenzelm
parents:
30573
diff
changeset
|
82 |
val prt_thm = Pretty.backquote o Display.pretty_thm ctxt; |
27811 | 83 |
fun prt arg = |
36959
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents:
36950
diff
changeset
|
84 |
(case Token.get_value arg of |
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents:
36950
diff
changeset
|
85 |
SOME (Token.Text s) => Pretty.str (quote s) |
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents:
36950
diff
changeset
|
86 |
| SOME (Token.Typ T) => Syntax.pretty_typ ctxt T |
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents:
36950
diff
changeset
|
87 |
| SOME (Token.Term t) => Syntax.pretty_term ctxt t |
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents:
36950
diff
changeset
|
88 |
| SOME (Token.Fact ths) => Pretty.enclose "(" ")" (Pretty.breaks (map prt_thm ths)) |
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents:
36950
diff
changeset
|
89 |
| _ => Pretty.str (Token.unparse arg)); |
21030 | 90 |
val (s, args) = #1 (dest_src src); |
91 |
in Pretty.block (Pretty.breaks (Pretty.str s :: map prt args)) end; |
|
92 |
||
15703 | 93 |
fun map_name f (Src ((s, args), pos)) = Src ((f s, args), pos); |
94 |
fun map_args f (Src ((s, args), pos)) = Src ((s, map f args), pos); |
|
95 |
||
96 |
||
97 |
(* values *) |
|
98 |
||
36959
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents:
36950
diff
changeset
|
99 |
fun morph_values phi = map_args (Token.map_value |
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents:
36950
diff
changeset
|
100 |
(fn Token.Text s => Token.Text s |
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents:
36950
diff
changeset
|
101 |
| Token.Typ T => Token.Typ (Morphism.typ phi T) |
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents:
36950
diff
changeset
|
102 |
| Token.Term t => Token.Term (Morphism.term phi t) |
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents:
36950
diff
changeset
|
103 |
| Token.Fact ths => Token.Fact (Morphism.fact phi ths) |
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents:
36950
diff
changeset
|
104 |
| Token.Attribute att => Token.Attribute (Morphism.transform phi att))); |
15703 | 105 |
|
36959
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents:
36950
diff
changeset
|
106 |
val assignable = map_args Token.assignable; |
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents:
36950
diff
changeset
|
107 |
val closure = map_args Token.closure; |
15703 | 108 |
|
109 |
||
110 |
||
27811 | 111 |
(** argument scanners **) |
5822
3f824514ad88
Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff
changeset
|
112 |
|
27371 | 113 |
(* context *) |
114 |
||
115 |
fun context x = (Scan.state >> Context.proof_of) x; |
|
116 |
fun theory x = (Scan.state >> Context.theory_of) x; |
|
117 |
||
118 |
||
27811 | 119 |
(* basic *) |
5878 | 120 |
|
36950 | 121 |
fun token atom = Scan.ahead Parse.not_eof --| atom; |
5878 | 122 |
|
27811 | 123 |
val ident = token |
36950 | 124 |
(Parse.short_ident || Parse.long_ident || Parse.sym_ident || Parse.term_var || |
125 |
Parse.type_ident || Parse.type_var || Parse.number); |
|
5878 | 126 |
|
36950 | 127 |
val string = token (Parse.string || Parse.verbatim); |
128 |
val alt_string = token Parse.alt_string; |
|
129 |
val symbolic = token Parse.keyword_ident_or_symbolic; |
|
27811 | 130 |
|
36959
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents:
36950
diff
changeset
|
131 |
fun $$$ x = (ident >> Token.content_of || Parse.keyword) |
27811 | 132 |
:|-- (fn y => if x = y then Scan.succeed x else Scan.fail); |
5878 | 133 |
|
134 |
||
27811 | 135 |
val named = ident || string; |
5878 | 136 |
|
10035 | 137 |
val add = $$$ "add"; |
138 |
val del = $$$ "del"; |
|
8803 | 139 |
val colon = $$$ ":"; |
10035 | 140 |
val query = $$$ "?"; |
141 |
val bang = $$$ "!"; |
|
20111 | 142 |
val query_colon = $$$ "?" ^^ $$$ ":"; |
143 |
val bang_colon = $$$ "!" ^^ $$$ ":"; |
|
10035 | 144 |
|
8803 | 145 |
fun parens scan = $$$ "(" |-- scan --| $$$ ")"; |
10150 | 146 |
fun bracks scan = $$$ "[" |-- scan --| $$$ "]"; |
15703 | 147 |
fun mode s = Scan.lift (Scan.optional (parens ($$$ s) >> K true) false); |
148 |
fun maybe scan = $$$ "_" >> K NONE || scan >> SOME; |
|
5878 | 149 |
|
36959
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents:
36950
diff
changeset
|
150 |
val name_source = named >> Token.source_of; |
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents:
36950
diff
changeset
|
151 |
val name_source_position = named >> Token.source_position_of; |
27882
eaa9fef9f4c1
Args.name_source(_position) for proper position information;
wenzelm
parents:
27819
diff
changeset
|
152 |
|
36959
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents:
36950
diff
changeset
|
153 |
val name = named >> Token.content_of; |
36950 | 154 |
val binding = Parse.position name >> Binding.make; |
36959
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents:
36950
diff
changeset
|
155 |
val alt_name = alt_string >> Token.content_of; |
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents:
36950
diff
changeset
|
156 |
val symbol = symbolic >> Token.content_of; |
17064 | 157 |
val liberal_name = symbol || name; |
8233 | 158 |
|
36959
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents:
36950
diff
changeset
|
159 |
val var = (ident >> Token.content_of) :|-- (fn x => |
27811 | 160 |
(case Lexicon.read_variable x of SOME v => Scan.succeed v | NONE => Scan.fail)); |
5878 | 161 |
|
5822
3f824514ad88
Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff
changeset
|
162 |
|
15703 | 163 |
(* values *) |
164 |
||
27811 | 165 |
fun value dest = Scan.some (fn arg => |
36959
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents:
36950
diff
changeset
|
166 |
(case Token.get_value arg of SOME v => (SOME (dest v) handle Match => NONE) | NONE => NONE)); |
15703 | 167 |
|
168 |
fun evaluate mk eval arg = |
|
36959
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents:
36950
diff
changeset
|
169 |
let val x = eval arg in (Token.assign (SOME (mk x)) arg; x) end; |
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents:
36950
diff
changeset
|
170 |
|
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents:
36950
diff
changeset
|
171 |
val internal_text = value (fn Token.Text s => s); |
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents:
36950
diff
changeset
|
172 |
val internal_typ = value (fn Token.Typ T => T); |
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents:
36950
diff
changeset
|
173 |
val internal_term = value (fn Token.Term t => t); |
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents:
36950
diff
changeset
|
174 |
val internal_fact = value (fn Token.Fact ths => ths); |
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents:
36950
diff
changeset
|
175 |
val internal_attribute = value (fn Token.Attribute att => att); |
15703 | 176 |
|
36959
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents:
36950
diff
changeset
|
177 |
fun named_text intern = internal_text || named >> evaluate Token.Text (intern o Token.content_of); |
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents:
36950
diff
changeset
|
178 |
fun named_typ readT = internal_typ || named >> evaluate Token.Typ (readT o Token.source_of); |
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents:
36950
diff
changeset
|
179 |
fun named_term read = internal_term || named >> evaluate Token.Term (read o Token.source_of); |
42464 | 180 |
|
36959
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents:
36950
diff
changeset
|
181 |
fun named_fact get = internal_fact || named >> evaluate Token.Fact (get o Token.content_of) || |
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents:
36950
diff
changeset
|
182 |
alt_string >> evaluate Token.Fact (get o Token.source_of); |
42464 | 183 |
|
36959
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents:
36950
diff
changeset
|
184 |
fun named_attribute att = |
42464 | 185 |
internal_attribute || |
186 |
named >> evaluate Token.Attribute (fn tok => att (Token.content_of tok, Token.position_of tok)); |
|
15703 | 187 |
|
188 |
||
5878 | 189 |
(* terms and types *) |
190 |
||
42360 | 191 |
val typ_abbrev = Scan.peek (named_typ o Proof_Context.read_typ_abbrev o Context.proof_of); |
25331 | 192 |
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
|
193 |
val term = Scan.peek (named_term o Syntax.read_term o Context.proof_of); |
42360 | 194 |
val term_abbrev = Scan.peek (named_term o Proof_Context.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
|
195 |
val prop = Scan.peek (named_term o Syntax.read_prop o Context.proof_of); |
18635 | 196 |
|
5878 | 197 |
|
15703 | 198 |
(* type and constant names *) |
199 |
||
35360
df2b2168e43a
clarified ProofContext.read_type_name/Args.type_name wrt strict logical constructors;
wenzelm
parents:
35013
diff
changeset
|
200 |
fun type_name strict = |
42360 | 201 |
Scan.peek (fn ctxt => named_typ (Proof_Context.read_type_name (Context.proof_of ctxt) strict)) |
18998 | 202 |
>> (fn Type (c, _) => c | TFree (a, _) => a | _ => ""); |
15703 | 203 |
|
35399
3881972fcfca
clarified ProofContext.read_const(_proper)/Args.const(_proper) wrt. strict logical consts;
wenzelm
parents:
35360
diff
changeset
|
204 |
fun const strict = |
42360 | 205 |
Scan.peek (fn ctxt => named_term (Proof_Context.read_const (Context.proof_of ctxt) strict dummyT)) |
18998 | 206 |
>> (fn Const (c, _) => c | Free (x, _) => x | _ => ""); |
7553 | 207 |
|
35399
3881972fcfca
clarified ProofContext.read_const(_proper)/Args.const(_proper) wrt. strict logical consts;
wenzelm
parents:
35360
diff
changeset
|
208 |
fun const_proper strict = |
42360 | 209 |
Scan.peek (fn ctxt => named_term (Proof_Context.read_const_proper (Context.proof_of ctxt) strict)) |
25343 | 210 |
>> (fn Const (c, _) => c | _ => ""); |
211 |
||
15703 | 212 |
|
27811 | 213 |
(* improper method arguments *) |
15703 | 214 |
|
8536 | 215 |
val from_to = |
36950 | 216 |
Parse.nat -- ($$$ "-" |-- Parse.nat) >> (fn (i, j) => fn tac => Seq.INTERVAL tac i j) || |
217 |
Parse.nat --| $$$ "-" >> (fn i => fn tac => fn st => Seq.INTERVAL tac i (Thm.nprems_of st) st) || |
|
218 |
Parse.nat >> (fn i => fn tac => tac i) || |
|
15703 | 219 |
$$$ "!" >> K ALLGOALS; |
8536 | 220 |
|
36950 | 221 |
val goal = $$$ "[" |-- Parse.!!! (from_to --| $$$ "]"); |
30514 | 222 |
fun goal_spec x = Scan.lift (Scan.optional goal (fn tac => tac 1)) x; |
8233 | 223 |
|
224 |
||
27811 | 225 |
(* arguments within outer syntax *) |
5878 | 226 |
|
27382 | 227 |
fun parse_args is_symid = |
228 |
let |
|
36950 | 229 |
val keyword_symid = token (Parse.keyword_with is_symid); |
230 |
fun atom blk = Parse.group "argument" |
|
40291 | 231 |
(ident || keyword_symid || string || alt_string || token Parse.float_number || |
36950 | 232 |
(if blk then token (Parse.$$$ ",") else Scan.fail)); |
5822
3f824514ad88
Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff
changeset
|
233 |
|
27382 | 234 |
fun args blk x = Scan.optional (args1 blk) [] x |
235 |
and args1 blk x = |
|
236 |
((Scan.repeat1 |
|
237 |
(Scan.repeat1 (atom blk) || |
|
238 |
argsp "(" ")" || |
|
239 |
argsp "[" "]")) >> flat) x |
|
36950 | 240 |
and argsp l r x = |
241 |
(token (Parse.$$$ l) ::: Parse.!!! (args true @@@ (token (Parse.$$$ r) >> single))) x; |
|
27382 | 242 |
in (args, args1) end; |
15703 | 243 |
|
36959
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents:
36950
diff
changeset
|
244 |
val parse = #1 (parse_args Token.ident_or_symbolic) false; |
27811 | 245 |
fun parse1 is_symid = #2 (parse_args is_symid) false; |
5822
3f824514ad88
Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff
changeset
|
246 |
|
27811 | 247 |
|
248 |
(* attributes *) |
|
27382 | 249 |
|
15703 | 250 |
fun attribs intern = |
251 |
let |
|
27819 | 252 |
val attrib_name = internal_text || (symbolic || named) |
36959
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents:
36950
diff
changeset
|
253 |
>> evaluate Token.Text (intern o Token.content_of); |
36950 | 254 |
val attrib = Parse.position (attrib_name -- Parse.!!! parse) >> src; |
255 |
in $$$ "[" |-- Parse.!!! (Parse.list attrib --| $$$ "]") end; |
|
15703 | 256 |
|
257 |
fun opt_attribs intern = Scan.optional (attribs intern) []; |
|
258 |
||
5822
3f824514ad88
Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff
changeset
|
259 |
|
27377 | 260 |
(* theorem specifications *) |
261 |
||
28078 | 262 |
fun thm_name intern s = binding -- opt_attribs intern --| $$$ s; |
27811 | 263 |
|
27377 | 264 |
fun opt_thm_name intern s = |
28078 | 265 |
Scan.optional |
28965 | 266 |
((binding -- opt_attribs intern || attribs intern >> pair Binding.empty) --| $$$ s) |
267 |
(Binding.empty, []); |
|
27377 | 268 |
|
269 |
||
27382 | 270 |
|
271 |
(** syntax wrapper **) |
|
5822
3f824514ad88
Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff
changeset
|
272 |
|
32784 | 273 |
fun syntax kind scan (Src ((s, args), pos)) st = |
36959
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents:
36950
diff
changeset
|
274 |
(case Scan.error (Scan.finite' Token.stopper (Scan.option scan)) (st, args) of |
21879 | 275 |
(SOME x, (st', [])) => (x, st') |
15703 | 276 |
| (_, (_, args')) => |
277 |
error (kind ^ " " ^ quote s ^ Position.str_of pos ^ ": bad arguments\n " ^ |
|
36959
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents:
36950
diff
changeset
|
278 |
space_implode " " (map Token.unparse args'))); |
15703 | 279 |
|
21879 | 280 |
fun context_syntax kind scan src = apsnd Context.the_proof o syntax kind scan src o Context.Proof; |
18998 | 281 |
|
5822
3f824514ad88
Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff
changeset
|
282 |
end; |