| author | paulson <lp15@cam.ac.uk> | 
| Wed, 25 Apr 2018 21:29:02 +0100 | |
| changeset 68041 | d45b78cb86cf | 
| parent 67722 | 012f1e8a1209 | 
| child 69349 | 7cef9e386ffe | 
| permissions | -rw-r--r-- | 
| 22106 | 1 | (* Title: Pure/Thy/thy_header.ML | 
| 46939 | 2 | Author: Makarius | 
| 22106 | 3 | |
| 46939 | 4 | Static theory header information. | 
| 22106 | 5 | *) | 
| 6 | ||
| 7 | signature THY_HEADER = | |
| 8 | sig | |
| 63429 | 9 | type keywords = ((string * Position.T) * Keyword.spec) list | 
| 46938 
cda018294515
some support for outer syntax keyword declarations within theory header;
 wenzelm parents: 
46737diff
changeset | 10 | type header = | 
| 48927 
ef462b5558eb
theory def/ref position reports, which enable hyperlinks etc.;
 wenzelm parents: 
48881diff
changeset | 11 |    {name: string * Position.T,
 | 
| 
ef462b5558eb
theory def/ref position reports, which enable hyperlinks etc.;
 wenzelm parents: 
48881diff
changeset | 12 | imports: (string * Position.T) list, | 
| 51294 
0850d43cb355
discontinued obsolete header "files" -- these are loaded explicitly after exploring dependencies;
 wenzelm parents: 
51293diff
changeset | 13 | keywords: keywords} | 
| 
0850d43cb355
discontinued obsolete header "files" -- these are loaded explicitly after exploring dependencies;
 wenzelm parents: 
51293diff
changeset | 14 | val make: string * Position.T -> (string * Position.T) list -> keywords -> header | 
| 59735 | 15 | val theoryN: string | 
| 58928 
23d0ffd48006
plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
 wenzelm parents: 
58924diff
changeset | 16 | val bootstrap_keywords: Keyword.keywords | 
| 
23d0ffd48006
plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
 wenzelm parents: 
58924diff
changeset | 17 | val add_keywords: keywords -> theory -> theory | 
| 
23d0ffd48006
plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
 wenzelm parents: 
58924diff
changeset | 18 | val get_keywords: theory -> Keyword.keywords | 
| 
23d0ffd48006
plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
 wenzelm parents: 
58924diff
changeset | 19 | val get_keywords': Proof.context -> Keyword.keywords | 
| 62895 
54c2abe7e9a4
treat ROOT.ML as theory with header "theory ML_Root imports ML_Bootstrap begin";
 wenzelm parents: 
62849diff
changeset | 20 | val ml_bootstrapN: string | 
| 62932 
db12de2367ca
support ROOT0.ML as well -- independently of ROOT.ML;
 wenzelm parents: 
62895diff
changeset | 21 | val ml_roots: string list | 
| 63022 | 22 | val bootstrap_thys: string list | 
| 66771 
925d10a7a610
clarified error for bad session-qualified imports;
 wenzelm parents: 
65999diff
changeset | 23 | val is_base_name: string -> bool | 
| 65452 | 24 | val import_name: string -> string | 
| 46938 
cda018294515
some support for outer syntax keyword declarations within theory header;
 wenzelm parents: 
46737diff
changeset | 25 | val args: header parser | 
| 67500 
dfde99d59f6e
tuned: prefer list operations over Source.source;
 wenzelm parents: 
67164diff
changeset | 26 | val read_tokens: Position.T -> Token.T list -> header | 
| 46938 
cda018294515
some support for outer syntax keyword declarations within theory header;
 wenzelm parents: 
46737diff
changeset | 27 | val read: Position.T -> string -> header | 
| 22106 | 28 | end; | 
| 29 | ||
| 32466 | 30 | structure Thy_Header: THY_HEADER = | 
| 22106 | 31 | struct | 
| 32 | ||
| 58928 
23d0ffd48006
plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
 wenzelm parents: 
