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