author | wenzelm |
Sat, 19 Nov 2011 21:18:38 +0100 | |
changeset 45592 | 8baa0b7f3f66 |
parent 44357 | 5f5649ac8235 |
child 46922 | 3717f3878714 |
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 attribs: Attrib.src list parser |
10 |
val opt_attribs: Attrib.src list parser |
|
11 |
val thm_name: string -> Attrib.binding parser |
|
12 |
val opt_thm_name: string -> Attrib.binding parser |
|
30481
de003023c302
removed old named_spec, spec_name, spec_opt_name;
wenzelm
parents:
29601
diff
changeset
|
13 |
val spec: (Attrib.binding * string) parser |
de003023c302
removed old named_spec, spec_name, spec_opt_name;
wenzelm
parents:
29601
diff
changeset
|
14 |
val specs: (Attrib.binding * string list) parser |
de003023c302
removed old named_spec, spec_name, spec_opt_name;
wenzelm
parents:
29601
diff
changeset
|
15 |
val alt_specs: (Attrib.binding * string) list parser |
de003023c302
removed old named_spec, spec_name, spec_opt_name;
wenzelm
parents:
29601
diff
changeset
|
16 |
val where_alt_specs: (Attrib.binding * string) list parser |
29312 | 17 |
val xthm: (Facts.ref * Attrib.src list) parser |
18 |
val xthms1: (Facts.ref * Attrib.src list) list parser |
|
19 |
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
|
20 |
val constdecl: (binding * string option * mixfix) parser |
0f99569d23e1
provide SpecParse.constdecl/constdef, e.g. for quotient_definition;
wenzelm
parents:
30726
diff
changeset
|
21 |
val constdef: ((binding * string option * mixfix) option * (Attrib.binding * string)) parser |
29312 | 22 |
val locale_mixfix: mixfix parser |
29581 | 23 |
val locale_fixes: (binding * string option * mixfix) list parser |
29312 | 24 |
val locale_insts: (string option list * (Attrib.binding * string) list) parser |
25 |
val class_expr: string list parser |
|
30726 | 26 |
val locale_expression: bool -> Expression.expression parser |
29312 | 27 |
val locale_keyword: string parser |
28 |
val context_element: Element.context parser |
|
29 |
val statement: (Attrib.binding * (string * string list) list) list parser |
|
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 |
|
40800
330eb65c9469
Parse.liberal_name for document antiquotations and attributes;
wenzelm
parents:
40793
diff
changeset
|
39 |
val attrib = Parse.position (Parse.liberal_name -- Parse.!!! Args.parse) >> Args.src; |
36950 | 40 |
val attribs = Parse.$$$ "[" |-- Parse.list attrib --| Parse.$$$ "]"; |
22104
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
wenzelm
parents:
diff
changeset
|
41 |
val opt_attribs = Scan.optional attribs []; |
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
wenzelm
parents:
diff
changeset
|
42 |
|
36950 | 43 |
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
|
44 |
|
22104
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
wenzelm
parents:
diff
changeset
|
45 |
fun opt_thm_name s = |
36950 | 46 |
Scan.optional ((Parse.binding -- opt_attribs || attribs >> pair Binding.empty) --| Parse.$$$ s) |
28965 | 47 |
Attrib.empty_binding; |
22104
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
wenzelm
parents:
diff
changeset
|
48 |
|
36950 | 49 |
val spec = opt_thm_name ":" -- Parse.prop; |
50 |
val specs = opt_thm_name ":" -- Scan.repeat1 Parse.prop; |
|
22104
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
wenzelm
parents:
diff
changeset
|
51 |
|
30481
de003023c302
removed old named_spec, spec_name, spec_opt_name;
wenzelm
parents:
29601
diff
changeset
|
52 |
val alt_specs = |
36950 | 53 |
Parse.enum1 "|" |
54 |
(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
|
55 |
|
36950 | 56 |
val where_alt_specs = Parse.where_ |-- Parse.!!! alt_specs; |
22104
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
wenzelm
parents:
diff
changeset
|
57 |
|
24013
3063a756611d
xthm: added [[declaration]] syntax (abbreviates dummy_thm [att]);
wenzelm
parents:
23919
diff
changeset
|
58 |
val xthm = |
36950 | 59 |
Parse.$$$ "[" |-- attribs --| Parse.$$$ "]" >> pair (Facts.named "") || |
40793
d21aedaa91e7
added Parse.literal_fact with proper inner_syntax markup (source position);
wenzelm
parents:
36955
diff
changeset
|
60 |
(Parse.literal_fact >> Facts.Fact || |
36950 | 61 |
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
|
62 |
|
22104
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
wenzelm
parents:
diff
changeset
|
63 |
val xthms1 = Scan.repeat1 xthm; |
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
wenzelm
parents:
diff
changeset
|
64 |
|
36950 | 65 |
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
|
66 |
|
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
wenzelm
parents:
diff
changeset
|
67 |
|
33287
0f99569d23e1
provide SpecParse.constdecl/constdef, e.g. for quotient_definition;
wenzelm
parents:
30726
diff
changeset
|
68 |
(* basic constant specifications *) |
0f99569d23e1
provide SpecParse.constdecl/constdef, e.g. for quotient_definition;
wenzelm
parents:
30726
diff
changeset
|
69 |
|
0f99569d23e1
provide SpecParse.constdecl/constdef, e.g. for quotient_definition;
wenzelm
parents:
30726
diff
changeset
|
70 |
val constdecl = |
36950 | 71 |
Parse.binding -- |
72 |
(Parse.where_ >> K (NONE, NoSyn) || |
|
73 |
Parse.$$$ "::" |-- Parse.!!! ((Parse.typ >> SOME) -- Parse.opt_mixfix' --| Parse.where_) || |
|
74 |
Scan.ahead (Parse.$$$ "(") |-- Parse.!!! (Parse.mixfix' --| Parse.where_ >> pair NONE)) |
|
75 |
>> Parse.triple2; |
|
33287
0f99569d23e1
provide SpecParse.constdecl/constdef, e.g. for quotient_definition;
wenzelm
parents:
30726
diff
changeset
|
76 |
|
36950 | 77 |
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
|
78 |
|
0f99569d23e1
provide SpecParse.constdecl/constdef, e.g. for quotient_definition;
wenzelm
parents:
30726
diff
changeset
|
79 |
|
22104
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
wenzelm
parents:
diff
changeset
|
80 |
(* locale and context elements *) |
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
wenzelm
parents:
diff
changeset
|
81 |
|
36950 | 82 |
val locale_mixfix = |
83 |
Parse.$$$ "(" -- Parse.$$$ "structure" -- Parse.!!! (Parse.$$$ ")") >> K Structure || |
|
84 |
Parse.mixfix; |
|
22104
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 locale_fixes = |
36950 | 87 |
Parse.and_list1 (Parse.binding -- Scan.option (Parse.$$$ "::" |-- Parse.typ) -- locale_mixfix |
88 |
>> (single o Parse.triple1) || |
|
42287
d98eb048a2e4
discontinued special treatment of structure Mixfix;
wenzelm
parents:
40800
diff
changeset
|
89 |
Parse.params >> map (fn (x, y) => (x, y, NoSyn))) >> flat; |
22104
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
wenzelm
parents:
diff
changeset
|
90 |
|
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
wenzelm
parents:
diff
changeset
|
91 |
val locale_insts = |
36950 | 92 |
Scan.optional |
93 |
(Parse.$$$ "[" |-- Parse.!!! (Scan.repeat1 (Parse.maybe Parse.term) --| Parse.$$$ "]")) [] -- |
|
94 |
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
|
95 |
|
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
wenzelm
parents:
diff
changeset
|
96 |
local |
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
wenzelm
parents:
diff
changeset
|
97 |
|
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
wenzelm
parents:
diff
changeset
|
98 |
val loc_element = |
36950 | 99 |
Parse.$$$ "fixes" |-- Parse.!!! locale_fixes >> Element.Fixes || |
100 |
Parse.$$$ "constrains" |-- |
|
101 |
Parse.!!! (Parse.and_list1 (Parse.name -- (Parse.$$$ "::" |-- Parse.typ))) |
|
22104
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
wenzelm
parents:
diff
changeset
|
102 |
>> Element.Constrains || |
36950 | 103 |
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
|
104 |
>> Element.Assumes || |
36950 | 105 |
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
|
106 |
>> Element.Defines || |
36950 | 107 |
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
|
108 |
>> (curry Element.Notes ""); |
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
wenzelm
parents:
diff
changeset
|
109 |
|
24869 | 110 |
fun plus1_unless test scan = |
36950 | 111 |
scan ::: Scan.repeat (Parse.$$$ "+" |-- Scan.unless test (Parse.!!! scan)); |
22104
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
wenzelm
parents:
diff
changeset
|
112 |
|
30726 | 113 |
fun prefix mandatory = |
36950 | 114 |
Parse.name -- |
115 |
(Parse.$$$ "!" >> K true || Parse.$$$ "?" >> K false || Scan.succeed mandatory) --| |
|
116 |
Parse.$$$ ":"; |
|
22104
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
wenzelm
parents:
diff
changeset
|
117 |
|
36950 | 118 |
val instance = Parse.where_ |-- |
119 |
Parse.and_list1 (Parse.name -- (Parse.$$$ "=" |-- Parse.term)) >> Expression.Named || |
|
120 |
Scan.repeat1 (Parse.maybe Parse.term) >> Expression.Positional; |
|
29033
721529248e31
Enable keyword 'structure' in for clause of locale expression.
ballarin
parents:
28965
diff
changeset
|
121 |
|
24869 | 122 |
in |
123 |
||
36950 | 124 |
val locale_keyword = |
125 |
Parse.$$$ "fixes" || Parse.$$$ "constrains" || Parse.$$$ "assumes" || |
|
126 |
Parse.$$$ "defines" || Parse.$$$ "notes"; |
|
28722 | 127 |
|
36950 | 128 |
val class_expr = plus1_unless locale_keyword Parse.xname; |
24869 | 129 |
|
30726 | 130 |
fun locale_expression mandatory = |
29033
721529248e31
Enable keyword 'structure' in for clause of locale expression.
ballarin
parents:
28965
diff
changeset
|
131 |
let |
36950 | 132 |
val expr2 = Parse.xname; |
30726 | 133 |
val expr1 = Scan.optional (prefix mandatory) ("", false) -- expr2 -- |
30720 | 134 |
Scan.optional instance (Expression.Named []) >> (fn ((p, l), i) => (l, (p, i))); |
135 |
val expr0 = plus1_unless locale_keyword expr1; |
|
36950 | 136 |
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
|
137 |
|
44357 | 138 |
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
|
139 |
|
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
wenzelm
parents:
diff
changeset
|
140 |
end; |
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
wenzelm
parents:
diff
changeset
|
141 |
|
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
wenzelm
parents:
diff
changeset
|
142 |
|
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
wenzelm
parents:
diff
changeset
|
143 |
(* statements *) |
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
wenzelm
parents:
diff
changeset
|
144 |
|
36950 | 145 |
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
|
146 |
|
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
wenzelm
parents:
diff
changeset
|
147 |
val obtain_case = |
36950 | 148 |
Parse.parbinding -- (Scan.optional (Parse.simple_fixes --| Parse.where_) [] -- |
149 |
(Parse.and_list1 (Scan.repeat1 Parse.prop) >> flat)); |
|
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 general_statement = |
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
wenzelm
parents:
diff
changeset
|
152 |
statement >> (fn x => ([], Element.Shows x)) || |
28722 | 153 |
Scan.repeat context_element -- |
36950 | 154 |
(Parse.$$$ "obtains" |-- Parse.!!! (Parse.enum1 "|" obtain_case) >> Element.Obtains || |
155 |
Parse.$$$ "shows" |-- Parse.!!! statement >> Element.Shows); |
|
22104
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
wenzelm
parents:
diff
changeset
|
156 |
|
36950 | 157 |
val statement_keyword = Parse.$$$ "obtains" || Parse.$$$ "shows"; |
22104
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
wenzelm
parents:
diff
changeset
|
158 |
|
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
wenzelm
parents:
diff
changeset
|
159 |
end; |
36952
338c3f8229e4
renamed structure SpecParse to Parse_Spec, keeping the old name as alias for some time;
wenzelm
parents:
36950
diff
changeset
|
160 |