58924diff
changeset | 33 | (** keyword declarations **) | 
| 
23d0ffd48006
plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
 wenzelm parents: 
58924diff
changeset | 34 | |
| 
23d0ffd48006
plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
 wenzelm parents: 
58924diff
changeset | 35 | (* header *) | 
| 
23d0ffd48006
plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
 wenzelm parents: 
58924diff
changeset | 36 | |
| 63429 | 37 | type keywords = ((string * Position.T) * Keyword.spec) list; | 
| 48874 
ff9cd47be39b
refined Thy_Load.check_thy: find more uses in body text, based on keywords;
 wenzelm parents: 
48864diff
changeset | 38 | |
| 46938 
cda018294515
some support for outer syntax keyword declarations within theory header;
 wenzelm parents: 
46737diff
changeset | 39 | type header = | 
| 48927 
ef462b5558eb
theory def/ref position reports, which enable hyperlinks etc.;
 wenzelm parents: 
48881diff
changeset | 40 |  {name: string * Position.T,
 | 
| 
ef462b5558eb
theory def/ref position reports, which enable hyperlinks etc.;
 wenzelm parents: 
48881diff
changeset | 41 | imports: (string * Position.T) list, | 
| 51294 
0850d43cb355
discontinued obsolete header "files" -- these are loaded explicitly after exploring dependencies;
 wenzelm parents: 
51293diff
changeset | 42 | keywords: keywords}; | 
| 46938 
cda018294515
some support for outer syntax keyword declarations within theory header;
 wenzelm parents: 
46737diff
changeset | 43 | |
| 51294 
0850d43cb355
discontinued obsolete header "files" -- these are loaded explicitly after exploring dependencies;
 wenzelm parents: 
51293diff
changeset | 44 | fun make name imports keywords : header = | 
| 
0850d43cb355
discontinued obsolete header "files" -- these are loaded explicitly after exploring dependencies;
 wenzelm parents: 
51293diff
changeset | 45 |   {name = name, imports = imports, keywords = keywords};
 | 
| 46938 
cda018294515
some support for outer syntax keyword declarations within theory header;
 wenzelm parents: 
46737diff
changeset | 46 | |
| 
cda018294515
some support for outer syntax keyword declarations within theory header;
 wenzelm parents: 
46737diff
changeset | 47 | |
| 58928 
23d0ffd48006
plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
 wenzelm parents: 
58924diff
changeset | 48 | (* bootstrap keywords *) | 
| 22106 | 49 | |
| 58868 
c5e1cce7ace3
uniform heading commands work in any context, even in theory header;
 wenzelm parents: 
58864diff
changeset | 50 | val chapterN = "chapter"; | 
| 
c5e1cce7ace3
uniform heading commands work in any context, even in theory header;
 wenzelm parents: 
58864diff
changeset | 51 | val sectionN = "section"; | 
| 
c5e1cce7ace3
uniform heading commands work in any context, even in theory header;
 wenzelm parents: 
58864diff
changeset | 52 | val subsectionN = "subsection"; | 
| 
c5e1cce7ace3
uniform heading commands work in any context, even in theory header;
 wenzelm parents: 
58864diff
changeset | 53 | val subsubsectionN = "subsubsection"; | 
| 61463 | 54 | val paragraphN = "paragraph"; | 
| 55 | val subparagraphN = "subparagraph"; | |
| 58999 
ed09ae4ea2d8
uniform treatment of all document markup commands: 'text' and 'txt' merely differ in LaTeX style;
 wenzelm parents: 
58932diff
changeset | 56 | val textN = "text"; | 
| 
ed09ae4ea2d8
uniform treatment of all document markup commands: 'text' and 'txt' merely differ in LaTeX style;
 wenzelm parents: 
58932diff
changeset | 57 | val txtN = "txt"; | 
| 
ed09ae4ea2d8
uniform treatment of all document markup commands: 'text' and 'txt' merely differ in LaTeX style;
 wenzelm parents: 
58932diff
changeset | 58 | val text_rawN = "text_raw"; | 
| 58868 
c5e1cce7ace3
uniform heading commands work in any context, even in theory header;
 wenzelm parents: 
