struct
(* Initial values of compiler state variables *)
val anyErrors = ref false
- val errorText = ref ""
+ val anyWarnings = ref false
val fileName = ref ""
val lineNum = ref 1
val linePos = ref [1]
val sourceStream = ref TextIO.stdIn
- fun print msg = (errorText := !errorText ^ msg;
- TextIO.print msg)
+ fun print msg = (TextIO.print msg)
(* Reset compiler to initial state *)
fun reset() = (anyErrors:=false;
- errorText:="";
+ anyWarnings:=false;
fileName:="";
lineNum:=1;
linePos:=[1];
sourceStream:=TextIO.stdIn)
- (* Print the given error message *)
- fun error posopt (msg:string) =
+ fun notify f prefix posopt (msg:string) =
let
val (startpos, endpos) = Option.getOpt (posopt, (0, 0))
fun look(pos,a::rest,n) =
else look(pos,rest,n-1)
| look _ = print "0.0"
in
- anyErrors := true;
+ f ();
print (!fileName); print ":";
look(startpos, !linePos, !lineNum);
if startpos=endpos then () else (print "-"; look(endpos, !linePos, !lineNum));
- app print [":error: ", msg, "\n"]
+ app print [":", prefix, ": ", msg, "\n"]
end
+ val error = notify (fn () => anyErrors := true) "error"
+ val warning = notify (fn () => anyWarnings := true) "warning"
+
val dummyLoc = (0, 0)
exception Error