21 |
addSC: string * int -> unit, |
addSC: string * int -> unit, |
22 |
addSN: string * pos -> unit, |
addSN: string * pos -> unit, |
23 |
getS: pos * (string * pos * pos -> lexresult) -> lexresult, |
getS: pos * (string * pos * pos -> lexresult) -> lexresult, |
24 |
handleEof: unit -> lexresult, |
handleEof: unit -> pos, |
25 |
newline: pos -> unit, |
newline: pos -> unit, |
26 |
error: pos -> string -> unit |
error: pos * pos -> string -> unit |
27 |
} |
} |
28 |
|
|
29 |
type arg = lexarg |
type arg = lexarg |
30 |
|
|
31 |
fun eof (arg: lexarg) = (#handleEof arg ()) |
fun eof (arg: lexarg) = let |
32 |
|
val pos = #handleEof arg () |
|
(* |
|
|
local |
|
|
val depth = ref 0 |
|
|
val curstring = ref ([]: char list) |
|
|
val startpos = ref 0 |
|
|
val instring = ref false |
|
|
in |
|
|
|
|
|
|
|
|
fun resetAll () = (depth := 0; startpos := 0; instring := false) |
|
|
|
|
|
(* comment stuff *) |
|
|
fun enterC () = depth := !depth + 1 |
|
|
fun leaveC () = let |
|
|
val d = !depth - 1 |
|
|
val _ = depth := d |
|
|
in |
|
|
d = 0 |
|
|
end |
|
|
|
|
|
(* string stuff *) |
|
|
fun newS sp = (curstring := []; startpos := sp; instring := true) |
|
|
fun addS c = curstring := c :: (!curstring) |
|
|
fun addSC (t, p, b) = addS (chr (ord (String.sub (t, 2)) - b)) |
|
|
fun addSN (t, p) = let |
|
|
val ns = substring (t, 1, 3) |
|
|
val n = Int.fromString ns |
|
33 |
in |
in |
|
addS (chr (valOf n)) |
|
|
handle _ => |
|
|
ErrorMsg.error p ("illegal decimal char spec " ^ ns) |
|
|
end |
|
|
fun getS endpos = |
|
|
(instring := false; |
|
|
Tokens.STRING (implode (rev (!curstring)), !startpos, endpos + 1)) |
|
|
|
|
|
(* handling EOF *) |
|
|
fun eof (arg: ) = let |
|
|
val pos = ErrorMsg.lastLinePos () |
|
|
in |
|
|
if !depth > 0 then |
|
|
ErrorMsg.error pos "unexpected EOF in COMMENT" |
|
|
else if !instring then |
|
|
ErrorMsg.error pos "unexpected EOF in STRING" |
|
|
else (); |
|
|
resetAll (); |
|
34 |
Tokens.EOF(pos,pos) |
Tokens.EOF(pos,pos) |
35 |
end |
end |
|
end |
|
|
*) |
|
36 |
|
|
37 |
local |
local |
38 |
val idlist = [("Alias", Tokens.ALIAS), |
val idlist = [("Alias", Tokens.ALIAS), |
121 |
<C,PC,PMC,MC>{eol} => (newline yypos; continue ()); |
<C,PC,PMC,MC>{eol} => (newline yypos; continue ()); |
122 |
<C,PC,PMC,MC>. => (continue ()); |
<C,PC,PMC,MC>. => (continue ()); |
123 |
|
|
124 |
<INITIAL,P,PM,M>"*)" => (error yypos "unmatched comment delimiter"; |
<INITIAL,P,PM,M>"*)" => (error (yypos, yypos+2) |
125 |
|
"unmatched comment delimiter"; |
126 |
continue ()); |
continue ()); |
127 |
|
|
128 |
<INITIAL>"\"" => (YYBEGIN S; newS (yypos, "string"); continue ()); |
<INITIAL>"\"" => (YYBEGIN S; newS (yypos, "string"); continue ()); |
152 |
<S>"\\"{eol} => (YYBEGIN SS; newline (yypos + 1); continue ()); |
<S>"\\"{eol} => (YYBEGIN SS; newline (yypos + 1); continue ()); |
153 |
<S>"\\"{ws}+ => (YYBEGIN SS; continue ()); |
<S>"\\"{ws}+ => (YYBEGIN SS; continue ()); |
154 |
|
|
155 |
<S>"\\". => (error yypos |
<S>"\\". => (error (yypos, yypos+2) |
156 |
("illegal escape character in string " ^ yytext); |
("illegal escape character in string " ^ yytext); |
157 |
continue ()); |
continue ()); |
158 |
|
|
159 |
<S>"\"" => (YYBEGIN INITIAL; getS (yypos, Tokens.FILE_NATIVE)); |
<S>"\"" => (YYBEGIN INITIAL; getS (yypos, Tokens.FILE_NATIVE)); |
160 |
<S>{eol} => (newline yypos; |
<S>{eol} => (newline yypos; |
161 |
error yypos "illegal linebreak in string"; |
error (yypos, yypos + size yytext) |
162 |
|
"illegal linebreak in string"; |
163 |
continue ()); |
continue ()); |
164 |
|
|
165 |
<S>. => (addS (String.sub (yytext, 0)); continue ()); |
<S>. => (addS (String.sub (yytext, 0)); continue ()); |
167 |
<SS>{eol} => (newline yypos; continue ()); |
<SS>{eol} => (newline yypos; continue ()); |
168 |
<SS>{ws}+ => (continue ()); |
<SS>{ws}+ => (continue ()); |
169 |
<SS>"\\" => (YYBEGIN S; continue ()); |
<SS>"\\" => (YYBEGIN S; continue ()); |
170 |
<SS>. => (error yypos |
<SS>. => (error (yypos, yypos+1) |
171 |
("illegal character in stringskip " ^ yytext); |
("illegal character in stringskip " ^ yytext); |
172 |
continue ()); |
continue ()); |
173 |
|
|
188 |
<P>{digit}+ => (Tokens.NUMBER |
<P>{digit}+ => (Tokens.NUMBER |
189 |
(valOf (Int.fromString yytext) |
(valOf (Int.fromString yytext) |
190 |
handle _ => |
handle _ => |
191 |
(error yypos "number too large"; 0), |
(error (yypos, yypos + size yytext) |
192 |
|
"number too large"; |
193 |
|
0), |
194 |
yypos, yypos + size yytext)); |
yypos, yypos + size yytext)); |
195 |
|
|
196 |
<P>{id} => (Tokens.CM_ID (yytext, yypos, yypos + size yytext)); |
<P>{id} => (Tokens.CM_ID (yytext, yypos, yypos + size yytext)); |
232 |
|
|
233 |
<INITIAL,M,PM,P>{ws}+ => (continue ()); |
<INITIAL,M,PM,P>{ws}+ => (continue ()); |
234 |
|
|
235 |
<M,PM>. => (error yypos |
<M,PM>. => (error (yypos, yypos+1) |
236 |
("illegal character at start of ML symbol: " ^ |
("illegal character at start of ML symbol: " ^ |
237 |
yytext); |
yytext); |
238 |
continue ()); |
continue ()); |
240 |
<INITIAL>{cmid} => (idToken (yytext, yypos)); |
<INITIAL>{cmid} => (idToken (yytext, yypos)); |
241 |
|
|
242 |
|
|
243 |
<INITIAL>. => (error yypos |
<INITIAL>. => (error (yypos, yypos+1) |
244 |
("illegal character: " ^ yytext); |
("illegal character: " ^ yytext); |
245 |
continue ()); |
continue ()); |