58864diff
changeset | 59 | |
| 22106 | 60 | val theoryN = "theory"; | 
| 61 | val importsN = "imports"; | |
| 46938 
cda018294515
some support for outer syntax keyword declarations within theory header;
 wenzelm parents: 
46737diff
changeset | 62 | val keywordsN = "keywords"; | 
| 63579 | 63 | val abbrevsN = "abbrevs"; | 
| 22106 | 64 | val beginN = "begin"; | 
| 65 | ||
| 58928 
23d0ffd48006
plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
 wenzelm parents: 
58924diff
changeset | 66 | val bootstrap_keywords = | 
| 58903 | 67 | Keyword.empty_keywords | 
| 58928 
23d0ffd48006
plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
 wenzelm parents: 
58924diff
changeset | 68 | |> Keyword.add_keywords | 
| 64556 | 69 |     [(("%", \<^here>), Keyword.no_spec),
 | 
| 70 |      (("(", \<^here>), Keyword.no_spec),
 | |
| 71 |      ((")", \<^here>), Keyword.no_spec),
 | |
| 72 |      ((",", \<^here>), Keyword.no_spec),
 | |
| 73 |      (("::", \<^here>), Keyword.no_spec),
 | |
| 74 |      (("=", \<^here>), Keyword.no_spec),
 | |
| 75 |      (("and", \<^here>), Keyword.no_spec),
 | |
| 76 | ((beginN, \<^here>), Keyword.quasi_command_spec), | |
| 77 | ((importsN, \<^here>), Keyword.quasi_command_spec), | |
| 78 | ((keywordsN, \<^here>), Keyword.quasi_command_spec), | |
| 79 | ((abbrevsN, \<^here>), Keyword.quasi_command_spec), | |
| 67139 
8fe0aba577af
explicit tag for document commands: avoid implicit use of document_tags;
 wenzelm parents: 
67136diff
changeset | 80 | ((chapterN, \<^here>), Keyword.document_heading_spec), | 
| 
8fe0aba577af
explicit tag for document commands: avoid implicit use of document_tags;
 wenzelm parents: 
67136diff
changeset | 81 | ((sectionN, \<^here>), Keyword.document_heading_spec), | 
| 
8fe0aba577af
explicit tag for document commands: avoid implicit use of document_tags;
 wenzelm parents: 
67136diff
changeset | 82 | ((subsectionN, \<^here>), Keyword.document_heading_spec), | 
| 
8fe0aba577af
explicit tag for document commands: avoid implicit use of document_tags;
 wenzelm parents: 
67136diff
changeset | 83 | ((subsubsectionN, \<^here>), Keyword.document_heading_spec), | 
| 
8fe0aba577af
explicit tag for document commands: avoid implicit use of document_tags;
 wenzelm parents: 
67136diff
changeset | 84 | ((paragraphN, \<^here>), Keyword.document_heading_spec), | 
| 
8fe0aba577af
explicit tag for document commands: avoid implicit use of document_tags;
 wenzelm parents: 
67136diff
changeset | 85 | ((subparagraphN, \<^here>), Keyword.document_heading_spec), | 
| 
8fe0aba577af
explicit tag for document commands: avoid implicit use of document_tags;
 wenzelm parents: 
67136diff
changeset | 86 | ((textN, \<^here>), Keyword.document_body_spec), | 
| 
8fe0aba577af
explicit tag for document commands: avoid implicit use of document_tags;
 wenzelm parents: 
67136diff
changeset | 87 | ((txtN, \<^here>), Keyword.document_body_spec), | 
| 
8fe0aba577af
explicit tag for document commands: avoid implicit use of document_tags;
 wenzelm parents: 
67136diff
changeset | 88 | ((text_rawN, \<^here>), ((Keyword.document_raw, []), ["document"])), | 
| 64556 | 89 | ((theoryN, \<^here>), ((Keyword.thy_begin, []), ["theory"])), | 
| 90 |      (("ML", \<^here>), ((Keyword.thy_decl, []), ["ML"]))];
 | |
