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