author | wenzelm |
Sat, 15 May 2010 23:32:15 +0200 | |
changeset 36952 | 338c3f8229e4 |
parent 36950 | src/Pure/Isar/spec_parse.ML@75b8f26f2f07 |
child 36955 | 226fb165833e |
permissions | -rw-r--r-- |
36952
338c3f8229e4
renamed structure SpecParse to Parse_Spec, keeping the old name as alias for some time;
wenzelm
parents:
36950
diff
changeset
|
1 |
(* Title: Pure/Isar/parse_spec.ML |
22104
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
wenzelm
parents:
diff
changeset
|
2 |
Author: Makarius |
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
wenzelm
parents:
diff
changeset
|
3 |
|
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
wenzelm
parents:
diff
changeset
|
4 |
Parsers for complex specifications. |
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
wenzelm
parents:
diff
changeset
|
5 |
*) |
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
wenzelm
parents:
diff
changeset
|
6 |
|
36952
338c3f8229e4
renamed structure SpecParse to Parse_Spec, keeping the old name as alias for some time;
wenzelm
parents:
36950
diff
changeset
|
7 |
signature PARSE_SPEC = |
22104
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
wenzelm
parents:
diff
changeset
|
8 |
sig |
29312 | 9 |
val attrib: Attrib.src parser |
10 |
val attribs: Attrib.src list parser |
|
11 |
val opt_attribs: Attrib.src list parser |
|
12 |
val thm_name: string -> Attrib.binding parser |
|
13 |
val opt_thm_name: string -> Attrib.binding parser |
|
30481
de003023c302
removed old named_spec, spec_name, spec_opt_name;
wenzelm
parents:
29601
diff
changeset
|
14 |
val spec: (Attrib.binding * string) parser |
de003023c302
removed old named_spec, spec_name, spec_opt_name;
wenzelm
parents:
29601
diff
changeset
|
15 |
val specs: (Attrib.binding * string list) parser |
de003023c302
removed old named_spec, spec_name, spec_opt_name;
wenzelm
parents:
29601
diff
changeset
|
16 |
val alt_specs: (Attrib.binding * string) list parser |
de003023c302
removed old named_spec, spec_name, spec_opt_name;
wenzelm
parents:
29601
diff
changeset
|
17 |
val where_alt_specs: (Attrib.binding * string) list parser |
29312 | 18 |
val xthm: (Facts.ref * Attrib.src list) parser |
19 |
val xthms1: (Facts.ref * Attrib.src list) list parser |
|
20 |
val name_facts: (Attrib.binding * (Facts.ref * Attrib.src list) list) list parser |
|
33287
0f99569d23e1
provide SpecParse.constdecl/constdef, e.g. for quotient_definition;
wenzelm
parents:
30726
diff
changeset
|
21 |
val constdecl: (binding * string option * mixfix) parser |
0f99569d23e1
provide SpecParse.constdecl/constdef, e.g. for quotient_definition;
wenzelm
parents:
30726
diff
changeset
|
22 |
val constdef: ((binding * string option * mixfix) option * (Attrib.binding * string)) parser |
29312 | 23 |
val locale_mixfix: mixfix parser |
29581 | 24 |
val locale_fixes: (binding * string option * mixfix) list parser |
29312 | 25 |
val locale_insts: (string option list * (Attrib.binding * string) list) parser |
26 |
val class_expr: string list parser |
|
30726 | 27 |
val locale_expression: bool -> Expression.expression parser |
29312 | 28 |
val locale_keyword: string parser |
29 |
val context_element: Element.context parser |
|
30 |
val statement: (Attrib.binding * (string * string list) list) list parser |
|
31 |
val general_statement: (Element.context list * Element.statement) parser |
|
32 |
val statement_keyword: string parser |
|
22104
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
wenzelm
parents:
diff
changeset
|
33 |
end; |
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
wenzelm
parents:
diff
changeset
|
34 |
|
36952
338c3f8229e4
renamed structure SpecParse to Parse_Spec, keeping the old name as alias for some time;
wenzelm
parents:
36950
diff
changeset
|
35 |
structure Parse_Spec: PARSE_SPEC = |
22104
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
wenzelm
parents:
diff
changeset
|
36 |
struct |
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
wenzelm
parents:
diff
changeset
|
37 |
|
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
wenzelm
parents:
diff
changeset
|
38 |
(* theorem specifications *) |
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
wenzelm
parents:
diff
changeset
|
39 |
|
36950 | 40 |
val attrib = |
41 |
Parse.position ((Parse.keyword_ident_or_symbolic || Parse.xname) -- Parse.!!! Args.parse) |
|
42 |
>> Args.src; |
|
43 |
||
44 |
val attribs = Parse.$$$ "[" |-- Parse.list attrib --| Parse.$$$ "]"; |
|
22104
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
wenzelm
parents:
diff
changeset
|
45 |
val opt_attribs = Scan.optional attribs []; |
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
wenzelm
parents:
diff
changeset
|
46 |
|
36950 | 47 |
fun thm_name s = Parse.binding -- opt_attribs --| Parse.$$$ s; |
28083
103d9282a946
explicit type Name.binding for higher-specification elements;
wenzelm
parents:
27816
diff
changeset
|
48 |
|
22104
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
wenzelm
parents:
diff
changeset
|
49 |
fun opt_thm_name s = |
36950 | 50 |
Scan.optional ((Parse.binding -- opt_attribs || attribs >> pair Binding.empty) --| Parse.$$$ s) |
28965 | 51 |
Attrib.empty_binding; |
22104
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
wenzelm
parents:
diff
changeset
|
52 |
|
36950 | 53 |
val spec = opt_thm_name ":" -- Parse.prop; |
54 |
val specs = opt_thm_name ":" -- Scan.repeat1 Parse.prop; |
|
22104
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
wenzelm
parents:
diff
changeset
|
55 |
|
30481
de003023c302
removed old named_spec, spec_name, spec_opt_name;
wenzelm
parents:
29601
diff
changeset
|
56 |
val alt_specs = |
36950 | 57 |
Parse.enum1 "|" |
58 |
(spec --| Scan.option (Scan.ahead (Parse.name || Parse.$$$ "[") -- Parse.!!! (Parse.$$$ "|"))); |
|
30481
de003023c302
removed old named_spec, spec_name, spec_opt_name;
wenzelm
parents:
29601
diff
changeset
|
59 |
|
36950 | 60 |
val where_alt_specs = Parse.where_ |-- Parse.!!! alt_specs; |
22104
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
wenzelm
parents:
diff
changeset
|
61 |
|
24013
3063a756611d
xthm: added [[declaration]] syntax (abbreviates dummy_thm [att]);
wenzelm
parents:
23919
diff
changeset
|
62 |
val xthm = |
36950 | 63 |
Parse.$$$ "[" |-- attribs --| Parse.$$$ "]" >> pair (Facts.named "") || |
64 |
(Parse.alt_string >> Facts.Fact || |
|
65 |
Parse.position Parse.xname -- Scan.option Attrib.thm_sel >> Facts.Named) -- opt_attribs; |
|
24013
3063a756611d
xthm: added [[declaration]] syntax (abbreviates dummy_thm [att]);
wenzelm
parents:
23919
diff
changeset
|
66 |
|
22104
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
wenzelm
parents:
diff
changeset
|
67 |
val xthms1 = Scan.repeat1 xthm; |
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
wenzelm
parents:
diff
changeset
|
68 |
|
36950 | 69 |
val name_facts = Parse.and_list1 (opt_thm_name "=" -- xthms1); |
22104
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
wenzelm
parents:
diff
changeset
|
70 |
|
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
wenzelm
parents:
diff
changeset
|
71 |
|
33287
0f99569d23e1
provide SpecParse.constdecl/constdef, e.g. for quotient_definition;
wenzelm
parents:
30726
diff
changeset
|
72 |
(* basic constant specifications *) |
0f99569d23e1
provide SpecParse.constdecl/constdef, e.g. for quotient_definition;
wenzelm
parents:
30726
diff
changeset
|
73 |
|
0f99569d23e1
provide SpecParse.constdecl/constdef, e.g. for quotient_definition;
wenzelm
parents:
30726
diff
changeset
|
74 |
val constdecl = |
36950 | 75 |
Parse.binding -- |
76 |
(Parse.where_ >> K (NONE, NoSyn) || |
|
77 |
Parse.$$$ "::" |-- Parse.!!! ((Parse.typ >> SOME) -- Parse.opt_mixfix' --| Parse.where_) || |
|
78 |
Scan.ahead (Parse.$$$ "(") |-- Parse.!!! (Parse.mixfix' --| Parse.where_ >> pair NONE)) |
|
79 |
>> Parse.triple2; |
|
33287
0f99569d23e1
provide SpecParse.constdecl/constdef, e.g. for quotient_definition;
wenzelm
parents:
30726
diff
changeset
|
80 |
|
36950 | 81 |
val constdef = Scan.option constdecl -- (opt_thm_name ":" -- Parse.prop); |
33287
0f99569d23e1
provide SpecParse.constdecl/constdef, e.g. for quotient_definition;
wenzelm
parents:
30726
diff
changeset
|
82 |
|
0f99569d23e1
provide SpecParse.constdecl/constdef, e.g. for quotient_definition;
wenzelm
parents:
30726
diff
changeset
|
83 |
|
22104
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
wenzelm
parents:
diff
changeset
|
84 |
(* locale and context elements *) |
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
wenzelm
parents:
diff
changeset
|
85 |
|
36950 | 86 |
val locale_mixfix = |
87 |
Parse.$$$ "(" -- Parse.$$$ "structure" -- Parse.!!! (Parse.$$$ ")") >> K Structure || |
|
88 |
Parse.mixfix; |
|
22104
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
wenzelm
parents:
diff
changeset
|
89 |
|
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
wenzelm
parents:
diff
changeset
|
90 |
val locale_fixes = |
36950 | 91 |
Parse.and_list1 (Parse.binding -- Scan.option (Parse.$$$ "::" |-- Parse.typ) -- locale_mixfix |
92 |
>> (single o Parse.triple1) || |
|
93 |
Parse.params >> map Syntax.no_syn) >> flat; |
|
22104
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
wenzelm
parents:
diff
changeset
|
94 |
|
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
wenzelm
parents:
diff
changeset
|
95 |
val locale_insts = |
36950 | 96 |
Scan.optional |
97 |
(Parse.$$$ "[" |-- Parse.!!! (Scan.repeat1 (Parse.maybe Parse.term) --| Parse.$$$ "]")) [] -- |
|
98 |
Scan.optional (Parse.where_ |-- Parse.and_list1 (opt_thm_name ":" -- Parse.prop)) []; |
|
22104
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
wenzelm
parents:
diff
changeset
|
99 |
|
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
wenzelm
parents:
diff
changeset
|
100 |
local |
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
wenzelm
parents:
diff
changeset
|
101 |
|
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
wenzelm
parents:
diff
changeset
|
102 |
val loc_element = |
36950 | 103 |
Parse.$$$ "fixes" |-- Parse.!!! locale_fixes >> Element.Fixes || |
104 |
Parse.$$$ "constrains" |-- |
|
105 |
Parse.!!! (Parse.and_list1 (Parse.name -- (Parse.$$$ "::" |-- Parse.typ))) |
|
22104
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
wenzelm
parents:
diff
changeset
|
106 |
>> Element.Constrains || |
36950 | 107 |
Parse.$$$ "assumes" |-- Parse.!!! (Parse.and_list1 (opt_thm_name ":" -- Scan.repeat1 Parse.propp)) |
22104
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
wenzelm
parents:
diff
changeset
|
108 |
>> Element.Assumes || |
36950 | 109 |
Parse.$$$ "defines" |-- Parse.!!! (Parse.and_list1 (opt_thm_name ":" -- Parse.propp)) |
22104
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
wenzelm
parents:
diff
changeset
|
110 |
>> Element.Defines || |
36950 | 111 |
Parse.$$$ "notes" |-- Parse.!!! (Parse.and_list1 (opt_thm_name "=" -- xthms1)) |
22104
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
wenzelm
parents:
diff
changeset
|
112 |
>> (curry Element.Notes ""); |
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
wenzelm
parents:
diff
changeset
|
113 |
|
24869 | 114 |
fun plus1_unless test scan = |
36950 | 115 |
scan ::: Scan.repeat (Parse.$$$ "+" |-- Scan.unless test (Parse.!!! scan)); |
22104
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
wenzelm
parents:
diff
changeset
|
116 |
|
30726 | 117 |
fun prefix mandatory = |
36950 | 118 |
Parse.name -- |
119 |
(Parse.$$$ "!" >> K true || Parse.$$$ "?" >> K false || Scan.succeed mandatory) --| |
|
120 |
Parse.$$$ ":"; |
|
22104
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
wenzelm
parents:
diff
changeset
|
121 |
|
36950 | 122 |
val instance = Parse.where_ |-- |
123 |
Parse.and_list1 (Parse.name -- (Parse.$$$ "=" |-- Parse.term)) >> Expression.Named || |
|
124 |
Scan.repeat1 (Parse.maybe Parse.term) >> Expression.Positional; |
|
29033
721529248e31
Enable keyword 'structure' in for clause of locale expression.
ballarin
parents:
28965
diff
changeset
|
125 |
|
24869 | 126 |
in |
127 |
||
36950 | 128 |
val locale_keyword = |
129 |
Parse.$$$ "fixes" || Parse.$$$ "constrains" || Parse.$$$ "assumes" || |
|
130 |
Parse.$$$ "defines" || Parse.$$$ "notes"; |
|
28722 | 131 |
|
36950 | 132 |
val class_expr = plus1_unless locale_keyword Parse.xname; |
24869 | 133 |
|
30726 | 134 |
fun locale_expression mandatory = |
29033
721529248e31
Enable keyword 'structure' in for clause of locale expression.
ballarin
parents:
28965
diff
changeset
|
135 |
let |
36950 | 136 |
val expr2 = Parse.xname; |
30726 | 137 |
val expr1 = Scan.optional (prefix mandatory) ("", false) -- expr2 -- |
30720 | 138 |
Scan.optional instance (Expression.Named []) >> (fn ((p, l), i) => (l, (p, i))); |
139 |
val expr0 = plus1_unless locale_keyword expr1; |
|
36950 | 140 |
in expr0 -- Scan.optional (Parse.$$$ "for" |-- Parse.!!! locale_fixes) [] end; |
29033
721529248e31
Enable keyword 'structure' in for clause of locale expression.
ballarin
parents:
28965
diff
changeset
|
141 |
|
36950 | 142 |
val context_element = Parse.group "context element" loc_element; |
22104
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
wenzelm
parents:
diff
changeset
|
143 |
|
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
wenzelm
parents:
diff
changeset
|
144 |
end; |
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
wenzelm
parents:
diff
changeset
|
145 |
|
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
wenzelm
parents:
diff
changeset
|
146 |
|
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
wenzelm
parents:
diff
changeset
|
147 |
(* statements *) |
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
wenzelm
parents:
diff
changeset
|
148 |
|
36950 | 149 |
val statement = Parse.and_list1 (opt_thm_name ":" -- Scan.repeat1 Parse.propp); |
22104
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
wenzelm
parents:
diff
changeset
|
150 |
|
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
wenzelm
parents:
diff
changeset
|
151 |
val obtain_case = |
36950 | 152 |
Parse.parbinding -- (Scan.optional (Parse.simple_fixes --| Parse.where_) [] -- |
153 |
(Parse.and_list1 (Scan.repeat1 Parse.prop) >> flat)); |
|
22104
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
wenzelm
parents:
diff
changeset
|
154 |
|
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
wenzelm
parents:
diff
changeset
|
155 |
val general_statement = |
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
wenzelm
parents:
diff
changeset
|
156 |
statement >> (fn x => ([], Element.Shows x)) || |
28722 | 157 |
Scan.repeat context_element -- |
36950 | 158 |
(Parse.$$$ "obtains" |-- Parse.!!! (Parse.enum1 "|" obtain_case) >> Element.Obtains || |
159 |
Parse.$$$ "shows" |-- Parse.!!! statement >> Element.Shows); |
|
22104
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
wenzelm
parents:
diff
changeset
|
160 |
|
36950 | 161 |
val statement_keyword = Parse.$$$ "obtains" || Parse.$$$ "shows"; |
22104
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
wenzelm
parents:
diff
changeset
|
162 |
|
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
wenzelm
parents:
diff
changeset
|
163 |
end; |
36952
338c3f8229e4
renamed structure SpecParse to Parse_Spec, keeping the old name as alias for some time;
wenzelm
parents:
36950
diff
changeset
|
164 |
|
338c3f8229e4
renamed structure SpecParse to Parse_Spec, keeping the old name as alias for some time;
wenzelm
parents:
36950
diff
changeset
|
165 |
(*legacy alias*) |
338c3f8229e4
renamed structure SpecParse to Parse_Spec, keeping the old name as alias for some time;
wenzelm
parents:
36950
diff
changeset
|
166 |
structure SpecParse = Parse_Spec; |
338c3f8229e4
renamed structure SpecParse to Parse_Spec, keeping the old name as alias for some time;
wenzelm
parents:
36950
diff
changeset
|
167 |