author | wenzelm |
Thu, 16 Jul 2009 20:32:05 +0200 | |
changeset 32018 | 3370cea95387 |
parent 29606 | fedb8be05f24 |
child 32466 | a393b7e2a2f8 |
permissions | -rw-r--r-- |
22106 | 1 |
(* Title: Pure/Thy/thy_header.ML |
2 |
Author: Markus Wenzel, TU Muenchen |
|
3 |
||
4 |
Theory headers -- independent of outer syntax. |
|
5 |
*) |
|
6 |
||
7 |
signature THY_HEADER = |
|
8 |
sig |
|
9 |
val args: OuterLex.token list -> |
|
10 |
(string * string list * (string * bool) list) * OuterLex.token list |
|
23863 | 11 |
val read: Position.T -> (string, 'a) Source.source -> string * string list * (string * bool) list |
22106 | 12 |
end; |
13 |
||
14 |
structure ThyHeader: THY_HEADER = |
|
15 |
struct |
|
16 |
||
17 |
structure T = OuterLex; |
|
18 |
structure P = OuterParse; |
|
19 |
||
20 |
||
21 |
(* keywords *) |
|
22 |
||
23 |
val headerN = "header"; |
|
24 |
val theoryN = "theory"; |
|
25 |
val importsN = "imports"; |
|
26 |
val usesN = "uses"; |
|
27 |
val beginN = "begin"; |
|
28 |
||
24577 | 29 |
val header_lexicon = Scan.make_lexicon |
30 |
(map Symbol.explode ["%", "(", ")", ";", beginN, headerN, importsN, theoryN, usesN]); |
|
22106 | 31 |
|
32 |
||
33 |
(* header args *) |
|
34 |
||
27890
62ac62e30ab1
args: explicit groups for file_name, theory_name;
wenzelm
parents:
27872
diff
changeset
|
35 |
val file_name = P.group "file name" P.name; |
62ac62e30ab1
args: explicit groups for file_name, theory_name;
wenzelm
parents:
27872
diff
changeset
|
36 |
val theory_name = P.group "theory name" P.name; |
62ac62e30ab1
args: explicit groups for file_name, theory_name;
wenzelm
parents:
27872
diff
changeset
|
37 |
|
62ac62e30ab1
args: explicit groups for file_name, theory_name;
wenzelm
parents:
27872
diff
changeset
|
38 |
val file = (P.$$$ "(" |-- P.!!! (file_name --| P.$$$ ")")) >> rpair false || file_name >> rpair true; |
22106 | 39 |
val uses = Scan.optional (P.$$$ usesN |-- P.!!! (Scan.repeat1 file)) []; |
40 |
||
41 |
val args = |
|
27890
62ac62e30ab1
args: explicit groups for file_name, theory_name;
wenzelm
parents:
27872
diff
changeset
|
42 |
theory_name -- (P.$$$ importsN |-- P.!!! (Scan.repeat1 theory_name -- uses --| P.$$$ beginN)) |
22106 | 43 |
>> P.triple2; |
44 |
||
45 |
||
46 |
(* read header *) |
|
47 |
||
48 |
val header = |
|
27872
631371a02b8c
P.doc_source and P.ml_sorce for proper SymbolPos.text;
wenzelm
parents:
27835
diff
changeset
|
49 |
(P.$$$ headerN -- P.tags) |-- (P.!!! (P.doc_source -- Scan.repeat P.semicolon -- |
22106 | 50 |
(P.$$$ theoryN -- P.tags) |-- args)) || |
51 |
(P.$$$ theoryN -- P.tags) |-- P.!!! args; |
|
52 |
||
23863 | 53 |
fun read pos src = |
22106 | 54 |
let val res = |
55 |
src |
|
27835
ff8b8513965a
Symbol.source/OuterLex.source: more explicit do_recover argument;
wenzelm
parents:
24739
diff
changeset
|
56 |
|> Symbol.source {do_recover = false} |
ff8b8513965a
Symbol.source/OuterLex.source: more explicit do_recover argument;
wenzelm
parents:
24739
diff
changeset
|
57 |
|> T.source {do_recover = NONE} (fn () => (header_lexicon, Scan.empty_lexicon)) pos |
22106 | 58 |
|> T.source_proper |
24739 | 59 |
|> Source.source T.stopper (Scan.single (Scan.error (P.!!! header))) NONE |
22106 | 60 |
|> Source.get_single; |
61 |
in |
|
62 |
(case res of SOME (x, _) => x |
|
63 |
| NONE => error ("Unexpected end of input" ^ Position.str_of pos)) |
|
64 |
end; |
|
65 |
||
66 |
end; |