| author | wenzelm |
| Thu, 02 Jul 2015 12:39:08 +0200 | |
| changeset 60630 | fc7625ec7427 |
| parent 60555 | 51a6997b1384 |
| child 61260 | e6f03fae14d5 |
| 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 thm_name: string -> Attrib.binding parser |
10 |
val opt_thm_name: string -> Attrib.binding parser |
|
|
30481
de003023c302
removed old named_spec, spec_name, spec_opt_name;
wenzelm
parents:
29601
diff
changeset
|
11 |
val spec: (Attrib.binding * string) parser |
|
de003023c302
removed old named_spec, spec_name, spec_opt_name;
wenzelm
parents:
29601
diff
changeset
|
12 |
val specs: (Attrib.binding * string list) parser |
|
de003023c302
removed old named_spec, spec_name, spec_opt_name;
wenzelm
parents:
29601
diff
changeset
|
13 |
val alt_specs: (Attrib.binding * string) list parser |
|
de003023c302
removed old named_spec, spec_name, spec_opt_name;
wenzelm
parents:
29601
diff
changeset
|
14 |
val where_alt_specs: (Attrib.binding * string) list parser |
|
58011
bc6bced136e5
tuned signature -- moved type src to Token, without aliases;
wenzelm
parents:
56945
diff
changeset
|
15 |
val name_facts: (Attrib.binding * (Facts.ref * Token.src list) list) list parser |
|
33287
0f99569d23e1
provide SpecParse.constdecl/constdef, e.g. for quotient_definition;
wenzelm
parents:
30726
diff
changeset
|
16 |
val constdecl: (binding * string option * mixfix) parser |
|
0f99569d23e1
provide SpecParse.constdecl/constdef, e.g. for quotient_definition;
wenzelm
parents:
30726
diff
changeset
|
17 |
val constdef: ((binding * string option * mixfix) option * (Attrib.binding * string)) parser |
|
47067
4ef29b0c568f
optional 'includes' element for long theorem statements;
wenzelm
parents:
46922
diff
changeset
|
18 |
val includes: (xstring * Position.T) list parser |
| 29581 | 19 |
val locale_fixes: (binding * string option * mixfix) list parser |
| 29312 | 20 |
val locale_insts: (string option list * (Attrib.binding * string) list) parser |
|
46922
3717f3878714
source positions for locale and class expressions;
wenzelm
parents:
45592
diff
changeset
|
21 |
val class_expression: string list parser |
|
49754
acafcac41690
more explicit namespace prefix for 'statespace' -- duplicate facts;
wenzelm
parents:
47067
diff
changeset
|
22 |
val locale_prefix: bool -> (string * bool) parser |
|
acafcac41690
more explicit namespace prefix for 'statespace' -- duplicate facts;
wenzelm
parents:
47067
diff
changeset
|
23 |
val locale_keyword: string parser |
| 30726 | 24 |
val locale_expression: bool -> Expression.expression parser |
| 29312 | 25 |
val context_element: Element.context parser |
26 |
val statement: (Attrib.binding * (string * string list) list) list parser |
|
| 60449 | 27 |
val if_statement: (Attrib.binding * (string * string list) list) list parser |
|
60555
51a6997b1384
support 'when' statement, which corresponds to 'presume';
wenzelm
parents:
60449
diff
changeset
|
28 |
val cond_statement: (bool * (Attrib.binding * (string * string list) list) list) parser |
| 60448 | 29 |
val obtains: Element.obtains parser |
| 29312 | 30 |
val general_statement: (Element.context list * Element.statement) parser |
31 |
val statement_keyword: string parser |
|
|
22104
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
wenzelm
parents:
diff
changeset
|
32 |
end; |
|
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
wenzelm
parents:
diff
changeset
|
33 |
|
|
36952
338c3f8229e4
renamed structure SpecParse to Parse_Spec, keeping the old name as alias for some time;
wenzelm
parents:
36950
diff
changeset
|
34 |
structure Parse_Spec: PARSE_SPEC = |
|
22104
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
wenzelm
parents:
diff
changeset
|
35 |
struct |
|
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
wenzelm
parents:
diff
changeset
|
36 |
|
|
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
wenzelm
parents:
diff
changeset
|
37 |
(* theorem specifications *) |
|
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
wenzelm
parents:
diff
changeset
|
38 |
|
|
58028
e4250d370657
tuned signature -- define some elementary operations earlier;
wenzelm
parents:
58011
diff
changeset
|
39 |
fun thm_name s = Parse.binding -- Parse.opt_attribs --| Parse.$$$ s; |
|
28083
103d9282a946
explicit type Name.binding for higher-specification elements;
wenzelm
parents:
27816
diff
changeset
|
40 |
|
|
22104
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
wenzelm
parents:
diff
changeset
|
41 |
fun opt_thm_name s = |
|
58028
e4250d370657
tuned signature -- define some elementary operations earlier;
wenzelm
parents:
58011
diff
changeset
|
42 |
Scan.optional |
|
e4250d370657
tuned signature -- define some elementary operations earlier;
wenzelm
parents:
58011
diff
changeset
|
43 |
((Parse.binding -- Parse.opt_attribs || Parse.attribs >> pair Binding.empty) --| Parse.$$$ s) |
| 28965 | 44 |
Attrib.empty_binding; |
|
22104
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
wenzelm
parents:
diff
changeset
|
45 |
|
| 36950 | 46 |
val spec = opt_thm_name ":" -- Parse.prop; |
47 |
val specs = opt_thm_name ":" -- Scan.repeat1 Parse.prop; |
|
|
22104
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
wenzelm
parents:
diff
changeset
|
48 |
|
|
30481
de003023c302
removed old named_spec, spec_name, spec_opt_name;
wenzelm
parents:
29601
diff
changeset
|
49 |
val alt_specs = |
| 36950 | 50 |
Parse.enum1 "|" |
51 |
(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
|
52 |
|
| 36950 | 53 |
val where_alt_specs = Parse.where_ |-- Parse.!!! alt_specs; |
|
22104
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
wenzelm
parents:
diff
changeset
|
54 |
|
|
58028
e4250d370657
tuned signature -- define some elementary operations earlier;
wenzelm
parents:
58011
diff
changeset
|
55 |
val name_facts = Parse.and_list1 (opt_thm_name "=" -- Parse.xthms1); |
|
22104
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
wenzelm
parents:
diff
changeset
|
56 |
|
|
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
wenzelm
parents:
diff
changeset
|
57 |
|
|
33287
0f99569d23e1
provide SpecParse.constdecl/constdef, e.g. for quotient_definition;
wenzelm
parents:
30726
diff
changeset
|
58 |
(* basic constant specifications *) |
|
0f99569d23e1
provide SpecParse.constdecl/constdef, e.g. for quotient_definition;
wenzelm
parents:
30726
diff
changeset
|
59 |
|
|
0f99569d23e1
provide SpecParse.constdecl/constdef, e.g. for quotient_definition;
wenzelm
parents:
30726
diff
changeset
|
60 |
val constdecl = |
| 36950 | 61 |
Parse.binding -- |
62 |
(Parse.where_ >> K (NONE, NoSyn) || |
|
63 |
Parse.$$$ "::" |-- Parse.!!! ((Parse.typ >> SOME) -- Parse.opt_mixfix' --| Parse.where_) || |
|
64 |
Scan.ahead (Parse.$$$ "(") |-- Parse.!!! (Parse.mixfix' --| Parse.where_ >> pair NONE))
|
|
65 |
>> Parse.triple2; |
|
|
33287
0f99569d23e1
provide SpecParse.constdecl/constdef, e.g. for quotient_definition;
wenzelm
parents:
30726
diff
changeset
|
66 |
|
| 36950 | 67 |
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
|
68 |
|
|
0f99569d23e1
provide SpecParse.constdecl/constdef, e.g. for quotient_definition;
wenzelm
parents:
30726
diff
changeset
|
69 |
|
|
22104
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
wenzelm
parents:
diff
changeset
|
70 |
(* locale and context elements *) |
|
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
wenzelm
parents:
diff
changeset
|
71 |
|
|
47067
4ef29b0c568f
optional 'includes' element for long theorem statements;
wenzelm
parents:
46922
diff
changeset
|
72 |
val includes = Parse.$$$ "includes" |-- Parse.!!! (Scan.repeat1 (Parse.position Parse.xname)); |
|
4ef29b0c568f
optional 'includes' element for long theorem statements;
wenzelm
parents:
46922
diff
changeset
|
73 |
|
|
22104
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
wenzelm
parents:
diff
changeset
|
74 |
val locale_fixes = |
|
51654
8450b944e58a
just one syntax category "mixfix" -- check structure annotation semantically;
wenzelm
parents:
49754
diff
changeset
|
75 |
Parse.and_list1 (Parse.binding -- Scan.option (Parse.$$$ "::" |-- Parse.typ) -- Parse.mixfix |
| 36950 | 76 |
>> (single o Parse.triple1) || |
| 60448 | 77 |
Parse.params) >> flat; |
|
22104
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
wenzelm
parents:
diff
changeset
|
78 |
|
|
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
wenzelm
parents:
diff
changeset
|
79 |
val locale_insts = |
| 36950 | 80 |
Scan.optional |
81 |
(Parse.$$$ "[" |-- Parse.!!! (Scan.repeat1 (Parse.maybe Parse.term) --| Parse.$$$ "]")) [] -- |
|
82 |
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
|
83 |
|
|
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
wenzelm
parents:
diff
changeset
|
84 |
local |
|
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
wenzelm
parents:
diff
changeset
|
85 |
|
|
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
wenzelm
parents:
diff
changeset
|
86 |
val loc_element = |
| 36950 | 87 |
Parse.$$$ "fixes" |-- Parse.!!! locale_fixes >> Element.Fixes || |
88 |
Parse.$$$ "constrains" |-- |
|
89 |
Parse.!!! (Parse.and_list1 (Parse.name -- (Parse.$$$ "::" |-- Parse.typ))) |
|
|
22104
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
wenzelm
parents:
diff
changeset
|
90 |
>> Element.Constrains || |
| 36950 | 91 |
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
|
92 |
>> Element.Assumes || |
| 36950 | 93 |
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
|
94 |
>> Element.Defines || |
|
58028
e4250d370657
tuned signature -- define some elementary operations earlier;
wenzelm
parents:
58011
diff
changeset
|
95 |
Parse.$$$ "notes" |-- Parse.!!! (Parse.and_list1 (opt_thm_name "=" -- Parse.xthms1)) |
|
22104
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
wenzelm
parents:
diff
changeset
|
96 |
>> (curry Element.Notes ""); |
|
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
wenzelm
parents:
diff
changeset
|
97 |
|
| 24869 | 98 |
fun plus1_unless test scan = |
| 36950 | 99 |
scan ::: Scan.repeat (Parse.$$$ "+" |-- Scan.unless test (Parse.!!! scan)); |
|
22104
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
wenzelm
parents:
diff
changeset
|
100 |
|
| 36950 | 101 |
val instance = Parse.where_ |-- |
102 |
Parse.and_list1 (Parse.name -- (Parse.$$$ "=" |-- Parse.term)) >> Expression.Named || |
|
103 |
Scan.repeat1 (Parse.maybe Parse.term) >> Expression.Positional; |
|
|
29033
721529248e31
Enable keyword 'structure' in for clause of locale expression.
ballarin
parents:
28965
diff
changeset
|
104 |
|
| 24869 | 105 |
in |
106 |
||
|
49754
acafcac41690
more explicit namespace prefix for 'statespace' -- duplicate facts;
wenzelm
parents:
47067
diff
changeset
|
107 |
fun locale_prefix mandatory = |
|
acafcac41690
more explicit namespace prefix for 'statespace' -- duplicate facts;
wenzelm
parents:
47067
diff
changeset
|
108 |
Scan.optional |
|
acafcac41690
more explicit namespace prefix for 'statespace' -- duplicate facts;
wenzelm
parents:
47067
diff
changeset
|
109 |
(Parse.name -- |
|
acafcac41690
more explicit namespace prefix for 'statespace' -- duplicate facts;
wenzelm
parents:
47067
diff
changeset
|
110 |
(Parse.$$$ "!" >> K true || Parse.$$$ "?" >> K false || Scan.succeed mandatory) --| |
|
acafcac41690
more explicit namespace prefix for 'statespace' -- duplicate facts;
wenzelm
parents:
47067
diff
changeset
|
111 |
Parse.$$$ ":") |
|
acafcac41690
more explicit namespace prefix for 'statespace' -- duplicate facts;
wenzelm
parents:
47067
diff
changeset
|
112 |
("", false);
|
|
acafcac41690
more explicit namespace prefix for 'statespace' -- duplicate facts;
wenzelm
parents:
47067
diff
changeset
|
113 |
|
| 36950 | 114 |
val locale_keyword = |
115 |
Parse.$$$ "fixes" || Parse.$$$ "constrains" || Parse.$$$ "assumes" || |
|
116 |
Parse.$$$ "defines" || Parse.$$$ "notes"; |
|
| 28722 | 117 |
|
|
46922
3717f3878714
source positions for locale and class expressions;
wenzelm
parents:
45592
diff
changeset
|
118 |
val class_expression = plus1_unless locale_keyword Parse.class; |
| 24869 | 119 |
|
| 30726 | 120 |
fun locale_expression mandatory = |
|
29033
721529248e31
Enable keyword 'structure' in for clause of locale expression.
ballarin
parents:
28965
diff
changeset
|
121 |
let |
|
46922
3717f3878714
source positions for locale and class expressions;
wenzelm
parents:
45592
diff
changeset
|
122 |
val expr2 = Parse.position Parse.xname; |
|
49754
acafcac41690
more explicit namespace prefix for 'statespace' -- duplicate facts;
wenzelm
parents:
47067
diff
changeset
|
123 |
val expr1 = locale_prefix mandatory -- expr2 -- |
| 30720 | 124 |
Scan.optional instance (Expression.Named []) >> (fn ((p, l), i) => (l, (p, i))); |
125 |
val expr0 = plus1_unless locale_keyword expr1; |
|
| 36950 | 126 |
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
|
127 |
|
| 44357 | 128 |
val context_element = Parse.group (fn () => "context element") loc_element; |
|
22104
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
wenzelm
parents:
diff
changeset
|
129 |
|
|
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
wenzelm
parents:
diff
changeset
|
130 |
end; |
|
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
wenzelm
parents:
diff
changeset
|
131 |
|
|
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
wenzelm
parents:
diff
changeset
|
132 |
|
|
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
wenzelm
parents:
diff
changeset
|
133 |
(* statements *) |
|
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
wenzelm
parents:
diff
changeset
|
134 |
|
| 36950 | 135 |
val statement = Parse.and_list1 (opt_thm_name ":" -- Scan.repeat1 Parse.propp); |
| 60449 | 136 |
val if_statement = Scan.optional (Parse.$$$ "if" |-- Parse.!!! statement) []; |
| 60414 | 137 |
|
|
60555
51a6997b1384
support 'when' statement, which corresponds to 'presume';
wenzelm
parents:
60449
diff
changeset
|
138 |
val cond_statement = |
|
51a6997b1384
support 'when' statement, which corresponds to 'presume';
wenzelm
parents:
60449
diff
changeset
|
139 |
Parse.$$$ "if" |-- Parse.!!! statement >> pair true || |
|
51a6997b1384
support 'when' statement, which corresponds to 'presume';
wenzelm
parents:
60449
diff
changeset
|
140 |
Parse.$$$ "when" |-- Parse.!!! statement >> pair false || |
|
51a6997b1384
support 'when' statement, which corresponds to 'presume';
wenzelm
parents:
60449
diff
changeset
|
141 |
Scan.succeed (true, []); |
|
51a6997b1384
support 'when' statement, which corresponds to 'presume';
wenzelm
parents:
60449
diff
changeset
|
142 |
|
|
22104
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
wenzelm
parents:
diff
changeset
|
143 |
val obtain_case = |
| 59784 | 144 |
Parse.parbinding -- |
| 60448 | 145 |
(Scan.optional (Parse.and_list1 Parse.fixes --| Parse.where_ >> flat) [] -- |
| 59784 | 146 |
(Parse.and_list1 (Scan.repeat1 Parse.prop) >> flat)); |
|
22104
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
wenzelm
parents:
diff
changeset
|
147 |
|
| 60448 | 148 |
val obtains = Parse.enum1 "|" obtain_case; |
149 |
||
|
22104
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
wenzelm
parents:
diff
changeset
|
150 |
val general_statement = |
|
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
wenzelm
parents:
diff
changeset
|
151 |
statement >> (fn x => ([], Element.Shows x)) || |
| 28722 | 152 |
Scan.repeat context_element -- |
| 60448 | 153 |
(Parse.$$$ "obtains" |-- Parse.!!! obtains >> Element.Obtains || |
| 36950 | 154 |
Parse.$$$ "shows" |-- Parse.!!! statement >> Element.Shows); |
|
22104
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
wenzelm
parents:
diff
changeset
|
155 |
|
| 36950 | 156 |
val statement_keyword = Parse.$$$ "obtains" || Parse.$$$ "shows"; |
|
22104
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
wenzelm
parents:
diff
changeset
|
157 |
|
|
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
wenzelm
parents:
diff
changeset
|
158 |
end; |