| 1 |
(* ml-lex-input.sml |
| 2 |
* |
| 3 |
* COPYRIGHT (c) 2005 |
| 4 |
* John Reppy (http://www.cs.uchicago.edu/~jhr) |
| 5 |
* Aaron Turon ([email protected]) |
| 6 |
* All rights reserved. |
| 7 |
* |
| 8 |
* Driver for ml-lex input format. |
| 9 |
*) |
| 10 |
|
| 11 |
structure MLLexInput : INPUT = |
| 12 |
struct |
| 13 |
|
| 14 |
structure MLLexLrVals = |
| 15 |
MLLexLrValsFun(structure Token = LrParser.Token) |
| 16 |
structure MLLexLex = |
| 17 |
MLLexLexFun(structure Tok = MLLexLrVals.Tokens) |
| 18 |
structure MLLexParser = |
| 19 |
Join(structure ParserData = MLLexLrVals.ParserData |
| 20 |
structure Lex = MLLexLex |
| 21 |
structure LrParser = LrParser) |
| 22 |
|
| 23 |
fun parseFile fname = let |
| 24 |
val anyErrors = ref false |
| 25 |
fun parseErr (msg, line, _) = ( |
| 26 |
print(concat["** Syntax error [", fname, ":", Int.toString line, "]: ", msg, "\n"]); |
| 27 |
anyErrors := true) |
| 28 |
val strm = TextIO.openIn fname |
| 29 |
val lexer = MLLexParser.makeLexer (fn n => TextIO.inputN (strm, n)) |
| 30 |
val (spec, _) = MLLexParser.parse(15, lexer, parseErr, ()) |
| 31 |
in |
| 32 |
TextIO.closeIn strm; |
| 33 |
if !anyErrors then NONE else SOME spec |
| 34 |
end |
| 35 |
|
| 36 |
end |