| 58928 
23d0ffd48006
plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
 wenzelm parents: 
58924diff
changeset | 91 | |
| 
23d0ffd48006
plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
 wenzelm parents: 
58924diff
changeset | 92 | |
| 
23d0ffd48006
plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
 wenzelm parents: 
58924diff
changeset | 93 | (* theory data *) | 
| 22106 | 94 | |
| 58928 
23d0ffd48006
plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
 wenzelm parents: 
58924diff
changeset | 95 | structure Data = Theory_Data | 
| 
23d0ffd48006
plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
 wenzelm parents: 
58924diff
changeset | 96 | ( | 
| 
23d0ffd48006
plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
 wenzelm parents: 
58924diff
changeset | 97 | type T = Keyword.keywords; | 
| 
23d0ffd48006
plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
 wenzelm parents: 
58924diff
changeset | 98 | val empty = bootstrap_keywords; | 
| 
23d0ffd48006
plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
 wenzelm parents: 
58924diff
changeset | 99 | val extend = I; | 
| 
23d0ffd48006
plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
 wenzelm parents: 
58924diff
changeset | 100 | val merge = Keyword.merge_keywords; | 
| 
23d0ffd48006
plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
 wenzelm parents: 
58924diff
changeset | 101 | ); | 
| 
23d0ffd48006
plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
 wenzelm parents: 
58924diff
changeset | 102 | |
| 
23d0ffd48006
plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
 wenzelm parents: 
58924diff
changeset | 103 | val add_keywords = Data.map o Keyword.add_keywords; | 
| 
23d0ffd48006
plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
 wenzelm parents: 
58924diff
changeset | 104 | |
| 
23d0ffd48006
plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
 wenzelm parents: 
58924diff
changeset | 105 | val get_keywords = Data.get; | 
| 
23d0ffd48006
plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
 wenzelm parents: 
58924diff
changeset | 106 | val get_keywords' = get_keywords o Proof_Context.theory_of; | 
| 
23d0ffd48006
plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
 wenzelm parents: 
58924diff
changeset | 107 | |
| 
23d0ffd48006
plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
 wenzelm parents: 
58924diff
changeset | 108 | |
| 
23d0ffd48006
plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
 wenzelm parents: 
58924diff
changeset | 109 | |
| 
23d0ffd48006
plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
 wenzelm parents: 
58924diff
changeset | 110 | (** concrete syntax **) | 
| 22106 | 111 | |
| 62895 
54c2abe7e9a4
treat ROOT.ML as theory with header "theory ML_Root imports ML_Bootstrap begin";
 wenzelm parents: 
62849diff
changeset | 112 | (* names *) | 
| 
54c2abe7e9a4
treat ROOT.ML as theory with header "theory ML_Root imports ML_Bootstrap begin";
 wenzelm parents: 
62849diff
changeset | 113 | |
| 
54c2abe7e9a4
treat ROOT.ML as theory with header "theory ML_Root imports ML_Bootstrap begin";
 wenzelm parents: 
62849diff
changeset | 114 | val ml_bootstrapN = "ML_Bootstrap"; | 
| 62932 
db12de2367ca
support ROOT0.ML as well -- independently of ROOT.ML;
 wenzelm parents: 
62895diff
changeset | 115 | val ml_roots = ["ML_Root0", "ML_Root"]; | 
| 63022 | 116 | val bootstrap_thys = ["Bootstrap_Pure", "Bootstrap_ML_Bootstrap"]; | 
| 62932 
db12de2367ca
support ROOT0.ML as well -- independently of ROOT.ML;
 wenzelm parents: 
62895diff
changeset | 117 | |
| 66771 
925d10a7a610
clarified error for bad session-qualified imports;
 wenzelm parents: 
65999diff
changeset | 118 | fun is_base_name s = | 
| 
925d10a7a610
clarified error for bad session-qualified imports;
 wenzelm parents: 
