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