author | wenzelm |
Wed, 09 Apr 2014 20:58:32 +0200 | |
changeset 56500 | 90f17a04567d |
parent 56499 | 7e0178c84994 |
child 57942 | e5bec882fdd0 |
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 |
56033 | 13 |
val range_of_src: src -> Position.T |
56028 | 14 |
val unparse_src: src -> string list |
56032
b034b9f0fa2a
clarified Args.check_src: retain name space information for error output;
wenzelm
parents:
56029
diff
changeset
|
15 |
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
|
16 |
val check_src: Proof.context -> 'a Name_Space.table -> src -> src * 'a |
45290 | 17 |
val transform_values: morphism -> src -> src |
55914
c5b752d549e3
clarified init_assignable: make double-sure that initial values are reset;
wenzelm
parents:
55828
diff
changeset
|
18 |
val init_assignable: src -> src |
15703 | 19 |
val closure: src -> src |
30513 | 20 |
val context: Proof.context context_parser |
21 |
val theory: theory context_parser |
|
22 |
val $$$ : string -> string parser |
|
23 |
val add: string parser |
|
24 |
val del: string parser |
|
25 |
val colon: string parser |
|
26 |
val query: string parser |
|
27 |
val bang: string parser |
|
28 |
val query_colon: string parser |
|
29 |
val bang_colon: string parser |
|
53168 | 30 |
val parens: 'a parser -> 'a parser |
31 |
val bracks: 'a parser -> 'a parser |
|
32 |
val mode: string -> bool parser |
|
30513 | 33 |
val maybe: 'a parser -> 'a option parser |
55111 | 34 |
val cartouche_inner_syntax: string parser |
55828
42ac3cfb89f6
clarified language markup: added "delimited" property;
wenzelm
parents:
55745
diff
changeset
|
35 |
val cartouche_source_position: Symbol_Pos.source parser |
56500
90f17a04567d
proper Args.name vs. Args.text as documented (in contrast to adhoc union in 75aaee32893d, which had to cope with more limited Args.T);
wenzelm
parents:
56499
diff
changeset
|
36 |
val text_source_position: Symbol_Pos.source parser |
90f17a04567d
proper Args.name vs. Args.text as documented (in contrast to adhoc union in 75aaee32893d, which had to cope with more limited Args.T);
wenzelm
parents:
56499
diff
changeset
|
37 |
val text: string parser |
55111 | 38 |
val name_inner_syntax: string parser |
55828
42ac3cfb89f6
clarified language markup: added "delimited" property;
wenzelm
parents:
55745
diff
changeset
|
39 |
val name_source_position: Symbol_Pos.source parser |
30513 | 40 |
val name: string parser |
41 |
val binding: binding parser |
|
42 |
val alt_name: string parser |
|
43 |
val symbol: string parser |
|
44 |
val liberal_name: string parser |
|
45 |
val var: indexname parser |
|
46 |
val internal_text: string parser |
|
47 |
val internal_typ: typ parser |
|
48 |
val internal_term: term parser |
|
49 |
val internal_fact: thm list parser |
|
50 |
val internal_attribute: (morphism -> attribute) parser |
|
51 |
val named_text: (string -> string) -> string parser |
|
52 |
val named_typ: (string -> typ) -> typ parser |
|
53 |
val named_term: (string -> term) -> term parser |
|
54 |
val named_fact: (string -> thm list) -> thm list parser |
|
42464 | 55 |
val named_attribute: |
56 |
(string * Position.T -> morphism -> attribute) -> (morphism -> attribute) parser |
|
30513 | 57 |
val typ_abbrev: typ context_parser |
58 |
val typ: typ context_parser |
|
59 |
val term: term context_parser |
|
55155 | 60 |
val term_pattern: term context_parser |
30513 | 61 |
val term_abbrev: term context_parser |
62 |
val prop: term context_parser |
|
55951
c07d184aebe9
tuned signature -- more uniform check_type_name/read_type_name;
wenzelm
parents:
55915
diff
changeset
|
63 |
val type_name: {proper: bool, strict: bool} -> string context_parser |
55954 | 64 |
val const: {proper: bool, strict: bool} -> string context_parser |
30514 | 65 |
val goal_spec: ((int -> tactic) -> tactic) context_parser |
55997
9dc5ce83202c
modernized Attrib.check_name/check_src similar to methods (see also a989bdaf8121);
wenzelm
parents:
55956
diff
changeset
|
66 |
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
|
67 |
val opt_attribs: (xstring * Position.T -> string) -> src list parser |
56032
b034b9f0fa2a
clarified Args.check_src: retain name space information for error output;
wenzelm
parents:
56029
diff
changeset
|
68 |
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
|
69 |
val syntax: '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 |
||
56032
b034b9f0fa2a
clarified Args.check_src: retain name space information for error output;
wenzelm
parents:
56029
diff
changeset
|
77 |
datatype src = |
b034b9f0fa2a
clarified Args.check_src: retain name space information for error output;
wenzelm
parents:
56029
diff
changeset
|
78 |
Src of |
b034b9f0fa2a
clarified Args.check_src: retain name space information for error output;
wenzelm
parents:
56029
diff
changeset
|
79 |
{name: string * Position.T, |
b034b9f0fa2a
clarified Args.check_src: retain name space information for error output;
wenzelm
parents:
56029
diff
changeset
|
80 |
args: Token.T list, |
b034b9f0fa2a
clarified Args.check_src: retain name space information for error output;
wenzelm
parents:
56029
diff
changeset
|
81 |
output_info: (string * Markup.T) option}; |
56029
8bedca4bd5a3
clarified Args.src: more abstract type, position refers to name only;
wenzelm
parents:
56028
diff
changeset
|
82 |
|
56032
b034b9f0fa2a
clarified Args.check_src: retain name space information for error output;
wenzelm
parents:
56029
diff
changeset
|
83 |
fun src name args = Src {name = name, args = args, output_info = NONE}; |
15703 | 84 |
|
56032
b034b9f0fa2a
clarified Args.check_src: retain name space information for error output;
wenzelm
parents:
56029
diff
changeset
|
85 |
fun name_of_src (Src {name, ...}) = name; |
b034b9f0fa2a
clarified Args.check_src: retain name space information for error output;
wenzelm
parents:
56029
diff
changeset
|
86 |
|
56033 | 87 |
fun range_of_src (Src {name = (_, pos), args, ...}) = |
88 |
if null args then pos |
|
89 |
else Position.set_range (pos, #2 (Token.range_of args)); |
|
90 |
||
56032
b034b9f0fa2a
clarified Args.check_src: retain name space information for error output;
wenzelm
parents:
56029
diff
changeset
|
91 |
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
|
92 |
|
56032
b034b9f0fa2a
clarified Args.check_src: retain name space information for error output;
wenzelm
parents:
56029
diff
changeset
|
93 |
fun pretty_src ctxt src = |
21030 | 94 |
let |
56037 | 95 |
val Src {name = (name, _), args, output_info} = src; |
96 |
val prt_name = |
|
97 |
(case output_info of |
|
98 |
NONE => Pretty.str name |
|
99 |
| SOME (_, markup) => Pretty.mark_str (markup, name)); |
|
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
|
100 |
val prt_thm = Pretty.backquote o Display.pretty_thm ctxt; |
56037 | 101 |
fun prt_arg 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
|
102 |
(case Token.get_value arg of |
56063 | 103 |
SOME (Token.Literal markup) => |
104 |
let val x = Token.content_of arg |
|
105 |
in Pretty.mark_str (Token.keyword_markup markup x, x) end |
|
55914
c5b752d549e3
clarified init_assignable: make double-sure that initial values are reset;
wenzelm
parents:
55828
diff
changeset
|
106 |
| 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
|
107 |
| 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
|
108 |
| 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
|
109 |
| 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
|
110 |
| _ => Pretty.mark_str (Token.markup arg, Token.unparse arg)); |
56037 | 111 |
in Pretty.block (Pretty.breaks (prt_name :: map prt_arg args)) end; |
21030 | 112 |
|
56029
8bedca4bd5a3
clarified Args.src: more abstract type, position refers to name only;
wenzelm
parents:
56028
diff
changeset
|
113 |
|
8bedca4bd5a3
clarified Args.src: more abstract type, position refers to name only;
wenzelm
parents:
56028
diff
changeset
|
114 |
(* check *) |
8bedca4bd5a3
clarified Args.src: more abstract type, position refers to name only;
wenzelm
parents:
56028
diff
changeset
|
115 |
|
56063 | 116 |
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
|
117 |
let |
b034b9f0fa2a
clarified Args.check_src: retain name space information for error output;
wenzelm
parents:
56029
diff
changeset
|
118 |
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
|
119 |
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
|
120 |
val kind = Name_Space.kind_of space; |
b034b9f0fa2a
clarified Args.check_src: retain name space information for error output;
wenzelm
parents:
56029
diff
changeset
|
121 |
val markup = Name_Space.markup space name; |
b034b9f0fa2a
clarified Args.check_src: retain name space information for error output;
wenzelm
parents:
56029
diff
changeset
|
122 |
in (Src {name = (name, pos), args = args, output_info = SOME (kind, markup)}, x) end; |
15703 | 123 |
|
124 |
||
125 |
(* values *) |
|
126 |
||
56037 | 127 |
fun map_args f (Src {name, args, output_info}) = |
128 |
Src {name = name, args = map f args, output_info = output_info}; |
|
129 |
||
45290 | 130 |
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
|
131 |
(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
|
132 |
| 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
|
133 |
| Token.Fact ths => Token.Fact (Morphism.fact phi ths) |
53112 | 134 |
| 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
|
135 |
| tok => tok)); |
15703 | 136 |
|
55914
c5b752d549e3
clarified init_assignable: make double-sure that initial values are reset;
wenzelm
parents:
55828
diff
changeset
|
137 |
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
|
138 |
val closure = map_args Token.closure; |
15703 | 139 |
|
140 |
||
141 |
||
27811 | 142 |
(** argument scanners **) |
5822
3f824514ad88
Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff
changeset
|
143 |
|
27371 | 144 |
(* context *) |
145 |
||
146 |
fun context x = (Scan.state >> Context.proof_of) x; |
|
147 |
fun theory x = (Scan.state >> Context.theory_of) x; |
|
148 |
||
149 |
||
27811 | 150 |
(* basic *) |
5878 | 151 |
|
56201 | 152 |
val ident = Parse.token |
36950 | 153 |
(Parse.short_ident || Parse.long_ident || Parse.sym_ident || Parse.term_var || |
154 |
Parse.type_ident || Parse.type_var || Parse.number); |
|
5878 | 155 |
|
56500
90f17a04567d
proper Args.name vs. Args.text as documented (in contrast to adhoc union in 75aaee32893d, which had to cope with more limited Args.T);
wenzelm
parents:
56499
diff
changeset
|
156 |
val string = Parse.token Parse.string; |
56499
7e0178c84994
allow text cartouches in regular outer syntax categories "text" and "altstring";
wenzelm
parents:
56333
diff
changeset
|
157 |
val alt_string = Parse.token (Parse.alt_string || Parse.cartouche); |
56201 | 158 |
val symbolic = Parse.token (Parse.keyword_with Token.ident_or_symbolic); |
27811 | 159 |
|
55914
c5b752d549e3
clarified init_assignable: make double-sure that initial values are reset;
wenzelm
parents:
55828
diff
changeset
|
160 |
fun $$$ x = |
56201 | 161 |
(ident || Parse.token Parse.keyword) :|-- (fn tok => |
56063 | 162 |
let val y = Token.content_of tok in |
163 |
if x = y |
|
56202 | 164 |
then (Token.assign (SOME (Token.Literal (false, Markup.quasi_keyword))) tok; Scan.succeed x) |
56063 | 165 |
else Scan.fail |
166 |
end); |
|
5878 | 167 |
|
27811 | 168 |
val named = ident || string; |
5878 | 169 |
|
10035 | 170 |
val add = $$$ "add"; |
171 |
val del = $$$ "del"; |
|
8803 | 172 |
val colon = $$$ ":"; |
10035 | 173 |
val query = $$$ "?"; |
174 |
val bang = $$$ "!"; |
|
20111 | 175 |
val query_colon = $$$ "?" ^^ $$$ ":"; |
176 |
val bang_colon = $$$ "!" ^^ $$$ ":"; |
|
10035 | 177 |
|
8803 | 178 |
fun parens scan = $$$ "(" |-- scan --| $$$ ")"; |
10150 | 179 |
fun bracks scan = $$$ "[" |-- scan --| $$$ "]"; |
53168 | 180 |
fun mode s = Scan.optional (parens ($$$ s) >> K true) false; |
15703 | 181 |
fun maybe scan = $$$ "_" >> K NONE || scan >> SOME; |
5878 | 182 |
|
56201 | 183 |
val cartouche = Parse.token Parse.cartouche; |
55111 | 184 |
val cartouche_inner_syntax = cartouche >> Token.inner_syntax_of; |
55045
99056d23e05b
cartouche within nested args (attributes, methods, etc.);
wenzelm
parents:
55033
diff
changeset
|
185 |
val cartouche_source_position = cartouche >> Token.source_position_of; |
99056d23e05b
cartouche within nested args (attributes, methods, etc.);
wenzelm
parents:
55033
diff
changeset
|
186 |
|
56500
90f17a04567d
proper Args.name vs. Args.text as documented (in contrast to adhoc union in 75aaee32893d, which had to cope with more limited Args.T);
wenzelm
parents:
56499
diff
changeset
|
187 |
val text_token = named || Parse.token (Parse.verbatim || Parse.cartouche); |
90f17a04567d
proper Args.name vs. Args.text as documented (in contrast to adhoc union in 75aaee32893d, which had to cope with more limited Args.T);
wenzelm
parents:
56499
diff
changeset
|
188 |
val text_source_position = text_token >> Token.source_position_of; |
90f17a04567d
proper Args.name vs. Args.text as documented (in contrast to adhoc union in 75aaee32893d, which had to cope with more limited Args.T);
wenzelm
parents:
56499
diff
changeset
|
189 |
val text = text_token >> Token.content_of; |
90f17a04567d
proper Args.name vs. Args.text as documented (in contrast to adhoc union in 75aaee32893d, which had to cope with more limited Args.T);
wenzelm
parents:
56499
diff
changeset
|
190 |
|
55111 | 191 |
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
|
192 |
val name_source_position = named >> Token.source_position_of; |
27882
eaa9fef9f4c1
Args.name_source(_position) for proper position information;
wenzelm
parents:
27819
diff
changeset
|
193 |
|
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 name = named >> Token.content_of; |
36950 | 195 |
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
|
196 |
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
|
197 |
val symbol = symbolic >> Token.content_of; |
17064 | 198 |
val liberal_name = symbol || name; |
8233 | 199 |
|
36959
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents:
36950
diff
changeset
|
200 |
val var = (ident >> Token.content_of) :|-- (fn x => |
27811 | 201 |
(case Lexicon.read_variable x of SOME v => Scan.succeed v | NONE => Scan.fail)); |
5878 | 202 |
|
5822
3f824514ad88
Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff
changeset
|
203 |
|
15703 | 204 |
(* values *) |
205 |
||
27811 | 206 |
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
|
207 |
(case Token.get_value arg of SOME v => (SOME (dest v) handle Match => NONE) | NONE => NONE)); |
15703 | 208 |
|
209 |
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
|
210 |
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
|
211 |
|
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_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
|
213 |
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
|
214 |
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
|
215 |
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
|
216 |
val internal_attribute = value (fn Token.Attribute att => att); |
15703 | 217 |
|
36959
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents:
36950
diff
changeset
|
218 |
fun named_text intern = internal_text || named >> evaluate Token.Text (intern o Token.content_of); |
55111 | 219 |
fun named_typ readT = internal_typ || named >> evaluate Token.Typ (readT o Token.inner_syntax_of); |
220 |
fun named_term read = internal_term || named >> evaluate Token.Term (read o Token.inner_syntax_of); |
|
42464 | 221 |
|
36959
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents:
36950
diff
changeset
|
222 |
fun named_fact get = internal_fact || named >> evaluate Token.Fact (get o Token.content_of) || |
55111 | 223 |
alt_string >> evaluate Token.Fact (get o Token.inner_syntax_of); |
42464 | 224 |
|
36959
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents:
36950
diff
changeset
|
225 |
fun named_attribute att = |
42464 | 226 |
internal_attribute || |
55708 | 227 |
named >> evaluate Token.Attribute (fn tok => att (Token.content_of tok, Token.pos_of tok)); |
15703 | 228 |
|
229 |
||
5878 | 230 |
(* terms and types *) |
231 |
||
42360 | 232 |
val typ_abbrev = Scan.peek (named_typ o Proof_Context.read_typ_abbrev o Context.proof_of); |
25331 | 233 |
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
|
234 |
val term = Scan.peek (named_term o Syntax.read_term o Context.proof_of); |
55155 | 235 |
val term_pattern = Scan.peek (named_term o Proof_Context.read_term_pattern o Context.proof_of); |
42360 | 236 |
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
|
237 |
val prop = Scan.peek (named_term o Syntax.read_prop o Context.proof_of); |
18635 | 238 |
|
5878 | 239 |
|
15703 | 240 |
(* type and constant names *) |
241 |
||
55951
c07d184aebe9
tuned signature -- more uniform check_type_name/read_type_name;
wenzelm
parents:
55915
diff
changeset
|
242 |
fun type_name flags = |
56002 | 243 |
Scan.peek (named_typ o Proof_Context.read_type_name flags o Context.proof_of) |
18998 | 244 |
>> (fn Type (c, _) => c | TFree (a, _) => a | _ => ""); |
15703 | 245 |
|
55954 | 246 |
fun const flags = |
56002 | 247 |
Scan.peek (named_term o Proof_Context.read_const flags o Context.proof_of) |
18998 | 248 |
>> (fn Const (c, _) => c | Free (x, _) => x | _ => ""); |
7553 | 249 |
|
15703 | 250 |
|
27811 | 251 |
(* improper method arguments *) |
15703 | 252 |
|
8536 | 253 |
val from_to = |
36950 | 254 |
Parse.nat -- ($$$ "-" |-- Parse.nat) >> (fn (i, j) => fn tac => Seq.INTERVAL tac i j) || |
255 |
Parse.nat --| $$$ "-" >> (fn i => fn tac => fn st => Seq.INTERVAL tac i (Thm.nprems_of st) st) || |
|
256 |
Parse.nat >> (fn i => fn tac => tac i) || |
|
15703 | 257 |
$$$ "!" >> K ALLGOALS; |
8536 | 258 |
|
56202 | 259 |
val goal = Parse.keyword_improper "[" |-- Parse.!!! (from_to --| Parse.keyword_improper "]"); |
30514 | 260 |
fun goal_spec x = Scan.lift (Scan.optional goal (fn tac => tac 1)) x; |
8233 | 261 |
|
262 |
||
27811 | 263 |
(* attributes *) |
27382 | 264 |
|
55997
9dc5ce83202c
modernized Attrib.check_name/check_src similar to methods (see also a989bdaf8121);
wenzelm
parents:
55956
diff
changeset
|
265 |
fun attribs check = |
15703 | 266 |
let |
55997
9dc5ce83202c
modernized Attrib.check_name/check_src similar to methods (see also a989bdaf8121);
wenzelm
parents:
55956
diff
changeset
|
267 |
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
|
268 |
val attrib_name = internal_text || (symbolic || named) >> evaluate Token.Text intern; |
56201 | 269 |
val attrib = Parse.position attrib_name -- Parse.!!! Parse.args >> uncurry src; |
36950 | 270 |
in $$$ "[" |-- Parse.!!! (Parse.list attrib --| $$$ "]") end; |
15703 | 271 |
|
55997
9dc5ce83202c
modernized Attrib.check_name/check_src similar to methods (see also a989bdaf8121);
wenzelm
parents:
55956
diff
changeset
|
272 |
fun opt_attribs check = Scan.optional (attribs check) []; |
15703 | 273 |
|
5822
3f824514ad88
Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff
changeset
|
274 |
|
27382 | 275 |
|
276 |
(** syntax wrapper **) |
|
5822
3f824514ad88
Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff
changeset
|
277 |
|
56032
b034b9f0fa2a
clarified Args.check_src: retain name space information for error output;
wenzelm
parents:
56029
diff
changeset
|
278 |
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
|
279 |
let |
c5b752d549e3
clarified init_assignable: make double-sure that initial values are reset;
wenzelm
parents:
55828
diff
changeset
|
280 |
val args1 = map Token.init_assignable args0; |
c5b752d549e3
clarified init_assignable: make double-sure that initial values are reset;
wenzelm
parents:
55828
diff
changeset
|
281 |
fun reported_text () = |
c5b752d549e3
clarified init_assignable: make double-sure that initial values are reset;
wenzelm
parents:
55828
diff
changeset
|
282 |
if Context_Position.is_visible_generic context then |
56063 | 283 |
((pos, Markup.operator) :: maps (Token.reports_of_value o Token.closure) args1) |
55914
c5b752d549e3
clarified init_assignable: make double-sure that initial values are reset;
wenzelm
parents:
55828
diff
changeset
|
284 |
|> map (fn (p, m) => Position.reported_text p m "") |
56333
38f1422ef473
support bulk messages consisting of small string segments, which are more healthy to the Poly/ML RTS and might prevent spurious GC crashes such as MTGCProcessMarkPointers::ScanAddressesInObject;
wenzelm
parents:
56202
diff
changeset
|
285 |
else []; |
55914
c5b752d549e3
clarified init_assignable: make double-sure that initial values are reset;
wenzelm
parents:
55828
diff
changeset
|
286 |
in |
c5b752d549e3
clarified init_assignable: make double-sure that initial values are reset;
wenzelm
parents:
55828
diff
changeset
|
287 |
(case Scan.error (Scan.finite' Token.stopper (Scan.option scan)) (context, args1) of |
56037 | 288 |
(SOME x, (context', [])) => |
289 |
let val _ = Output.report (reported_text ()) |
|
290 |
in (x, context') end |
|
55914
c5b752d549e3
clarified init_assignable: make double-sure that initial values are reset;
wenzelm
parents:
55828
diff
changeset
|
291 |
| (_, (_, args2)) => |
56037 | 292 |
let |
293 |
val print_name = |
|
294 |
(case output_info of |
|
295 |
NONE => quote name |
|
56038
0e2dec666152
tuned messages -- in accordance to Isabelle/Scala;
wenzelm
parents:
56037
diff
changeset
|
296 |
| SOME (kind, markup) => plain_words kind ^ " " ^ quote (Markup.markup markup name)); |
56037 | 297 |
val print_args = |
298 |
if null args2 then "" else ":\n " ^ space_implode " " (map Token.print args2); |
|
299 |
in |
|
300 |
error ("Bad arguments for " ^ print_name ^ Position.here pos ^ print_args ^ |
|
56333
38f1422ef473
support bulk messages consisting of small string segments, which are more healthy to the Poly/ML RTS and might prevent spurious GC crashes such as MTGCProcessMarkPointers::ScanAddressesInObject;
wenzelm
parents:
56202
diff
changeset
|
301 |
Markup.markup_report (implode (reported_text ()))) |
56037 | 302 |
end) |
55914
c5b752d549e3
clarified init_assignable: make double-sure that initial values are reset;
wenzelm
parents:
55828
diff
changeset
|
303 |
end; |
15703 | 304 |
|
56032
b034b9f0fa2a
clarified Args.check_src: retain name space information for error output;
wenzelm
parents:
56029
diff
changeset
|
305 |
fun syntax scan src = apsnd Context.the_proof o syntax_generic scan src o Context.Proof; |
18998 | 306 |
|
5822
3f824514ad88
Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff
changeset
|
307 |
end; |