author | wenzelm |
Mon, 10 Mar 2014 15:20:41 +0100 | |
changeset 56027 | 25889f5c39a8 |
parent 56002 | 2028467b4df4 |
child 56028 | 422024102d9d |
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 |
56027
25889f5c39a8
prefer Name_Space.pretty with its builtin markup;
wenzelm
parents:
56002
diff
changeset
|
13 |
val pretty_src: (string -> Pretty.T) -> Proof.context -> src -> Pretty.T |
15703 | 14 |
val map_name: (string -> string) -> src -> src |
45290 | 15 |
val transform_values: morphism -> src -> src |
55914
c5b752d549e3
clarified init_assignable: make double-sure that initial values are reset;
wenzelm
parents:
55828
diff
changeset
|
16 |
val init_assignable: src -> src |
15703 | 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 |
55828
42ac3cfb89f6
clarified language markup: added "delimited" property;
wenzelm
parents:
55745
diff
changeset
|
33 |
val cartouche_source_position: Symbol_Pos.source parser |
55111 | 34 |
val name_inner_syntax: string parser |
55828
42ac3cfb89f6
clarified language markup: added "delimited" property;
wenzelm
parents:
55745
diff
changeset
|
35 |
val name_source_position: Symbol_Pos.source 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 |
|
55951
c07d184aebe9
tuned signature -- more uniform check_type_name/read_type_name;
wenzelm
parents:
55915
diff
changeset
|
59 |
val type_name: {proper: bool, strict: bool} -> string context_parser |
55954 | 60 |
val const: {proper: bool, strict: bool} -> string context_parser |
30514 | 61 |
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
|
62 |
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
|
63 |
val parse1: (string -> bool) -> Token.T list parser |
55997
9dc5ce83202c
modernized Attrib.check_name/check_src similar to methods (see also a989bdaf8121);
wenzelm
parents:
55956
diff
changeset
|
64 |
val attribs: (xstring * Position.T -> string) -> src list parser |
9dc5ce83202c
modernized Attrib.check_name/check_src similar to methods (see also a989bdaf8121);
wenzelm
parents:
55956
diff
changeset
|
65 |
val opt_attribs: (xstring * Position.T -> string) -> src list parser |
9dc5ce83202c
modernized Attrib.check_name/check_src similar to methods (see also a989bdaf8121);
wenzelm
parents:
55956
diff
changeset
|
66 |
val thm_name: (xstring * Position.T -> string) -> string -> (binding * src list) parser |
9dc5ce83202c
modernized Attrib.check_name/check_src similar to methods (see also a989bdaf8121);
wenzelm
parents:
55956
diff
changeset
|
67 |
val opt_thm_name: (xstring * Position.T -> string) -> string -> (binding * src list) parser |
30513 | 68 |
val syntax: string -> 'a context_parser -> src -> Context.generic -> 'a * Context.generic |
69 |
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
|
70 |
end; |
3f824514ad88
Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff
changeset
|
71 |
|
3f824514ad88
Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff
changeset
|
72 |
structure Args: ARGS = |
3f824514ad88
Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff
changeset
|
73 |
struct |
3f824514ad88
Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff
changeset
|
74 |
|
15703 | 75 |
(** datatype src **) |
76 |
||
36959
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents:
36950
diff
changeset
|
77 |
datatype src = Src of (string * Token.T list) * Position.T; |
15703 | 78 |
|
79 |
val src = Src; |
|
80 |
fun dest_src (Src src) = src; |
|
81 |
||
56027
25889f5c39a8
prefer Name_Space.pretty with its builtin markup;
wenzelm
parents:
56002
diff
changeset
|
82 |
fun pretty_src pretty_name ctxt src = |
21030 | 83 |
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
|
84 |
val prt_thm = Pretty.backquote o Display.pretty_thm ctxt; |
27811 | 85 |
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
|
86 |
(case Token.get_value arg of |
55915
607948c90bf0
suppress short abbreviations more uniformly, for outer and quasi-outer syntax;
wenzelm
parents:
55914
diff
changeset
|
87 |
SOME (v as Token.Literal s) => Pretty.marks_str (Token.value_markup v, s) |
55914
c5b752d549e3
clarified init_assignable: make double-sure that initial values are reset;
wenzelm
parents:
55828
diff
changeset
|
88 |
| SOME (Token.Text s) => Pretty.str (quote s) |
36959
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)) |
55915
607948c90bf0
suppress short abbreviations more uniformly, for outer and quasi-outer syntax;
wenzelm
parents:
55914
diff
changeset
|
92 |
| _ => Pretty.mark_str (Token.markup arg, Token.unparse arg)); |
56027
25889f5c39a8
prefer Name_Space.pretty with its builtin markup;
wenzelm
parents:
56002
diff
changeset
|
93 |
val (name, args) = #1 (dest_src src); |
25889f5c39a8
prefer Name_Space.pretty with its builtin markup;
wenzelm
parents:
56002
diff
changeset
|
94 |
in Pretty.block (Pretty.breaks (pretty_name name :: map prt args)) end; |
21030 | 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 |
55914
c5b752d549e3
clarified init_assignable: make double-sure that initial values are reset;
wenzelm
parents:
55828
diff
changeset
|
103 |
(fn Token.Typ T => Token.Typ (Morphism.typ phi T) |
36959
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.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
|
105 |
| Token.Fact ths => Token.Fact (Morphism.fact phi ths) |
53112 | 106 |
| Token.Attribute att => Token.Attribute (Morphism.transform phi att) |
55914
c5b752d549e3
clarified init_assignable: make double-sure that initial values are reset;
wenzelm
parents:
55828
diff
changeset
|
107 |
| tok => tok)); |
15703 | 108 |
|
55914
c5b752d549e3
clarified init_assignable: make double-sure that initial values are reset;
wenzelm
parents:
55828
diff
changeset
|
109 |
val init_assignable = map_args Token.init_assignable; |
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 closure = map_args Token.closure; |
15703 | 111 |
|
112 |
||
113 |
||
27811 | 114 |
(** argument scanners **) |
5822
3f824514ad88
Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff
changeset
|
115 |
|
27371 | 116 |
(* context *) |
117 |
||
118 |
fun context x = (Scan.state >> Context.proof_of) x; |
|
119 |
fun theory x = (Scan.state >> Context.theory_of) x; |
|
120 |
||
121 |
||
27811 | 122 |
(* basic *) |
5878 | 123 |
|
36950 | 124 |
fun token atom = Scan.ahead Parse.not_eof --| atom; |
5878 | 125 |
|
27811 | 126 |
val ident = token |
36950 | 127 |
(Parse.short_ident || Parse.long_ident || Parse.sym_ident || Parse.term_var || |
128 |
Parse.type_ident || Parse.type_var || Parse.number); |
|
5878 | 129 |
|
36950 | 130 |
val string = token (Parse.string || Parse.verbatim); |
131 |
val alt_string = token Parse.alt_string; |
|
132 |
val symbolic = token Parse.keyword_ident_or_symbolic; |
|
27811 | 133 |
|
55914
c5b752d549e3
clarified init_assignable: make double-sure that initial values are reset;
wenzelm
parents:
55828
diff
changeset
|
134 |
fun $$$ x = |
c5b752d549e3
clarified init_assignable: make double-sure that initial values are reset;
wenzelm
parents:
55828
diff
changeset
|
135 |
(ident || token Parse.keyword) :|-- (fn tok => |
c5b752d549e3
clarified init_assignable: make double-sure that initial values are reset;
wenzelm
parents:
55828
diff
changeset
|
136 |
let val y = Token.content_of tok |
c5b752d549e3
clarified init_assignable: make double-sure that initial values are reset;
wenzelm
parents:
55828
diff
changeset
|
137 |
in if x = y then (Token.assign (SOME (Token.Literal x)) tok; Scan.succeed x) else Scan.fail end); |
5878 | 138 |
|
139 |
||
27811 | 140 |
val named = ident || string; |
5878 | 141 |
|
10035 | 142 |
val add = $$$ "add"; |
143 |
val del = $$$ "del"; |
|
8803 | 144 |
val colon = $$$ ":"; |
10035 | 145 |
val query = $$$ "?"; |
146 |
val bang = $$$ "!"; |
|
20111 | 147 |
val query_colon = $$$ "?" ^^ $$$ ":"; |
148 |
val bang_colon = $$$ "!" ^^ $$$ ":"; |
|
10035 | 149 |
|
8803 | 150 |
fun parens scan = $$$ "(" |-- scan --| $$$ ")"; |
10150 | 151 |
fun bracks scan = $$$ "[" |-- scan --| $$$ "]"; |
53168 | 152 |
fun mode s = Scan.optional (parens ($$$ s) >> K true) false; |
15703 | 153 |
fun maybe scan = $$$ "_" >> K NONE || scan >> SOME; |
5878 | 154 |
|
55045
99056d23e05b
cartouche within nested args (attributes, methods, etc.);
wenzelm
parents:
55033
diff
changeset
|
155 |
val cartouche = token Parse.cartouche; |
55111 | 156 |
val cartouche_inner_syntax = cartouche >> Token.inner_syntax_of; |
55045
99056d23e05b
cartouche within nested args (attributes, methods, etc.);
wenzelm
parents:
55033
diff
changeset
|
157 |
val cartouche_source_position = cartouche >> Token.source_position_of; |
99056d23e05b
cartouche within nested args (attributes, methods, etc.);
wenzelm
parents:
55033
diff
changeset
|
158 |
|
55111 | 159 |
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
|
160 |
val name_source_position = named >> Token.source_position_of; |
27882
eaa9fef9f4c1
Args.name_source(_position) for proper position information;
wenzelm
parents:
27819
diff
changeset
|
161 |
|
36959
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents:
36950
diff
changeset
|
162 |
val name = named >> Token.content_of; |
36950 | 163 |
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
|
164 |
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
|
165 |
val symbol = symbolic >> Token.content_of; |
17064 | 166 |
val liberal_name = symbol || name; |
8233 | 167 |
|
36959
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents:
36950
diff
changeset
|
168 |
val var = (ident >> Token.content_of) :|-- (fn x => |
27811 | 169 |
(case Lexicon.read_variable x of SOME v => Scan.succeed v | NONE => Scan.fail)); |
5878 | 170 |
|
5822
3f824514ad88
Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff
changeset
|
171 |
|
15703 | 172 |
(* values *) |
173 |
||
27811 | 174 |
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
|
175 |
(case Token.get_value arg of SOME v => (SOME (dest v) handle Match => NONE) | NONE => NONE)); |
15703 | 176 |
|
177 |
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
|
178 |
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
|
179 |
|
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_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
|
181 |
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
|
182 |
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
|
183 |
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
|
184 |
val internal_attribute = value (fn Token.Attribute att => att); |
15703 | 185 |
|
36959
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents:
36950
diff
changeset
|
186 |
fun named_text intern = internal_text || named >> evaluate Token.Text (intern o Token.content_of); |
55111 | 187 |
fun named_typ readT = internal_typ || named >> evaluate Token.Typ (readT o Token.inner_syntax_of); |
188 |
fun named_term read = internal_term || named >> evaluate Token.Term (read o Token.inner_syntax_of); |
|
42464 | 189 |
|
36959
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents:
36950
diff
changeset
|
190 |
fun named_fact get = internal_fact || named >> evaluate Token.Fact (get o Token.content_of) || |
55111 | 191 |
alt_string >> evaluate Token.Fact (get o Token.inner_syntax_of); |
42464 | 192 |
|
36959
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents:
36950
diff
changeset
|
193 |
fun named_attribute att = |
42464 | 194 |
internal_attribute || |
55708 | 195 |
named >> evaluate Token.Attribute (fn tok => att (Token.content_of tok, Token.pos_of tok)); |
15703 | 196 |
|
197 |
||
5878 | 198 |
(* terms and types *) |
199 |
||
42360 | 200 |
val typ_abbrev = Scan.peek (named_typ o Proof_Context.read_typ_abbrev o Context.proof_of); |
25331 | 201 |
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
|
202 |
val term = Scan.peek (named_term o Syntax.read_term o Context.proof_of); |
55155 | 203 |
val term_pattern = Scan.peek (named_term o Proof_Context.read_term_pattern o Context.proof_of); |
42360 | 204 |
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
|
205 |
val prop = Scan.peek (named_term o Syntax.read_prop o Context.proof_of); |
18635 | 206 |
|
5878 | 207 |
|
15703 | 208 |
(* type and constant names *) |
209 |
||
55951
c07d184aebe9
tuned signature -- more uniform check_type_name/read_type_name;
wenzelm
parents:
55915
diff
changeset
|
210 |
fun type_name flags = |
56002 | 211 |
Scan.peek (named_typ o Proof_Context.read_type_name flags o Context.proof_of) |
18998 | 212 |
>> (fn Type (c, _) => c | TFree (a, _) => a | _ => ""); |
15703 | 213 |
|
55954 | 214 |
fun const flags = |
56002 | 215 |
Scan.peek (named_term o Proof_Context.read_const flags o Context.proof_of) |
18998 | 216 |
>> (fn Const (c, _) => c | Free (x, _) => x | _ => ""); |
7553 | 217 |
|
15703 | 218 |
|
27811 | 219 |
(* improper method arguments *) |
15703 | 220 |
|
8536 | 221 |
val from_to = |
36950 | 222 |
Parse.nat -- ($$$ "-" |-- Parse.nat) >> (fn (i, j) => fn tac => Seq.INTERVAL tac i j) || |
223 |
Parse.nat --| $$$ "-" >> (fn i => fn tac => fn st => Seq.INTERVAL tac i (Thm.nprems_of st) st) || |
|
224 |
Parse.nat >> (fn i => fn tac => tac i) || |
|
15703 | 225 |
$$$ "!" >> K ALLGOALS; |
8536 | 226 |
|
36950 | 227 |
val goal = $$$ "[" |-- Parse.!!! (from_to --| $$$ "]"); |
30514 | 228 |
fun goal_spec x = Scan.lift (Scan.optional goal (fn tac => tac 1)) x; |
8233 | 229 |
|
230 |
||
27811 | 231 |
(* arguments within outer syntax *) |
5878 | 232 |
|
53113
d9ba3417cb41
more careful parsing of nested argument tokens -- avoid Parse.RESET_VALUE on still uninterpreted material;
wenzelm
parents:
53112
diff
changeset
|
233 |
val argument_kinds = |
d9ba3417cb41
more careful parsing of nested argument tokens -- avoid Parse.RESET_VALUE on still uninterpreted material;
wenzelm
parents:
53112
diff
changeset
|
234 |
[Token.Ident, Token.LongIdent, Token.SymIdent, Token.Var, Token.TypeIdent, Token.TypeVar, |
55033 | 235 |
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
|
236 |
|
27382 | 237 |
fun parse_args is_symid = |
238 |
let |
|
53113
d9ba3417cb41
more careful parsing of nested argument tokens -- avoid Parse.RESET_VALUE on still uninterpreted material;
wenzelm
parents:
53112
diff
changeset
|
239 |
fun argument blk = |
d9ba3417cb41
more careful parsing of nested argument tokens -- avoid Parse.RESET_VALUE on still uninterpreted material;
wenzelm
parents:
53112
diff
changeset
|
240 |
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
|
241 |
(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
|
242 |
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
|
243 |
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
|
244 |
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
|
245 |
(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
|
246 |
end)); |
5822
3f824514ad88
Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff
changeset
|
247 |
|
27382 | 248 |
fun args blk x = Scan.optional (args1 blk) [] x |
249 |
and args1 blk x = |
|
250 |
((Scan.repeat1 |
|
53113
d9ba3417cb41
more careful parsing of nested argument tokens -- avoid Parse.RESET_VALUE on still uninterpreted material;
wenzelm
parents:
53112
diff
changeset
|
251 |
(Scan.repeat1 (argument blk) || |
27382 | 252 |
argsp "(" ")" || |
253 |
argsp "[" "]")) >> flat) x |
|
36950 | 254 |
and argsp l r x = |
255 |
(token (Parse.$$$ l) ::: Parse.!!! (args true @@@ (token (Parse.$$$ r) >> single))) x; |
|
27382 | 256 |
in (args, args1) end; |
15703 | 257 |
|
36959
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents:
36950
diff
changeset
|
258 |
val parse = #1 (parse_args Token.ident_or_symbolic) false; |
27811 | 259 |
fun parse1 is_symid = #2 (parse_args is_symid) false; |
5822
3f824514ad88
Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff
changeset
|
260 |
|
27811 | 261 |
|
262 |
(* attributes *) |
|
27382 | 263 |
|
55997
9dc5ce83202c
modernized Attrib.check_name/check_src similar to methods (see also a989bdaf8121);
wenzelm
parents:
55956
diff
changeset
|
264 |
fun attribs check = |
15703 | 265 |
let |
55997
9dc5ce83202c
modernized Attrib.check_name/check_src similar to methods (see also a989bdaf8121);
wenzelm
parents:
55956
diff
changeset
|
266 |
fun intern tok = check (Token.content_of tok, Token.pos_of tok); |
9dc5ce83202c
modernized Attrib.check_name/check_src similar to methods (see also a989bdaf8121);
wenzelm
parents:
55956
diff
changeset
|
267 |
val attrib_name = internal_text || (symbolic || named) >> evaluate Token.Text intern; |
36950 | 268 |
val attrib = Parse.position (attrib_name -- Parse.!!! parse) >> src; |
269 |
in $$$ "[" |-- Parse.!!! (Parse.list attrib --| $$$ "]") end; |
|
15703 | 270 |
|
55997
9dc5ce83202c
modernized Attrib.check_name/check_src similar to methods (see also a989bdaf8121);
wenzelm
parents:
55956
diff
changeset
|
271 |
fun opt_attribs check = Scan.optional (attribs check) []; |
15703 | 272 |
|
5822
3f824514ad88
Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff
changeset
|
273 |
|
27377 | 274 |
(* theorem specifications *) |
275 |
||
55997
9dc5ce83202c
modernized Attrib.check_name/check_src similar to methods (see also a989bdaf8121);
wenzelm
parents:
55956
diff
changeset
|
276 |
fun thm_name check_attrib s = binding -- opt_attribs check_attrib --| $$$ s; |
27811 | 277 |
|
55997
9dc5ce83202c
modernized Attrib.check_name/check_src similar to methods (see also a989bdaf8121);
wenzelm
parents:
55956
diff
changeset
|
278 |
fun opt_thm_name check_attrib s = |
28078 | 279 |
Scan.optional |
55997
9dc5ce83202c
modernized Attrib.check_name/check_src similar to methods (see also a989bdaf8121);
wenzelm
parents:
55956
diff
changeset
|
280 |
((binding -- opt_attribs check_attrib || attribs check_attrib >> pair Binding.empty) --| $$$ s) |
28965 | 281 |
(Binding.empty, []); |
27377 | 282 |
|
283 |
||
27382 | 284 |
|
285 |
(** syntax wrapper **) |
|
5822
3f824514ad88
Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff
changeset
|
286 |
|
55914
c5b752d549e3
clarified init_assignable: make double-sure that initial values are reset;
wenzelm
parents:
55828
diff
changeset
|
287 |
fun syntax kind scan (Src ((s, args0), pos)) context = |
c5b752d549e3
clarified init_assignable: make double-sure that initial values are reset;
wenzelm
parents:
55828
diff
changeset
|
288 |
let |
c5b752d549e3
clarified init_assignable: make double-sure that initial values are reset;
wenzelm
parents:
55828
diff
changeset
|
289 |
val args1 = map Token.init_assignable args0; |
c5b752d549e3
clarified init_assignable: make double-sure that initial values are reset;
wenzelm
parents:
55828
diff
changeset
|
290 |
fun reported_text () = |
c5b752d549e3
clarified init_assignable: make double-sure that initial values are reset;
wenzelm
parents:
55828
diff
changeset
|
291 |
if Context_Position.is_visible_generic context then |
c5b752d549e3
clarified init_assignable: make double-sure that initial values are reset;
wenzelm
parents:
55828
diff
changeset
|
292 |
maps (Token.reports_of_value o Token.closure) args1 |
c5b752d549e3
clarified init_assignable: make double-sure that initial values are reset;
wenzelm
parents:
55828
diff
changeset
|
293 |
|> map (fn (p, m) => Position.reported_text p m "") |
c5b752d549e3
clarified init_assignable: make double-sure that initial values are reset;
wenzelm
parents:
55828
diff
changeset
|
294 |
|> implode |
c5b752d549e3
clarified init_assignable: make double-sure that initial values are reset;
wenzelm
parents:
55828
diff
changeset
|
295 |
else ""; |
c5b752d549e3
clarified init_assignable: make double-sure that initial values are reset;
wenzelm
parents:
55828
diff
changeset
|
296 |
in |
c5b752d549e3
clarified init_assignable: make double-sure that initial values are reset;
wenzelm
parents:
55828
diff
changeset
|
297 |
(case Scan.error (Scan.finite' Token.stopper (Scan.option scan)) (context, args1) of |
c5b752d549e3
clarified init_assignable: make double-sure that initial values are reset;
wenzelm
parents:
55828
diff
changeset
|
298 |
(SOME x, (context', [])) => (Output.report (reported_text ()); (x, context')) |
c5b752d549e3
clarified init_assignable: make double-sure that initial values are reset;
wenzelm
parents:
55828
diff
changeset
|
299 |
| (_, (_, args2)) => |
c5b752d549e3
clarified init_assignable: make double-sure that initial values are reset;
wenzelm
parents:
55828
diff
changeset
|
300 |
error ("Bad arguments for " ^ kind ^ " " ^ quote s ^ Position.here pos ^ |
c5b752d549e3
clarified init_assignable: make double-sure that initial values are reset;
wenzelm
parents:
55828
diff
changeset
|
301 |
(if null args2 then "" else ":\n " ^ space_implode " " (map Token.print args2)) ^ |
55956
94d384d621b0
reject internal term names outright, and complete consts instead;
wenzelm
parents:
55955
diff
changeset
|
302 |
Markup.markup_report (reported_text ()))) |
55914
c5b752d549e3
clarified init_assignable: make double-sure that initial values are reset;
wenzelm
parents:
55828
diff
changeset
|
303 |
end; |
15703 | 304 |
|
55914
c5b752d549e3
clarified init_assignable: make double-sure that initial values are reset;
wenzelm
parents:
55828
diff
changeset
|
305 |
fun context_syntax kind scan src = |
c5b752d549e3
clarified init_assignable: make double-sure that initial values are reset;
wenzelm
parents:
55828
diff
changeset
|
306 |
apsnd Context.the_proof o syntax kind scan src o Context.Proof; |
18998 | 307 |
|
5822
3f824514ad88
Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff
changeset
|
308 |
end; |