65999diff
changeset | 119 | s <> "" andalso not (exists_string (member (op =) ["/", "\\", ":"]) s) | 
| 
925d10a7a610
clarified error for bad session-qualified imports;
 wenzelm parents: 
65999diff
changeset | 120 | |
| 67164 | 121 | fun import_name s = | 
| 122 | if String.isSuffix ".thy" s then | |
| 123 |     error ("Malformed theory import: " ^ quote s)
 | |
| 124 | else Path.base_name (Path.explode s); | |
| 62895 
54c2abe7e9a4
treat ROOT.ML as theory with header "theory ML_Root imports ML_Bootstrap begin";
 wenzelm parents: 
62849diff
changeset | 125 | |
| 
54c2abe7e9a4
treat ROOT.ML as theory with header "theory ML_Root imports ML_Bootstrap begin";
 wenzelm parents: 
62849diff
changeset | 126 | |
| 22106 | 127 | (* header args *) | 
| 128 | ||
| 46938 
cda018294515
some support for outer syntax keyword declarations within theory header;
 wenzelm parents: 
46737diff
changeset | 129 | local | 
| 
cda018294515
some support for outer syntax keyword declarations within theory header;
 wenzelm parents: 
46737diff
changeset | 130 | |
| 59694 | 131 | fun imports name = | 
| 132 | if name = Context.PureN then Scan.succeed [] | |
| 62969 | 133 | else Parse.$$$ importsN |-- Parse.!!! (Scan.repeat1 (Parse.position Parse.theory_name)); | 
| 53962 
65bca53daf70
more robust parser: 'imports' are mandatory except for bootstrapping Pure;
 wenzelm parents: 
51627diff
changeset | 134 | |
| 48864 
3ee314ae1e0a
added keyword kind "thy_load" (with optional list of file extensions);
 wenzelm parents: 
48707diff
changeset | 135 | val opt_files = | 
| 
3ee314ae1e0a
added keyword kind "thy_load" (with optional list of file extensions);
 wenzelm parents: 
48707diff
changeset | 136 |   Scan.optional (Parse.$$$ "(" |-- Parse.!!! (Parse.list1 Parse.name) --| Parse.$$$ ")") [];
 | 
| 50128 
599c935aac82
alternative completion for outer syntax keywords;
 wenzelm parents: 
48992diff
changeset | 137 | |
| 48864 
3ee314ae1e0a
added keyword kind "thy_load" (with optional list of file extensions);
 wenzelm parents: 
48707diff
changeset | 138 | val keyword_spec = | 
| 
3ee314ae1e0a
added keyword kind "thy_load" (with optional list of file extensions);
 wenzelm parents: 
48707diff
changeset | 139 | Parse.group (fn () => "outer syntax keyword specification") | 
| 
3ee314ae1e0a
added keyword kind "thy_load" (with optional list of file extensions);
 wenzelm parents: 
48707diff
changeset | 140 | (Parse.name -- opt_files -- Parse.tags); | 
| 
3ee314ae1e0a
added keyword kind "thy_load" (with optional list of file extensions);
 wenzelm parents: 
48707diff
changeset | 141 | |
| 46939 | 142 | val keyword_decl = | 
| 59934 
b65c4370f831
more position information and PIDE markup for command keywords;
 wenzelm parents: 
59735diff
changeset | 143 | Scan.repeat1 (Parse.position Parse.string) -- | 
| 63579 | 144 | Scan.optional (Parse.$$$ "::" |-- Parse.!!! keyword_spec) Keyword.no_spec | 
| 145 | >> (fn (names, spec) => map (rpair spec) names); | |
| 146 | ||
| 67722 
012f1e8a1209
allow multiple entries of and_list (on both sides);
 wenzelm parents: 
67500diff
changeset | 147 | val abbrevs = | 
| 
012f1e8a1209
allow multiple entries of and_list (on both sides);
 wenzelm parents: 
67500diff
changeset | 148 | Parse.and_list1 | 
| 
012f1e8a1209
allow multiple entries of and_list (on both sides);
 wenzelm parents: 
