1 (* This file comes mostly from
"Modern Compiler Implementation in ML," by Andrew Appel
2 * http
://www
.cs
.princeton
.edu
/~appel
/modern
/ml
/
7 val reset
: unit
-> unit
9 val anyErrors
: bool ref
10 val errorText
: string ref
12 val fileName
: string ref
13 val sourceStream
: TextIO.instream ref
16 val linePos
: int list ref
18 val error
: (int * int) option
-> string -> unit
23 structure ErrorMsg
:> ERRORMSG
=
25 (* Initial values
of compiler state variables
*)
26 val anyErrors
= ref
false
27 val errorText
= ref
""
31 val sourceStream
= ref
TextIO.stdIn
33 fun print msg
= (errorText
:= !errorText ^ msg
;
36 (* Reset compiler to initial state
*)
37 fun reset() = (anyErrors
:=false;
42 sourceStream
:=TextIO.stdIn
)
44 (* Print the given error message
*)
45 fun error
posopt (msg
:string) =
47 val (startpos
, endpos
) = Option
.getOpt (posopt
, (0, 0))
48 fun look(pos
,a
::rest
,n
) =
49 if a
<pos
then app print
[Int.toString n
,
52 else look(pos
,rest
,n
-1)
53 | look _
= print
"0.0"
56 print (!fileName
); print
":";
57 look(startpos
, !linePos
, !lineNum
);
58 if startpos
=endpos
then () else (print
"-"; look(endpos
, !linePos
, !lineNum
));
59 app print
[":error: ", msg
, "\n"]