| author | paulson | 
| Fri, 13 Nov 2009 11:34:05 +0000 | |
| changeset 33655 | c6dde2106128 | 
| parent 33287 | 0f99569d23e1 | 
| child 36950 | 75b8f26f2f07 | 
| permissions | -rw-r--r-- | 
| 22104 
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
 wenzelm parents: diff
changeset | 1 | (* Title: Pure/Isar/spec_parse.ML | 
| 
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 | |
| 
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
 wenzelm parents: diff
changeset | 7 | signature SPEC_PARSE = | 
| 
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: 
29601diff
changeset | 14 | val spec: (Attrib.binding * string) parser | 
| 
de003023c302
removed old named_spec, spec_name, spec_opt_name;
 wenzelm parents: 
29601diff
changeset | 15 | val specs: (Attrib.binding * string list) parser | 
| 
de003023c302
removed old named_spec, spec_name, spec_opt_name;
 wenzelm parents: 
29601diff
changeset | 16 | val alt_specs: (Attrib.binding * string) list parser | 
| 
de003023c302
removed old named_spec, spec_name, spec_opt_name;
 wenzelm parents: 
29601diff
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: 
30726diff
changeset | 21 | val constdecl: (binding * string option * mixfix) parser | 
| 
0f99569d23e1
provide SpecParse.constdecl/constdef, e.g. for quotient_definition;
 wenzelm parents: 
30726diff
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 | |
| 
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
 wenzelm parents: diff
changeset | 35 | structure SpecParse: SPEC_PARSE = | 
| 
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 | structure P = OuterParse; | 
| 
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
 wenzelm parents: diff
changeset | 39 | |
| 
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
 wenzelm parents: diff
changeset | 40 | |
| 
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
 wenzelm parents: diff
changeset | 41 | (* theorem specifications *) | 
| 
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
 wenzelm parents: diff
changeset | 42 | |
| 27816 
0dfed2f2822a
unified Args.T with OuterLex.token, renamed some operations;
 wenzelm parents: 
27378diff
changeset | 43 | val attrib = P.position ((P.keyword_ident_or_symbolic || P.xname) -- P.!!! Args.parse) >> Args.src; | 
| 24014 | 44 | val attribs = P.$$$ "[" |-- P.list attrib --| P.$$$ "]"; | 
| 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 | |
| 28083 
103d9282a946
explicit type Name.binding for higher-specification elements;
 wenzelm parents: 
27816diff
changeset | 47 | fun thm_name s = P.binding -- opt_attribs --| P.$$$ s; | 
| 
103d9282a946
explicit type Name.binding for higher-specification elements;
 wenzelm parents: 
27816diff
changeset | 48 | |
| 22104 
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
 wenzelm parents: diff
changeset | 49 | fun opt_thm_name s = | 
| 28965 | 50 | Scan.optional ((P.binding -- opt_attribs || attribs >> pair Binding.empty) --| P.$$$ s) | 
| 51 | Attrib.empty_binding; | |
| 22104 
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
 wenzelm parents: diff
changeset | 52 | |
| 30481 
de003023c302
removed old named_spec, spec_name, spec_opt_name;
 wenzelm parents: 
29601diff
changeset | 53 | val spec = opt_thm_name ":" -- P.prop; | 
| 
de003023c302
removed old named_spec, spec_name, spec_opt_name;
 wenzelm parents: 
29601diff
changeset | 54 | val specs = opt_thm_name ":" -- Scan.repeat1 P.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: 
29601diff
changeset | 56 | val alt_specs = | 
| 
de003023c302
removed old named_spec, spec_name, spec_opt_name;
 wenzelm parents: 
29601diff
changeset | 57 | P.enum1 "|" (spec --| Scan.option (Scan.ahead (P.name || P.$$$ "[") -- P.!!! (P.$$$ "|"))); | 
| 
de003023c302
removed old named_spec, spec_name, spec_opt_name;
 wenzelm parents: 
29601diff
changeset | 58 | |
| 
de003023c302
removed old named_spec, spec_name, spec_opt_name;
 wenzelm parents: 
29601diff
changeset | 59 | val where_alt_specs = P.where_ |-- P.!!! alt_specs; | 
| 22104 
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
 wenzelm parents: diff
changeset | 60 | |
| 24013 
3063a756611d
xthm: added [[declaration]] syntax (abbreviates dummy_thm [att]);
 wenzelm parents: 
23919diff
changeset | 61 | val xthm = | 
| 26361 | 62 | P.$$$ "[" |-- attribs --| P.$$$ "]" >> pair (Facts.named "") || | 
| 63 | (P.alt_string >> Facts.Fact || | |
| 27816 
0dfed2f2822a
unified Args.T with OuterLex.token, renamed some operations;
 wenzelm parents: 
27378diff
changeset | 64 | P.position P.xname -- Scan.option Attrib.thm_sel >> Facts.Named) -- opt_attribs; | 
| 24013 
3063a756611d
xthm: added [[declaration]] syntax (abbreviates dummy_thm [att]);
 wenzelm parents: 
23919diff
changeset | 65 | |
| 22104 
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
 wenzelm parents: diff
changeset | 66 | val xthms1 = Scan.repeat1 xthm; | 
| 
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
 wenzelm parents: diff
changeset | 67 | |
| 
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
 wenzelm parents: diff
changeset | 68 | val name_facts = P.and_list1 (opt_thm_name "=" -- xthms1); | 
| 
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
 wenzelm parents: diff
changeset | 69 | |
| 
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
 wenzelm parents: diff
changeset | 70 | |
| 33287 
0f99569d23e1
provide SpecParse.constdecl/constdef, e.g. for quotient_definition;
 wenzelm parents: 
30726diff
changeset | 71 | (* basic constant specifications *) | 
| 
0f99569d23e1
provide SpecParse.constdecl/constdef, e.g. for quotient_definition;
 wenzelm parents: 
30726diff
changeset | 72 | |
| 
0f99569d23e1
provide SpecParse.constdecl/constdef, e.g. for quotient_definition;
 wenzelm parents: 
30726diff
changeset | 73 | val constdecl = | 
| 
0f99569d23e1
provide SpecParse.constdecl/constdef, e.g. for quotient_definition;
 wenzelm parents: 
30726diff
changeset | 74 | P.binding -- | 
| 
0f99569d23e1
provide SpecParse.constdecl/constdef, e.g. for quotient_definition;
 wenzelm parents: 
30726diff
changeset | 75 | (P.where_ >> K (NONE, NoSyn) || | 
| 
0f99569d23e1
provide SpecParse.constdecl/constdef, e.g. for quotient_definition;
 wenzelm parents: 
30726diff
changeset | 76 | P.$$$ "::" |-- P.!!! ((P.typ >> SOME) -- P.opt_mixfix' --| P.where_) || | 
| 
0f99569d23e1
provide SpecParse.constdecl/constdef, e.g. for quotient_definition;
 wenzelm parents: 
30726diff
changeset | 77 |       Scan.ahead (P.$$$ "(") |-- P.!!! (P.mixfix' --| P.where_ >> pair NONE))
 | 
| 
0f99569d23e1
provide SpecParse.constdecl/constdef, e.g. for quotient_definition;
 wenzelm parents: 
30726diff
changeset | 78 | >> P.triple2; | 
| 
0f99569d23e1
provide SpecParse.constdecl/constdef, e.g. for quotient_definition;
 wenzelm parents: 
30726diff
changeset | 79 | |
| 
0f99569d23e1
provide SpecParse.constdecl/constdef, e.g. for quotient_definition;
 wenzelm parents: 
30726diff
changeset | 80 | val constdef = Scan.option constdecl -- (opt_thm_name ":" -- P.prop); | 
| 
0f99569d23e1
provide SpecParse.constdecl/constdef, e.g. for quotient_definition;
 wenzelm parents: 
30726diff
changeset | 81 | |
| 
0f99569d23e1
provide SpecParse.constdecl/constdef, e.g. for quotient_definition;
 wenzelm parents: 
30726diff
changeset | 82 | |
| 22104 
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
 wenzelm parents: diff
changeset | 83 | (* locale and context elements *) | 
| 
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
 wenzelm parents: diff
changeset | 84 | |
| 
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
 wenzelm parents: diff
changeset | 85 | val locale_mixfix = P.$$$ "(" -- P.$$$ "structure" -- P.!!! (P.$$$ ")") >> K Structure || P.mixfix;
 | 
| 
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
 wenzelm parents: diff
changeset | 86 | |
| 
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
 wenzelm parents: diff
changeset | 87 | val locale_fixes = | 
| 28083 
103d9282a946
explicit type Name.binding for higher-specification elements;
 wenzelm parents: 
27816diff
changeset | 88 | P.and_list1 (P.binding -- Scan.option (P.$$$ "::" |-- P.typ) -- locale_mixfix | 
| 22104 
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
 wenzelm parents: diff
changeset | 89 | >> (single o P.triple1) || | 
| 
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
 wenzelm parents: diff
changeset | 90 | P.params >> map Syntax.no_syn) >> flat; | 
| 
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
 wenzelm parents: diff
changeset | 91 | |
| 
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
 wenzelm parents: diff
changeset | 92 | val locale_insts = | 
| 22658 
263d42253f53
Experimental interpretation code for definitions.
 ballarin parents: 
22104diff
changeset | 93 | Scan.optional (P.$$$ "[" |-- P.!!! (Scan.repeat1 (P.maybe P.term) --| P.$$$ "]")) [] | 
| 30726 | 94 | -- Scan.optional (P.where_ |-- P.and_list1 (opt_thm_name ":" -- P.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 = | 
| 
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
 wenzelm parents: diff
changeset | 99 | P.$$$ "fixes" |-- P.!!! locale_fixes >> Element.Fixes || | 
| 
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
 wenzelm parents: diff
changeset | 100 | P.$$$ "constrains" |-- P.!!! (P.and_list1 (P.name -- (P.$$$ "::" |-- P.typ))) | 
| 
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
 wenzelm parents: diff
changeset | 101 | >> Element.Constrains || | 
| 
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
 wenzelm parents: diff
changeset | 102 | P.$$$ "assumes" |-- P.!!! (P.and_list1 (opt_thm_name ":" -- Scan.repeat1 P.propp)) | 
| 
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
 wenzelm parents: diff
changeset | 103 | >> Element.Assumes || | 
| 
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
 wenzelm parents: diff
changeset | 104 | P.$$$ "defines" |-- P.!!! (P.and_list1 (opt_thm_name ":" -- P.propp)) | 
| 
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
 wenzelm parents: diff
changeset | 105 | >> Element.Defines || | 
| 
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
 wenzelm parents: diff
changeset | 106 | P.$$$ "notes" |-- P.!!! (P.and_list1 (opt_thm_name "=" -- xthms1)) | 
| 
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
 wenzelm parents: diff
changeset | 107 | >> (curry Element.Notes ""); | 
| 
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
 wenzelm parents: diff
changeset | 108 | |
| 24869 | 109 | fun plus1_unless test scan = | 
| 25999 | 110 | scan ::: Scan.repeat (P.$$$ "+" |-- Scan.unless test (P.!!! scan)); | 
| 22104 
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
 wenzelm parents: diff
changeset | 111 | |
| 30726 | 112 | fun prefix mandatory = | 
| 113 | P.name -- (P.$$$ "!" >> K true || P.$$$ "?" >> K false || Scan.succeed mandatory) --| P.$$$ ":"; | |
| 22104 
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
 wenzelm parents: diff
changeset | 114 | |
| 30726 | 115 | val instance = P.where_ |-- | 
| 116 | P.and_list1 (P.name -- (P.$$$ "=" |-- P.term)) >> Expression.Named || | |
| 117 | Scan.repeat1 (P.maybe P.term) >> Expression.Positional; | |
| 29033 
721529248e31
Enable keyword 'structure' in for clause of locale expression.
 ballarin parents: 
28965diff
changeset | 118 | |
| 24869 | 119 | in | 
| 120 | ||
| 28722 | 121 | val locale_keyword = P.$$$ "fixes" || P.$$$ "constrains" || P.$$$ "assumes" || | 
| 122 | P.$$$ "defines" || P.$$$ "notes"; | |
| 123 | ||
| 124 | val class_expr = plus1_unless locale_keyword P.xname; | |
| 24869 | 125 | |
| 30726 | 126 | fun locale_expression mandatory = | 
| 29033 
721529248e31
Enable keyword 'structure' in for clause of locale expression.
 ballarin parents: 
28965diff
changeset | 127 | let | 
| 30720 | 128 | val expr2 = P.xname; | 
| 30726 | 129 |     val expr1 = Scan.optional (prefix mandatory) ("", false) -- expr2 --
 | 
| 30720 | 130 | Scan.optional instance (Expression.Named []) >> (fn ((p, l), i) => (l, (p, i))); | 
| 131 | val expr0 = plus1_unless locale_keyword expr1; | |
| 29033 
721529248e31
Enable keyword 'structure' in for clause of locale expression.
 ballarin parents: 
28965diff
changeset | 132 | in expr0 -- Scan.optional (P.$$$ "for" |-- P.!!! locale_fixes) [] end; | 
| 
721529248e31
Enable keyword 'structure' in for clause of locale expression.
 ballarin parents: 
28965diff
changeset | 133 | |
| 22104 
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
 wenzelm parents: diff
changeset | 134 | val context_element = P.group "context element" loc_element; | 
| 
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
 wenzelm parents: diff
changeset | 135 | |
| 
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
 wenzelm parents: diff
changeset | 136 | end; | 
| 
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
 wenzelm parents: diff
changeset | 137 | |
| 
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
 wenzelm parents: diff
changeset | 138 | |
| 
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
 wenzelm parents: diff
changeset | 139 | (* statements *) | 
| 
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
 wenzelm parents: diff
changeset | 140 | |
| 
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
 wenzelm parents: diff
changeset | 141 | val statement = P.and_list1 (opt_thm_name ":" -- Scan.repeat1 P.propp); | 
| 
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 | val obtain_case = | 
| 30726 | 144 | P.parbinding -- (Scan.optional (P.simple_fixes --| P.where_) [] -- | 
| 22104 
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
 wenzelm parents: diff
changeset | 145 | (P.and_list1 (Scan.repeat1 P.prop) >> flat)); | 
| 
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 general_statement = | 
| 
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
 wenzelm parents: diff
changeset | 148 | statement >> (fn x => ([], Element.Shows x)) || | 
| 28722 | 149 | Scan.repeat context_element -- | 
| 22104 
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
 wenzelm parents: diff
changeset | 150 | (P.$$$ "obtains" |-- P.!!! (P.enum1 "|" obtain_case) >> Element.Obtains || | 
| 
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
 wenzelm parents: diff
changeset | 151 | P.$$$ "shows" |-- P.!!! statement >> Element.Shows); | 
| 
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
 wenzelm parents: diff
changeset | 152 | |
| 
e8a1c88be824
Parsers for complex specifications (material from outer_parse.ML);
 wenzelm parents: diff
changeset | 153 | val statement_keyword = P.$$$ "obtains" || P.$$$ "shows"; | 
| 
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 | end; |