Mercurial > urweb
comparison src/compiler.sml @ 5:258261a53842
Elaborating files
author | Adam Chlipala <adamc@hcoop.net> |
---|---|
date | Sat, 26 Jan 2008 16:02:47 -0500 |
parents | 5c3cc348e9e6 |
children | f1c36df29ed7 |
comparison
equal
deleted
inserted
replaced
4:5c3cc348e9e6 | 5:258261a53842 |
---|---|
45 fun parseerror (s, p1, p2) = ErrorMsg.errorAt' (p1, p2) s | 45 fun parseerror (s, p1, p2) = ErrorMsg.errorAt' (p1, p2) s |
46 val lexer = LrParser.Stream.streamify (Lex.makeLexer get) | 46 val lexer = LrParser.Stream.streamify (Lex.makeLexer get) |
47 val (absyn, _) = LacwebP.parse (30, lexer, parseerror, ()) | 47 val (absyn, _) = LacwebP.parse (30, lexer, parseerror, ()) |
48 in | 48 in |
49 TextIO.closeIn file; | 49 TextIO.closeIn file; |
50 SOME absyn | 50 if ErrorMsg.anyErrors () then |
51 NONE | |
52 else | |
53 SOME absyn | |
51 end | 54 end |
52 handle LrParser.ParseError => NONE | 55 handle LrParser.ParseError => NONE |
53 | 56 |
57 fun elaborate env filename = | |
58 case parse filename of | |
59 NONE => NONE | |
60 | SOME file => | |
61 let | |
62 val out = Elaborate.elabFile env file | |
63 in | |
64 if ErrorMsg.anyErrors () then | |
65 NONE | |
66 else | |
67 SOME out | |
68 end | |
69 | |
70 | |
54 fun testParse filename = | 71 fun testParse filename = |
55 case parse filename of | 72 case parse filename of |
56 NONE => print "Parse error\n" | 73 NONE => print "Failed\n" |
57 | SOME file => | 74 | SOME file => |
58 if ErrorMsg.anyErrors () then | 75 (Print.print (SourcePrint.p_file file); |
59 print "Recoverable parse error\n" | 76 print "\n") |
60 else | 77 |
61 (Print.print (SourcePrint.p_file file); | 78 fun testElaborate filename = |
62 print "\n") | 79 (case elaborate ElabEnv.empty filename of |
80 NONE => print "Failed\n" | |
81 | SOME (_, file) => | |
82 (Print.print (ElabPrint.p_file ElabEnv.empty file); | |
83 print "\n")) | |
84 handle ElabEnv.UnboundNamed n => | |
85 print ("Unbound named " ^ Int.toString n ^ "\n") | |
63 | 86 |
64 end | 87 end |