| 1 |
(* parse-file.sml |
| 2 |
* |
| 3 |
* COPYRIGHT (c) 2006 |
| 4 |
* John Reppy (http://www.cs.uchicago.edu/~jhr) |
| 5 |
* Aaron Turon (http://www.cs.uchicago.edu/~adrassi) |
| 6 |
* All rights reserved. |
| 7 |
* |
| 8 |
* Driver for the parser. |
| 9 |
*) |
| 10 |
|
| 11 |
structure ParseFile = |
| 12 |
struct |
| 13 |
|
| 14 |
structure P = SpecParseFn(SpecLex) |
| 15 |
|
| 16 |
fun parse filename = let |
| 17 |
val _ = Err.status ("parsing " ^ filename) |
| 18 |
val file = TextIO.openIn filename |
| 19 |
val sm = AntlrStreamPos.mkSourcemap' filename |
| 20 |
val strm = SpecLex.streamifyInstream file |
| 21 |
(* performance testing |
| 22 |
fun go 0 = () |
| 23 |
| go n = (ignore (P.parse (SpecLex.lex (AntlrStreamPos.mkSourcemap())) (filename, sm) strm); |
| 24 |
go (n - 1)) |
| 25 |
val _ = go 1000 |
| 26 |
*) |
| 27 |
val (res, strm', errs, _) = P.parse (SpecLex.lex sm) (filename, sm) strm |
| 28 |
fun doErr err = Err.errMsg ["Syntax error ", |
| 29 |
AntlrRepair.repairToString SpecTokens.toString sm err] |
| 30 |
in |
| 31 |
app doErr errs; |
| 32 |
TextIO.closeIn file; |
| 33 |
res |
| 34 |
end |
| 35 |
|
| 36 |
end |