-
Notifications
You must be signed in to change notification settings - Fork 5
/
abbot.sml
71 lines (65 loc) · 2.29 KB
/
abbot.sml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
structure Abbot = struct
fun genFromFile
(fromFile : string,
namePartsOpt : string list option,
toDir : string,
toFileOpt : string option) =
let
val () = print "Parsing...\n"
val parse_data = Parse.parsefile fromFile
val toFile =
case toFileOpt of
NONE => fromFile
| SOME toFile => toFile
val (sigName, structName) =
case namePartsOpt of
SOME parts =>
(String.concatWith "_" (List.map AbbotCore.BIG parts),
String.concat (List.map AbbotCore.Big parts))
| NONE =>
let
val parts =
String.tokens
(fn (#"." | #"-" | #"_") => true | _ => false)
toFile
in
(String.concatWith "_" (List.map AbbotCore.BIG parts),
String.concat (List.map AbbotCore.Big parts))
end
val () = print "Analysis...\n"
val ana = Analysis.analyze parse_data
val () = print "Generating signature...\n"
val stream = TextIO.openOut (toDir ^ "/" ^ toFile ^ ".sig")
val _ = Util.write stream (fn () => AbbotUser.doit_user sigName ana)
val _ = Util.flush ()
val _ = TextIO.closeOut stream
val () = print "Generating structure...\n"
val stream = TextIO.openOut (toDir ^ "/" ^ toFile ^ ".sml")
val _ = Util.write stream
(fn () => AbbotImpl.doit_impl sigName structName ana)
val _ = Util.flush ()
val _ = TextIO.closeOut stream
val () = print "Pulling in support code...\n"
val stream = TextIO.openOut (toDir ^ "/abt.cm")
val _ =
Util.write stream
(fn () =>
Util.emit
["Group\n"
^ " signature " ^ sigName ^ "\n"
^ " structure " ^ structName ^ "\n"
^ "is\n"
^ " ../cmlib/cmlib.cm\n"
^ " temp.sig\n"
^ " temp.sml\n"
^ " abt.sig\n"
^ " abt.sml\n"
^ " " ^ toFile ^ ".sig\n"
^ " " ^ toFile ^ ".sml\n"])
val _ = Util.flush ()
val _ = TextIO.closeOut stream
in
()
end
handle Parse.Parse s => print s
end