67500diff
changeset | 149 | (Scan.repeat1 Parse.text -- (Parse.$$$ "=" |-- Parse.!!! (Scan.repeat1 Parse.text)) | 
| 
012f1e8a1209
allow multiple entries of and_list (on both sides);
 wenzelm parents: 
67500diff
changeset | 150 | >> uncurry (map_product pair)) >> flat; | 
| 50128 
599c935aac82
alternative completion for outer syntax keywords;
 wenzelm parents: 
48992diff
changeset | 151 | |
| 46939 | 152 | val keyword_decls = Parse.and_list1 keyword_decl >> flat; | 
| 46938 
cda018294515
some support for outer syntax keyword declarations within theory header;
 wenzelm parents: 
46737diff
changeset | 153 | |
| 
cda018294515
some support for outer syntax keyword declarations within theory header;
 wenzelm parents: 
46737diff
changeset | 154 | in | 
| 22106 | 155 | |
| 156 | val args = | |
| 59693 | 157 | Parse.position Parse.theory_name :|-- (fn (name, pos) => | 
| 59694 | 158 | imports name -- | 
| 53962 
65bca53daf70
more robust parser: 'imports' are mandatory except for bootstrapping Pure;
 wenzelm parents: 
51627diff
changeset | 159 | Scan.optional (Parse.$$$ keywordsN |-- Parse.!!! keyword_decls) [] --| | 
| 63579 | 160 | (Scan.optional (Parse.$$$ abbrevsN |-- Parse.!!! abbrevs) [] -- Parse.$$$ beginN) | 
| 161 | >> (fn (imports, keywords) => make (name, pos) imports keywords)); | |
| 46938 
cda018294515
some support for outer syntax keyword declarations within theory header;
 wenzelm parents: 
46737diff
changeset | 162 | |
| 
cda018294515
some support for outer syntax keyword declarations within theory header;
 wenzelm parents: 
46737diff
changeset | 163 | end; | 
| 22106 | 164 | |
| 165 | ||
| 166 | (* read header *) | |
| 167 | ||
| 58868 
c5e1cce7ace3
uniform heading commands work in any context, even in theory header;
 wenzelm parents: 
58864diff
changeset | 168 | val heading = | 
| 67136 | 169 | (Parse.command_name chapterN || | 
| 170 | Parse.command_name sectionN || | |
| 171 | Parse.command_name subsectionN || | |
| 172 | Parse.command_name subsubsectionN || | |
| 173 | Parse.command_name paragraphN || | |
| 174 | Parse.command_name subparagraphN || | |
| 175 | Parse.command_name textN || | |
| 176 | Parse.command_name txtN || | |
| 177 | Parse.command_name text_rawN) -- | |
| 58868 
c5e1cce7ace3
uniform heading commands work in any context, even in theory header;
 wenzelm parents: 
58864diff
changeset | 178 | Parse.tags -- Parse.!!! Parse.document_source; | 
| 
c5e1cce7ace3
uniform heading commands work in any context, even in theory header;
 wenzelm parents: 
58864diff
changeset | 179 | |
| 67500 
dfde99d59f6e
tuned: prefer list operations over Source.source;
 wenzelm parents: 
67164diff
changeset | 180 | val parse_header = | 
| 67136 | 181 | (Scan.repeat heading -- Parse.command_name theoryN -- Parse.tags) |-- Parse.!!! args; | 
| 22106 | 182 | |
| 67500 
dfde99d59f6e
tuned: prefer list operations over Source.source;
 wenzelm parents: 
67164diff
changeset | 183 | fun read_tokens pos toks = | 
| 
dfde99d59f6e
tuned: prefer list operations over Source.source;
 wenzelm parents: 
67164diff
changeset | 184 | filter Token.is_proper toks | 
| 
dfde99d59f6e
tuned: prefer list operations over Source.source;
 wenzelm parents: 
67164diff
changeset | 185 | |> Source.of_list | 
| 
dfde99d59f6e
tuned: prefer list operations over Source.source;
 wenzelm parents: 
67164diff
changeset | 186 | |> Source.source Token.stopper (Scan.single (Scan.error (Parse.!!! parse_header))) | 
| 
dfde99d59f6e
tuned: prefer list operations over Source.source;
 wenzelm parents: 
67164diff
changeset | 187 | |> Source.get_single | 
| 
dfde99d59f6e
tuned: prefer list operations over Source.source;
 wenzelm parents: 
67164diff
changeset | 188 |   |> (fn SOME (header, _) => header | NONE => error ("Unexpected end of input" ^ Position.here pos));
 | 
| 
dfde99d59f6e
tuned: prefer list operations over Source.source;
 wenzelm parents: 
67164diff
changeset | 189 | |
| 
dfde99d59f6e
tuned: prefer list operations over Source.source;
 wenzelm parents: 
67164diff
changeset | 190 | local | 
| 48927 
ef462b5558eb
theory def/ref position reports, which enable hyperlinks etc.;
 wenzelm parents: 
48881diff
changeset | 191 | |
| 67500 
dfde99d59f6e
tuned: prefer list operations over Source.source;
 wenzelm parents: 
67164diff
changeset | 192 | fun read_header pos text = | 
| 
dfde99d59f6e
tuned: prefer list operations over Source.source;
 wenzelm parents: 
67164diff
changeset | 193 | Symbol_Pos.explode (text, pos) | 
| 
dfde99d59f6e
tuned: prefer list operations over Source.source;
 wenzelm parents: 
67164diff
changeset | 194 |   |> Token.tokenize bootstrap_keywords {strict = false}
 | 
| 
dfde99d59f6e
tuned: prefer list operations over Source.source;
 wenzelm parents: 
67164diff
changeset | 195 | |> read_tokens pos; | 
| 
dfde99d59f6e
tuned: prefer list operations over Source.source;
 wenzelm parents: 
67164diff
changeset | 196 | |
| 
dfde99d59f6e
tuned: prefer list operations over Source.source;
 wenzelm parents: 
67164diff
changeset | 197 | val approx_length = 1024; | 
| 22106 | 198 | |
| 67500 
dfde99d59f6e
tuned: prefer list operations over Source.source;
 wenzelm parents: 
67164diff
changeset | 199 | in | 
| 
dfde99d59f6e
tuned: prefer list operations over Source.source;
 wenzelm parents: 
67164diff
changeset | 200 | |
| 
dfde99d59f6e
tuned: prefer list operations over Source.source;
 wenzelm parents: 
67164diff
changeset | 201 | fun read pos text = | 
| 
dfde99d59f6e
tuned: prefer list operations over Source.source;
 wenzelm parents: 
67164diff
changeset | 202 | if size text <= approx_length then read_header pos text | 
| 
dfde99d59f6e
tuned: prefer list operations over Source.source;
 wenzelm parents: 
67164diff
changeset | 203 | else | 
| 
dfde99d59f6e
tuned: prefer list operations over Source.source;
 wenzelm parents: 
67164diff
changeset | 204 | let val approx_text = String.substring (text, 0, approx_length) in | 
| 
dfde99d59f6e
tuned: prefer list operations over Source.source;
 wenzelm parents: 
67164diff
changeset | 205 | if String.isSuffix "begin" approx_text then read_header pos text | 
| 
dfde99d59f6e
tuned: prefer list operations over Source.source;
 wenzelm parents: 
67164diff
changeset | 206 | else (read_header pos approx_text handle ERROR _ => read_header pos text) | 
| 
dfde99d59f6e
tuned: prefer list operations over Source.source;
 wenzelm parents: 
67164diff
changeset | 207 | end; | 
| 48927 
ef462b5558eb
theory def/ref position reports, which enable hyperlinks etc.;
 wenzelm parents: 
48881diff
changeset | 208 | |
| 22106 | 209 | end; | 
| 67500 
dfde99d59f6e
tuned: prefer list operations over Source.source;
 wenzelm parents: 
67164diff
changeset | 210 | |
| 
dfde99d59f6e
tuned: prefer list operations over Source.source;
 wenzelm parents: 
67164diff
changeset | 211 | end; |