| 1 |
structure SpecLex = struct |
| 2 |
|
| 3 |
datatype yystart_state = |
| 4 |
COM | CODE | STRING | PRECODE | PRECONSTR | CONSTR | INITIAL |
| 5 |
local |
| 6 |
|
| 7 |
structure UserDeclarations = |
| 8 |
struct |
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
structure Tok = SpecTokens |
| 13 |
|
| 14 |
val comLvl : int ref = ref 0 (* nesting depth of comments *) |
| 15 |
val comStart : int ref = ref 0 (* start line of current comment *) |
| 16 |
|
| 17 |
type lex_result = Tok.token |
| 18 |
|
| 19 |
fun err (lineNo, colNo, msg) = Err.errMsg [ |
| 20 |
"Lexical error [", Int.toString lineNo, ".", Int.toString colNo, "]: ", msg |
| 21 |
] |
| 22 |
|
| 23 |
fun eof () = ( |
| 24 |
if (!comLvl > 0) |
| 25 |
then () |
| 26 |
(* err(~1, "unclosed comment starting at line " ^ Int.toString(!comStart)) *) |
| 27 |
else (); |
| 28 |
Tok.EOF) |
| 29 |
|
| 30 |
val text : string list ref = ref [] |
| 31 |
fun addText s = (text := s::(!text)) |
| 32 |
fun clrText () = (text := []) |
| 33 |
fun getText () = concat (rev (!text)) |
| 34 |
|
| 35 |
val pcount = ref 0 (* nesting depth of parentheses in CODE *) |
| 36 |
fun inc (ri as ref i) = (ri := i+1) |
| 37 |
fun dec (ri as ref i) = (ri := i-1) |
| 38 |
|
| 39 |
end |
| 40 |
|
| 41 |
datatype yymatch |
| 42 |
= yyNO_MATCH |
| 43 |
| yyMATCH of ULexBuffer.stream * action * yymatch |
| 44 |
withtype action = ULexBuffer.stream * yymatch -> UserDeclarations.lex_result |
| 45 |
|
| 46 |
val yytable : ((UTF8.wchar * UTF8.wchar * int) list * int list) Vector.vector = |
| 47 |
#[([(0w0,0w12,7), |
| 48 |
(0w14,0w39,7), |
| 49 |
(0w41,0w41,7), |
| 50 |
(0w43,0w2147483647,7), |
| 51 |
(0w13,0w13,8), |
| 52 |
(0w40,0w40,9), |
| 53 |
(0w42,0w42,10)], []), ([(0w0,0w33,14), |
| 54 |
(0w35,0w39,14), |
| 55 |
(0w42,0w2147483647,14), |
| 56 |
(0w34,0w34,15), |
| 57 |
(0w40,0w40,16), |
| 58 |
(0w41,0w41,17)], []), ([(0w0,0w9,20), |
| 59 |
(0w11,0w12,20), |
| 60 |
(0w14,0w33,20), |
| 61 |
(0w35,0w91,20), |
| 62 |
(0w93,0w2147483647,20), |
| 63 |
(0w10,0w10,21), |
| 64 |
(0w13,0w13,22), |
| 65 |
(0w34,0w34,23), |
| 66 |
(0w92,0w92,24)], []), ([(0w0,0w8,29), |
| 67 |
(0w14,0w31,29), |
| 68 |
(0w33,0w33,29), |
| 69 |
(0w35,0w35,29), |
| 70 |
(0w38,0w39,29), |
| 71 |
(0w41,0w41,29), |
| 72 |
(0w46,0w46,29), |
| 73 |
(0w48,0w57,29), |
| 74 |
(0w60,0w60,29), |
| 75 |
(0w62,0w62,29), |
| 76 |
(0w92,0w92,29), |
| 77 |
(0w94,0w96,29), |
| 78 |
(0w123,0w123,29), |
| 79 |
(0w125,0w2147483647,29), |
| 80 |
(0w9,0w12,30), |
| 81 |
(0w32,0w32,30), |
| 82 |
(0w13,0w13,31), |
| 83 |
(0w34,0w34,32), |
| 84 |
(0w36,0w36,33), |
| 85 |
(0w37,0w37,34), |
| 86 |
(0w40,0w40,35), |
| 87 |
(0w42,0w42,36), |
| 88 |
(0w43,0w43,37), |
| 89 |
(0w44,0w44,38), |
| 90 |
(0w45,0w45,39), |
| 91 |
(0w47,0w47,40), |
| 92 |
(0w58,0w58,41), |
| 93 |
(0w59,0w59,42), |
| 94 |
(0w61,0w61,43), |
| 95 |
(0w63,0w63,44), |
| 96 |
(0w64,0w64,45), |
| 97 |
(0w65,0w90,46), |
| 98 |
(0w97,0w110,46), |
| 99 |
(0w112,0w122,46), |
| 100 |
(0w91,0w91,47), |
| 101 |
(0w93,0w93,48), |
| 102 |
(0w111,0w111,49), |
| 103 |
(0w124,0w124,50)], []), ([(0w0,0w2147483647,29)], []), ([(0w0,0w8,29), |
| 104 |
(0w14,0w31,29), |
| 105 |
(0w33,0w33,29), |
| 106 |
(0w35,0w38,29), |
| 107 |
(0w43,0w43,29), |
| 108 |
(0w46,0w57,29), |
| 109 |
(0w60,0w60,29), |
| 110 |
(0w62,0w64,29), |
| 111 |
(0w91,0w96,29), |
| 112 |
(0w126,0w2147483647,29), |
| 113 |
(0w9,0w12,151), |
| 114 |
(0w32,0w32,151), |
| 115 |
(0w13,0w13,152), |
| 116 |
(0w34,0w34,153), |
| 117 |
(0w39,0w39,154), |
| 118 |
(0w40,0w40,155), |
| 119 |
(0w41,0w41,156), |
| 120 |
(0w42,0w42,157), |
| 121 |
(0w44,0w44,158), |
| 122 |
(0w45,0w45,159), |
| 123 |
(0w58,0w58,160), |
| 124 |
(0w59,0w59,161), |
| 125 |
(0w61,0w61,162), |
| 126 |
(0w65,0w90,163), |
| 127 |
(0w97,0w99,163), |
| 128 |
(0w101,0w110,163), |
| 129 |
(0w112,0w122,163), |
| 130 |
(0w100,0w100,164), |
| 131 |
(0w111,0w111,165), |
| 132 |
(0w123,0w123,166), |
| 133 |
(0w124,0w124,167), |
| 134 |
(0w125,0w125,168)], []), ([(0w0,0w8,29), |
| 135 |
(0w14,0w31,29), |
| 136 |
(0w33,0w33,29), |
| 137 |
(0w35,0w35,29), |
| 138 |
(0w38,0w39,29), |
| 139 |
(0w46,0w46,29), |
| 140 |
(0w48,0w57,29), |
| 141 |
(0w60,0w60,29), |
| 142 |
(0w62,0w62,29), |
| 143 |
(0w92,0w92,29), |
| 144 |
(0w94,0w96,29), |
| 145 |
(0w123,0w123,29), |
| 146 |
(0w125,0w2147483647,29), |
| 147 |
(0w9,0w12,30), |
| 148 |
(0w32,0w32,30), |
| 149 |
(0w13,0w13,31), |
| 150 |
(0w34,0w34,179), |
| 151 |
(0w36,0w36,33), |
| 152 |
(0w37,0w37,34), |
| 153 |
(0w40,0w40,180), |
| 154 |
(0w41,0w41,181), |
| 155 |
(0w42,0w42,36), |
| 156 |
(0w43,0w43,37), |
| 157 |
(0w44,0w44,38), |
| 158 |
(0w45,0w45,39), |
| 159 |
(0w47,0w47,40), |
| 160 |
(0w58,0w58,41), |
| 161 |
(0w59,0w59,42), |
| 162 |
(0w61,0w61,43), |
| 163 |
(0w63,0w63,44), |
| 164 |
(0w64,0w64,45), |
| 165 |
(0w65,0w90,46), |
| 166 |
(0w97,0w110,46), |
| 167 |
(0w112,0w122,46), |
| 168 |
(0w91,0w91,47), |
| 169 |
(0w93,0w93,48), |
| 170 |
(0w111,0w111,49), |
| 171 |
(0w124,0w124,50)], []), ([], [44, 75]), ([(0w10,0w10,13)], [44, 75]), ([(0w42,0w42,12)], [44, 75]), ([(0w41,0w41,11)], [44, 75]), ([], [43]), ([], [42]), ([], [44]), ([(0w0,0w33,19), |
| 172 |
(0w35,0w39,19), |
| 173 |
(0w42,0w2147483647,19)], [50, 75]), ([], [49, 75]), ([(0w42,0w42,18)], [47, 75]), ([], [48, 75]), ([], [41]), ([(0w0,0w33,19), |
| 174 |
(0w35,0w39,19), |
| 175 |
(0w42,0w2147483647,19)], [50]), ([(0w0,0w9,28), |
| 176 |
(0w11,0w12,28), |
| 177 |
(0w14,0w33,28), |
| 178 |
(0w35,0w91,28), |
| 179 |
(0w93,0w2147483647,28)], [55, 75]), ([], [52, 75]), ([(0w10,0w10,27)], [52, 75]), ([], [51, 75]), ([(0w34,0w34,25), |
| 180 |
(0w92,0w92,26)], [53, 75]), ([], [56]), ([], [54]), ([], [52]), ([(0w0,0w9,28), |
| 181 |
(0w11,0w12,28), |
| 182 |
(0w14,0w33,28), |
| 183 |
(0w35,0w91,28), |
| 184 |
(0w93,0w2147483647,28)], [55]), ([], [75]), ([(0w9,0w12,149), |
| 185 |
(0w32,0w32,149), |
| 186 |
(0w13,0w13,150)], [1, 75]), ([(0w9,0w12,149), |
| 187 |
(0w32,0w32,149), |
| 188 |
(0w13,0w13,150)], [1, 75]), ([], [46, 75]), ([], [22, 75]), ([(0w99,0w99,56), |
| 189 |
(0w100,0w100,57), |
| 190 |
(0w101,0w101,58), |
| 191 |
(0w104,0w104,59), |
| 192 |
(0w105,0w105,60), |
| 193 |
(0w107,0w107,61), |
| 194 |
(0w110,0w110,62), |
| 195 |
(0w112,0w112,63), |
| 196 |
(0w114,0w114,64), |
| 197 |
(0w115,0w115,65), |
| 198 |
(0w116,0w116,66), |
| 199 |
(0w118,0w118,67), |
| 200 |
(0w119,0w119,68)], [75]), ([(0w42,0w42,55)], [45, 75]), ([], [24, 75]), ([], [23, 75]), ([], [28, 75]), ([(0w62,0w62,54)], [75]), ([], [33, 75]), ([], [26, 75]), ([], [27, 75]), ([(0w62,0w62,53)], [34, 75]), ([], [25, 75]), ([], [21, 75]), ([(0w39,0w39,51), |
| 201 |
(0w48,0w57,51), |
| 202 |
(0w65,0w90,51), |
| 203 |
(0w95,0w95,51), |
| 204 |
(0w97,0w122,51)], [2, 75]), ([], [31, 75]), ([], [32, 75]), ([(0w39,0w39,51), |
| 205 |
(0w48,0w57,51), |
| 206 |
(0w65,0w90,51), |
| 207 |
(0w95,0w95,51), |
| 208 |
(0w97,0w101,51), |
| 209 |
(0w103,0w122,51), |
| 210 |
(0w102,0w102,52)], [2, 75]), ([], [20, 75]), ([(0w39,0w39,51), |
| 211 |
(0w48,0w57,51), |
| 212 |
(0w65,0w90,51), |
| 213 |
(0w95,0w95,51), |
| 214 |
(0w97,0w122,51)], [2]), ([(0w39,0w39,51), |
| 215 |
(0w48,0w57,51), |
| 216 |
(0w65,0w90,51), |
| 217 |
(0w95,0w95,51), |
| 218 |
(0w97,0w122,51)], [0, 2]), ([], [36]), ([], [35]), ([], [40]), ([(0w104,0w104,144)], []), ([(0w101,0w101,134), |
| 219 |
(0w114,0w114,135)], []), ([(0w110,0w110,130)], []), ([(0w101,0w101,125)], []), ([(0w109,0w109,120)], []), ([(0w101,0w101,113)], []), ([(0w97,0w97,103), |
| 220 |
(0w111,0w111,104)], []), ([(0w114,0w114,98)], []), ([(0w101,0w101,92)], []), ([(0w116,0w116,88)], []), ([(0w111,0w111,77), |
| 221 |
(0w114,0w114,78)], []), ([(0w97,0w97,73)], []), ([(0w104,0w104,69)], []), ([(0w101,0w101,70)], []), ([(0w114,0w114,71)], []), ([(0w101,0w101,72)], []), ([], [19]), ([(0w108,0w108,74)], []), ([(0w117,0w117,75)], []), ([(0w101,0w101,76)], []), ([], [18]), ([(0w107,0w107,80)], []), ([(0w121,0w121,79)], []), ([], [17]), ([(0w101,0w101,81)], []), ([(0w110,0w110,82)], []), ([(0w115,0w115,83), |
| 222 |
(0w116,0w116,84)], [15]), ([], [15]), ([(0w121,0w121,85)], []), ([(0w112,0w112,86)], []), ([(0w101,0w101,87)], []), ([], [16]), ([(0w97,0w97,89)], []), ([(0w114,0w114,90)], []), ([(0w116,0w116,91)], []), ([], [14]), ([(0w102,0w102,93)], []), ([(0w99,0w99,94)], []), ([(0w101,0w101,95)], []), ([(0w108,0w108,96)], []), ([(0w108,0w108,97)], []), ([], [13]), ([(0w101,0w101,99)], []), ([(0w102,0w102,100)], []), ([(0w101,0w101,101)], []), ([(0w114,0w114,102)], []), ([], [12]), ([(0w109,0w109,111)], []), ([(0w110,0w110,105)], []), ([(0w116,0w116,106)], []), ([(0w101,0w101,107)], []), ([(0w114,0w114,108)], []), ([(0w109,0w109,109)], []), ([(0w115,0w115,110)], [11]), ([], [11]), ([(0w101,0w101,112)], []), ([], [10]), ([(0w121,0w121,114)], []), ([(0w119,0w119,115)], []), ([(0w111,0w111,116)], []), ([(0w114,0w114,117)], []), ([(0w100,0w100,118)], []), ([(0w115,0w115,119)], [9]), ([], [9]), ([(0w112,0w112,121)], []), ([(0w111,0w111,122)], []), ([(0w114,0w114,123)], []), ([(0w116,0w116,124)], []), ([], [8]), ([(0w97,0w97,126)], []), ([(0w100,0w100,127)], []), ([(0w101,0w101,128)], []), ([(0w114,0w114,129)], []), ([], [7]), ([(0w116,0w116,131)], []), ([(0w114,0w114,132)], []), ([(0w121,0w121,133)], []), ([], [6]), ([(0w102,0w102,142)], []), ([(0w111,0w111,136)], []), ([(0w112,0w112,137)], []), ([(0w112,0w112,138)], []), ([(0w105,0w105,139)], []), ([(0w110,0w110,140)], []), ([(0w103,0w103,141)], []), ([], [5]), ([(0w115,0w115,143)], []), ([], [4]), ([(0w97,0w97,145)], []), ([(0w110,0w110,146)], []), ([(0w103,0w103,147)], []), ([(0w101,0w101,148)], []), ([], [3]), ([(0w9,0w12,149), |
| 223 |
(0w32,0w32,149), |
| 224 |
(0w13,0w13,150)], [1]), ([(0w9,0w12,149), |
| 225 |
(0w32,0w32,149), |
| 226 |
(0w13,0w13,150)], [1]), ([], [57, 75]), ([(0w10,0w10,178)], [57, 75]), ([], [73, 75]), ([(0w39,0w39,177), |
| 227 |
(0w48,0w57,177), |
| 228 |
(0w65,0w90,177), |
| 229 |
(0w95,0w95,177), |
| 230 |
(0w97,0w122,177)], [60, 75]), ([(0w42,0w42,176)], [68, 75]), ([], [69, 75]), ([], [64, 75]), ([], [66, 75]), ([(0w62,0w62,175)], [75]), ([], [65, 75]), ([], [67, 75]), ([], [74, 75]), ([(0w39,0w39,169), |
| 231 |
(0w48,0w57,169), |
| 232 |
(0w65,0w90,169), |
| 233 |
(0w95,0w95,169), |
| 234 |
(0w97,0w122,169), |
| 235 |
(0w46,0w46,170)], [59, 75]), ([(0w39,0w39,169), |
| 236 |
(0w48,0w57,169), |
| 237 |
(0w65,0w90,169), |
| 238 |
(0w95,0w95,169), |
| 239 |
(0w97,0w104,169), |
| 240 |
(0w106,0w122,169), |
| 241 |
(0w46,0w46,170), |
| 242 |
(0w105,0w105,172)], [59, 75]), ([(0w39,0w39,169), |
| 243 |
(0w48,0w57,169), |
| 244 |
(0w65,0w90,169), |
| 245 |
(0w95,0w95,169), |
| 246 |
(0w97,0w101,169), |
| 247 |
(0w103,0w122,169), |
| 248 |
(0w46,0w46,170), |
| 249 |
(0w102,0w102,171)], [59, 75]), ([], [70, 75]), ([], [63, 75]), ([], [71, 75]), ([(0w39,0w39,169), |
| 250 |
(0w48,0w57,169), |
| 251 |
(0w65,0w90,169), |
| 252 |
(0w95,0w95,169), |
| 253 |
(0w97,0w122,169), |
| 254 |
(0w46,0w46,170)], [59]), ([], [61]), ([(0w39,0w39,169), |
| 255 |
(0w48,0w57,169), |
| 256 |
(0w65,0w90,169), |
| 257 |
(0w95,0w95,169), |
| 258 |
(0w97,0w122,169), |
| 259 |
(0w46,0w46,170)], [58, 59]), ([(0w39,0w39,169), |
| 260 |
(0w48,0w57,169), |
| 261 |
(0w65,0w90,169), |
| 262 |
(0w95,0w95,169), |
| 263 |
(0w97,0w102,169), |
| 264 |
(0w104,0w122,169), |
| 265 |
(0w46,0w46,170), |
| 266 |
(0w103,0w103,173)], [59]), ([(0w39,0w39,169), |
| 267 |
(0w48,0w57,169), |
| 268 |
(0w65,0w90,169), |
| 269 |
(0w95,0w95,169), |
| 270 |
(0w97,0w104,169), |
| 271 |
(0w106,0w122,169), |
| 272 |
(0w46,0w46,170), |
| 273 |
(0w105,0w105,174)], [59]), ([(0w39,0w39,169), |
| 274 |
(0w48,0w57,169), |
| 275 |
(0w65,0w90,169), |
| 276 |
(0w95,0w95,169), |
| 277 |
(0w97,0w115,169), |
| 278 |
(0w117,0w122,169), |
| 279 |
(0w46,0w46,170), |
| 280 |
(0w116,0w116,174)], [59, 62]), ([], [72]), ([], [39]), ([(0w39,0w39,177), |
| 281 |
(0w48,0w57,177), |
| 282 |
(0w65,0w90,177), |
| 283 |
(0w95,0w95,177), |
| 284 |
(0w97,0w122,177)], [60]), ([], [57]), ([], [37, 75]), ([(0w42,0w42,182)], [29, 75]), ([], [30, 75]), ([], [38])] |
| 285 |
fun yystreamify' p input = ULexBuffer.mkStream (p, input) |
| 286 |
|
| 287 |
fun yystreamifyReader' p readFn strm = let |
| 288 |
val s = ref strm |
| 289 |
fun iter(strm, n, accum) = |
| 290 |
if n > 1024 then (String.implode (rev accum), strm) |
| 291 |
else (case readFn strm |
| 292 |
of NONE => (String.implode (rev accum), strm) |
| 293 |
| SOME(c, strm') => iter (strm', n+1, c::accum)) |
| 294 |
fun input() = let |
| 295 |
val (data, strm) = iter(!s, 0, []) |
| 296 |
in |
| 297 |
s := strm; |
| 298 |
data |
| 299 |
end |
| 300 |
in |
| 301 |
yystreamify' p input |
| 302 |
end |
| 303 |
|
| 304 |
fun yystreamifyInstream' p strm = yystreamify' p (fn ()=>TextIO.input strm) |
| 305 |
|
| 306 |
fun innerLex |
| 307 |
(yystrm_, yyss_, yysm) = let |
| 308 |
(* current start state *) |
| 309 |
val yyss = ref yyss_ |
| 310 |
fun YYBEGIN ss = (yyss := ss) |
| 311 |
(* current input stream *) |
| 312 |
val yystrm = ref yystrm_ |
| 313 |
fun yysetStrm strm = yystrm := strm |
| 314 |
fun yygetPos() = ULexBuffer.getpos (!yystrm) |
| 315 |
fun yystreamify input = yystreamify' (yygetPos()) input |
| 316 |
fun yystreamifyReader readFn strm = yystreamifyReader' (yygetPos()) readFn strm |
| 317 |
fun yystreamifyInstream strm = yystreamifyInstream' (yygetPos()) strm |
| 318 |
(* start position of token -- can be updated via skip() *) |
| 319 |
val yystartPos = ref (yygetPos()) |
| 320 |
(* get one char of input *) |
| 321 |
fun yygetc strm = (case ULexBuffer.getu strm |
| 322 |
of (SOME (0w10, s')) => |
| 323 |
(AntlrStreamPos.markNewLine yysm (ULexBuffer.getpos strm); |
| 324 |
SOME (0w10, s')) |
| 325 |
| x => x) |
| 326 |
fun yygetList getc strm = let |
| 327 |
val get1 = UTF8.getu getc |
| 328 |
fun iter (strm, accum) = |
| 329 |
(case get1 strm |
| 330 |
of NONE => rev accum |
| 331 |
| SOME (w, strm') => iter (strm', w::accum) |
| 332 |
(* end case *)) |
| 333 |
in |
| 334 |
iter (strm, []) |
| 335 |
end |
| 336 |
(* create yytext *) |
| 337 |
fun yymksubstr(strm) = ULexBuffer.subtract (strm, !yystrm) |
| 338 |
fun yymktext(strm) = Substring.string (yymksubstr strm) |
| 339 |
fun yymkunicode(strm) = yygetList Substring.getc (yymksubstr strm) |
| 340 |
open UserDeclarations |
| 341 |
fun lex () = let |
| 342 |
fun yystuck (yyNO_MATCH) = raise Fail "lexer reached a stuck state" |
| 343 |
| yystuck (yyMATCH (strm, action, old)) = |
| 344 |
action (strm, old) |
| 345 |
val yypos = yygetPos() |
| 346 |
fun yygetlineNo strm = AntlrStreamPos.lineNo yysm (ULexBuffer.getpos strm) |
| 347 |
fun yygetcolNo strm = AntlrStreamPos.colNo yysm (ULexBuffer.getpos strm) |
| 348 |
fun yyactsToMatches (strm, [], oldMatches) = oldMatches |
| 349 |
| yyactsToMatches (strm, act::acts, oldMatches) = |
| 350 |
yyMATCH (strm, act, yyactsToMatches (strm, acts, oldMatches)) |
| 351 |
fun yygo actTable = |
| 352 |
(fn (~1, _, oldMatches) => yystuck oldMatches |
| 353 |
| (curState, strm, oldMatches) => let |
| 354 |
val (transitions, finals') = Vector.sub (yytable, curState) |
| 355 |
val finals = List.map (fn i => Vector.sub (actTable, i)) finals' |
| 356 |
fun tryfinal() = |
| 357 |
yystuck (yyactsToMatches (strm, finals, oldMatches)) |
| 358 |
fun find (c, []) = NONE |
| 359 |
| find (c, (c1, c2, s)::ts) = |
| 360 |
if c1 <= c andalso c <= c2 then SOME s |
| 361 |
else find (c, ts) |
| 362 |
in case yygetc strm |
| 363 |
of SOME(c, strm') => |
| 364 |
(case find (c, transitions) |
| 365 |
of NONE => tryfinal() |
| 366 |
| SOME n => |
| 367 |
yygo actTable |
| 368 |
(n, strm', |
| 369 |
yyactsToMatches (strm, finals, oldMatches))) |
| 370 |
| NONE => tryfinal() |
| 371 |
end) |
| 372 |
val yylastwasnref = ref (ULexBuffer.lastWasNL (!yystrm)) |
| 373 |
fun continue() = let val yylastwasn = !yylastwasnref in |
| 374 |
let |
| 375 |
fun yyAction0 (strm, lastMatch : yymatch) = (yystrm := strm; |
| 376 |
YYBEGIN CONSTR; Tok.OF) |
| 377 |
fun yyAction1 (strm, lastMatch : yymatch) = (yystrm := strm; skip()) |
| 378 |
fun yyAction2 (strm, lastMatch : yymatch) = let |
| 379 |
val yytext = yymktext(strm) |
| 380 |
in |
| 381 |
yystrm := strm; Tok.ID yytext |
| 382 |
end |
| 383 |
fun yyAction3 (strm, lastMatch : yymatch) = (yystrm := strm; Tok.KW_change) |
| 384 |
fun yyAction4 (strm, lastMatch : yymatch) = (yystrm := strm; |
| 385 |
YYBEGIN PRECODE; Tok.KW_defs) |
| 386 |
fun yyAction5 (strm, lastMatch : yymatch) = (yystrm := strm; Tok.KW_dropping) |
| 387 |
fun yyAction6 (strm, lastMatch : yymatch) = (yystrm := strm; Tok.KW_entry) |
| 388 |
fun yyAction7 (strm, lastMatch : yymatch) = (yystrm := strm; |
| 389 |
YYBEGIN PRECODE; Tok.KW_header) |
| 390 |
fun yyAction8 (strm, lastMatch : yymatch) = (yystrm := strm; Tok.KW_import) |
| 391 |
fun yyAction9 (strm, lastMatch : yymatch) = (yystrm := strm; Tok.KW_keywords) |
| 392 |
fun yyAction10 (strm, lastMatch : yymatch) = (yystrm := strm; Tok.KW_name) |
| 393 |
fun yyAction11 (strm, lastMatch : yymatch) = (yystrm := strm; Tok.KW_nonterms) |
| 394 |
fun yyAction12 (strm, lastMatch : yymatch) = (yystrm := strm; Tok.KW_prefer) |
| 395 |
fun yyAction13 (strm, lastMatch : yymatch) = (yystrm := strm; |
| 396 |
YYBEGIN CONSTR; Tok.KW_refcell) |
| 397 |
fun yyAction14 (strm, lastMatch : yymatch) = (yystrm := strm; Tok.KW_start) |
| 398 |
fun yyAction15 (strm, lastMatch : yymatch) = (yystrm := strm; |
| 399 |
YYBEGIN CONSTR; Tok.KW_tokens) |
| 400 |
fun yyAction16 (strm, lastMatch : yymatch) = (yystrm := strm; |
| 401 |
YYBEGIN CONSTR; Tok.KW_tokentype) |
| 402 |
fun yyAction17 (strm, lastMatch : yymatch) = (yystrm := strm; Tok.KW_try) |
| 403 |
fun yyAction18 (strm, lastMatch : yymatch) = (yystrm := strm; |
| 404 |
YYBEGIN PRECODE; Tok.KW_value) |
| 405 |
fun yyAction19 (strm, lastMatch : yymatch) = (yystrm := strm; |
| 406 |
YYBEGIN PRECODE; Tok.KW_where) |
| 407 |
fun yyAction20 (strm, lastMatch : yymatch) = (yystrm := strm; Tok.BAR) |
| 408 |
fun yyAction21 (strm, lastMatch : yymatch) = (yystrm := strm; |
| 409 |
YYBEGIN PRECODE; Tok.AT) |
| 410 |
fun yyAction22 (strm, lastMatch : yymatch) = (yystrm := strm; Tok.DOLLAR) |
| 411 |
fun yyAction23 (strm, lastMatch : yymatch) = (yystrm := strm; Tok.PLUS) |
| 412 |
fun yyAction24 (strm, lastMatch : yymatch) = (yystrm := strm; Tok.STAR) |
| 413 |
fun yyAction25 (strm, lastMatch : yymatch) = (yystrm := strm; Tok.QUERY) |
| 414 |
fun yyAction26 (strm, lastMatch : yymatch) = (yystrm := strm; Tok.COLON) |
| 415 |
fun yyAction27 (strm, lastMatch : yymatch) = (yystrm := strm; Tok.SEMI) |
| 416 |
fun yyAction28 (strm, lastMatch : yymatch) = (yystrm := strm; Tok.COMMA) |
| 417 |
fun yyAction29 (strm, lastMatch : yymatch) = (yystrm := strm; Tok.LP) |
| 418 |
fun yyAction30 (strm, lastMatch : yymatch) = (yystrm := strm; Tok.RP) |
| 419 |
fun yyAction31 (strm, lastMatch : yymatch) = (yystrm := strm; Tok.LSB) |
| 420 |
fun yyAction32 (strm, lastMatch : yymatch) = (yystrm := strm; Tok.RSB) |
| 421 |
fun yyAction33 (strm, lastMatch : yymatch) = (yystrm := strm; Tok.SLASH) |
| 422 |
fun yyAction34 (strm, lastMatch : yymatch) = (yystrm := strm; Tok.EQ) |
| 423 |
fun yyAction35 (strm, lastMatch : yymatch) = (yystrm := strm; Tok.ARROW) |
| 424 |
fun yyAction36 (strm, lastMatch : yymatch) = (yystrm := strm; |
| 425 |
YYBEGIN PRECODE; Tok.DARROW) |
| 426 |
fun yyAction37 (strm, lastMatch : yymatch) = let |
| 427 |
val yytext = yymktext(strm) |
| 428 |
in |
| 429 |
yystrm := strm; |
| 430 |
YYBEGIN STRING; clrText(); addText yytext; |
| 431 |
ignore(continue() before YYBEGIN INITIAL); |
| 432 |
Tok.STRING (getText()) |
| 433 |
end |
| 434 |
fun yyAction38 (strm, lastMatch : yymatch) = let |
| 435 |
val yylineno = ref(yygetlineNo(!(yystrm))) |
| 436 |
in |
| 437 |
yystrm := strm; |
| 438 |
comLvl := 1; comStart := !yylineno; YYBEGIN COM; |
| 439 |
ignore(continue() before YYBEGIN INITIAL); |
| 440 |
continue() |
| 441 |
end |
| 442 |
fun yyAction39 (strm, lastMatch : yymatch) = let |
| 443 |
val yylineno = ref(yygetlineNo(!(yystrm))) |
| 444 |
in |
| 445 |
yystrm := strm; |
| 446 |
comLvl := 1; comStart := !yylineno; YYBEGIN COM; |
| 447 |
ignore(continue() before YYBEGIN CONSTR); |
| 448 |
continue() |
| 449 |
end |
| 450 |
fun yyAction40 (strm, lastMatch : yymatch) = let |
| 451 |
val yylineno = ref(yygetlineNo(!(yystrm))) |
| 452 |
in |
| 453 |
yystrm := strm; |
| 454 |
comLvl := 1; comStart := !yylineno; YYBEGIN COM; |
| 455 |
ignore(continue() before YYBEGIN PRECODE); |
| 456 |
continue() |
| 457 |
end |
| 458 |
fun yyAction41 (strm, lastMatch : yymatch) = let |
| 459 |
val yylineno = ref(yygetlineNo(!(yystrm))) |
| 460 |
in |
| 461 |
yystrm := strm; |
| 462 |
comLvl := 1; comStart := !yylineno; YYBEGIN COM; |
| 463 |
ignore(continue() before YYBEGIN CODE); |
| 464 |
continue() |
| 465 |
end |
| 466 |
fun yyAction42 (strm, lastMatch : yymatch) = (yystrm := strm; |
| 467 |
comLvl := !comLvl+1; continue()) |
| 468 |
fun yyAction43 (strm, lastMatch : yymatch) = (yystrm := strm; |
| 469 |
comLvl := !comLvl-1; |
| 470 |
if (!comLvl = 0) |
| 471 |
then (Tok.BOGUS) |
| 472 |
else continue()) |
| 473 |
fun yyAction44 (strm, lastMatch : yymatch) = (yystrm := strm; continue()) |
| 474 |
fun yyAction45 (strm, lastMatch : yymatch) = (yystrm := strm; |
| 475 |
pcount := 1; YYBEGIN CODE; clrText(); continue()) |
| 476 |
fun yyAction46 (strm, lastMatch : yymatch) = let |
| 477 |
val yytext = yymktext(strm) |
| 478 |
in |
| 479 |
yystrm := strm; |
| 480 |
YYBEGIN STRING; clrText(); addText yytext; |
| 481 |
ignore(continue() before YYBEGIN PRECODE); |
| 482 |
Tok.STRING (getText()) |
| 483 |
end |
| 484 |
fun yyAction47 (strm, lastMatch : yymatch) = let |
| 485 |
val yytext = yymktext(strm) |
| 486 |
in |
| 487 |
yystrm := strm; |
| 488 |
addText yytext; (* NOTE: the initial "(" is consumed in the PRECODE state *) |
| 489 |
inc pcount; continue() |
| 490 |
end |
| 491 |
fun yyAction48 (strm, lastMatch : yymatch) = let |
| 492 |
val yytext = yymktext(strm) |
| 493 |
in |
| 494 |
yystrm := strm; |
| 495 |
dec pcount; |
| 496 |
if !pcount = 0 |
| 497 |
then (YYBEGIN INITIAL; Tok.CODE (getText())) |
| 498 |
else (addText yytext; continue()) |
| 499 |
end |
| 500 |
fun yyAction49 (strm, lastMatch : yymatch) = let |
| 501 |
val yytext = yymktext(strm) |
| 502 |
in |
| 503 |
yystrm := strm; |
| 504 |
addText yytext; YYBEGIN STRING; |
| 505 |
ignore(continue() before YYBEGIN CODE); |
| 506 |
continue() |
| 507 |
end |
| 508 |
fun yyAction50 (strm, lastMatch : yymatch) = let |
| 509 |
val yytext = yymktext(strm) |
| 510 |
in |
| 511 |
yystrm := strm; addText yytext; continue() |
| 512 |
end |
| 513 |
fun yyAction51 (strm, lastMatch : yymatch) = let |
| 514 |
val yytext = yymktext(strm) |
| 515 |
in |
| 516 |
yystrm := strm; addText yytext; Tok.BOGUS |
| 517 |
end |
| 518 |
fun yyAction52 (strm, lastMatch : yymatch) = let |
| 519 |
val yycolno = ref(yygetcolNo(!(yystrm))) |
| 520 |
val yylineno = ref(yygetlineNo(!(yystrm))) |
| 521 |
val yytext = yymktext(strm) |
| 522 |
in |
| 523 |
yystrm := strm; |
| 524 |
addText yytext; err (!yylineno, !yycolno, "unclosed string"); |
| 525 |
Tok.BOGUS |
| 526 |
end |
| 527 |
fun yyAction53 (strm, lastMatch : yymatch) = let |
| 528 |
val yytext = yymktext(strm) |
| 529 |
in |
| 530 |
yystrm := strm; addText yytext; continue() |
| 531 |
end |
| 532 |
fun yyAction54 (strm, lastMatch : yymatch) = let |
| 533 |
val yytext = yymktext(strm) |
| 534 |
in |
| 535 |
yystrm := strm; addText yytext; continue() |
| 536 |
end |
| 537 |
fun yyAction55 (strm, lastMatch : yymatch) = let |
| 538 |
val yytext = yymktext(strm) |
| 539 |
in |
| 540 |
yystrm := strm; addText(String.toString yytext); continue() |
| 541 |
end |
| 542 |
fun yyAction56 (strm, lastMatch : yymatch) = let |
| 543 |
val yytext = yymktext(strm) |
| 544 |
in |
| 545 |
yystrm := strm; addText yytext; continue() |
| 546 |
end |
| 547 |
fun yyAction57 (strm, lastMatch : yymatch) = (yystrm := strm; continue()) |
| 548 |
fun yyAction58 (strm, lastMatch : yymatch) = (yystrm := strm; Tok.OF) |
| 549 |
fun yyAction59 (strm, lastMatch : yymatch) = let |
| 550 |
val yytext = yymktext(strm) |
| 551 |
in |
| 552 |
yystrm := strm; Tok.ID yytext |
| 553 |
end |
| 554 |
fun yyAction60 (strm, lastMatch : yymatch) = let |
| 555 |
val yytext = yymktext(strm) |
| 556 |
in |
| 557 |
yystrm := strm; Tok.TYVAR yytext |
| 558 |
end |
| 559 |
fun yyAction61 (strm, lastMatch : yymatch) = let |
| 560 |
val yytext = yymktext(strm) |
| 561 |
in |
| 562 |
yystrm := strm; Tok.IDDOT yytext |
| 563 |
end |
| 564 |
fun yyAction62 (strm, lastMatch : yymatch) = let |
| 565 |
val yytext = yymktext(strm) |
| 566 |
in |
| 567 |
yystrm := strm; Tok.INT yytext |
| 568 |
end |
| 569 |
fun yyAction63 (strm, lastMatch : yymatch) = (yystrm := strm; Tok.BAR) |
| 570 |
fun yyAction64 (strm, lastMatch : yymatch) = (yystrm := strm; Tok.STAR) |
| 571 |
fun yyAction65 (strm, lastMatch : yymatch) = (yystrm := strm; Tok.COLON) |
| 572 |
fun yyAction66 (strm, lastMatch : yymatch) = (yystrm := strm; Tok.COMMA) |
| 573 |
fun yyAction67 (strm, lastMatch : yymatch) = (yystrm := strm; |
| 574 |
YYBEGIN INITIAL; Tok.SEMI) |
| 575 |
fun yyAction68 (strm, lastMatch : yymatch) = (yystrm := strm; Tok.LP) |
| 576 |
fun yyAction69 (strm, lastMatch : yymatch) = (yystrm := strm; Tok.RP) |
| 577 |
fun yyAction70 (strm, lastMatch : yymatch) = (yystrm := strm; Tok.LCB) |
| 578 |
fun yyAction71 (strm, lastMatch : yymatch) = (yystrm := strm; Tok.RCB) |
| 579 |
fun yyAction72 (strm, lastMatch : yymatch) = (yystrm := strm; Tok.ARROW) |
| 580 |
fun yyAction73 (strm, lastMatch : yymatch) = let |
| 581 |
val yytext = yymktext(strm) |
| 582 |
in |
| 583 |
yystrm := strm; |
| 584 |
YYBEGIN STRING; clrText(); addText yytext; |
| 585 |
ignore(continue() before YYBEGIN CONSTR); |
| 586 |
Tok.STRING (getText()) |
| 587 |
end |
| 588 |
fun yyAction74 (strm, lastMatch : yymatch) = (yystrm := strm; |
| 589 |
YYBEGIN PRECODE; Tok.EQ) |
| 590 |
fun yyAction75 (strm, lastMatch : yymatch) = let |
| 591 |
val yycolno = ref(yygetcolNo(!(yystrm))) |
| 592 |
val yylineno = ref(yygetlineNo(!(yystrm))) |
| 593 |
val yytext = yymktext(strm) |
| 594 |
in |
| 595 |
yystrm := strm; |
| 596 |
err (!yylineno, !yycolno, |
| 597 |
concat["illegal character '", |
| 598 |
String.toCString yytext, "'"]); |
| 599 |
continue() |
| 600 |
end |
| 601 |
val yyactTable = Vector.fromList([yyAction0, yyAction1, yyAction2, yyAction3, |
| 602 |
yyAction4, yyAction5, yyAction6, yyAction7, yyAction8, yyAction9, yyAction10, |
| 603 |
yyAction11, yyAction12, yyAction13, yyAction14, yyAction15, yyAction16, |
| 604 |
yyAction17, yyAction18, yyAction19, yyAction20, yyAction21, yyAction22, |
| 605 |
yyAction23, yyAction24, yyAction25, yyAction26, yyAction27, yyAction28, |
| 606 |
yyAction29, yyAction30, yyAction31, yyAction32, yyAction33, yyAction34, |
| 607 |
yyAction35, yyAction36, yyAction37, yyAction38, yyAction39, yyAction40, |
| 608 |
yyAction41, yyAction42, yyAction43, yyAction44, yyAction45, yyAction46, |
| 609 |
yyAction47, yyAction48, yyAction49, yyAction50, yyAction51, yyAction52, |
| 610 |
yyAction53, yyAction54, yyAction55, yyAction56, yyAction57, yyAction58, |
| 611 |
yyAction59, yyAction60, yyAction61, yyAction62, yyAction63, yyAction64, |
| 612 |
yyAction65, yyAction66, yyAction67, yyAction68, yyAction69, yyAction70, |
| 613 |
yyAction71, yyAction72, yyAction73, yyAction74, yyAction75]) |
| 614 |
in |
| 615 |
if ULexBuffer.eof(!(yystrm)) |
| 616 |
then let |
| 617 |
val yycolno = ref(yygetcolNo(!(yystrm))) |
| 618 |
val yylineno = ref(yygetlineNo(!(yystrm))) |
| 619 |
in |
| 620 |
(case (!(yyss)) |
| 621 |
of _ => (UserDeclarations.eof()) |
| 622 |
(* end case *)) |
| 623 |
end |
| 624 |
else (case (!(yyss)) |
| 625 |
of COM => yygo yyactTable (0, !(yystrm), yyNO_MATCH) |
| 626 |
| CODE => yygo yyactTable (1, !(yystrm), yyNO_MATCH) |
| 627 |
| STRING => yygo yyactTable (2, !(yystrm), yyNO_MATCH) |
| 628 |
| PRECODE => yygo yyactTable (3, !(yystrm), yyNO_MATCH) |
| 629 |
| PRECONSTR => yygo yyactTable (4, !(yystrm), yyNO_MATCH) |
| 630 |
| CONSTR => yygo yyactTable (5, !(yystrm), yyNO_MATCH) |
| 631 |
| INITIAL => yygo yyactTable (6, !(yystrm), yyNO_MATCH) |
| 632 |
(* end case *)) |
| 633 |
end |
| 634 |
end |
| 635 |
and skip() = (yystartPos := yygetPos(); |
| 636 |
yylastwasnref := ULexBuffer.lastWasNL (!yystrm); |
| 637 |
continue()) |
| 638 |
in (continue(), (!yystartPos, yygetPos()), !yystrm, !yyss) end |
| 639 |
in |
| 640 |
lex() |
| 641 |
end |
| 642 |
in |
| 643 |
type pos = AntlrStreamPos.pos |
| 644 |
type span = AntlrStreamPos.span |
| 645 |
type tok = UserDeclarations.lex_result |
| 646 |
|
| 647 |
datatype prestrm = STRM of ULexBuffer.stream * |
| 648 |
(yystart_state * tok * span * prestrm * yystart_state) option ref |
| 649 |
type strm = (prestrm * yystart_state) |
| 650 |
|
| 651 |
fun lex sm |
| 652 |
(STRM (yystrm, memo), ss) = (case !memo |
| 653 |
of NONE => let |
| 654 |
val (tok, span, yystrm', ss') = innerLex |
| 655 |
(yystrm, ss, sm) |
| 656 |
val strm' = STRM (yystrm', ref NONE); |
| 657 |
in |
| 658 |
memo := SOME (ss, tok, span, strm', ss'); |
| 659 |
(tok, span, (strm', ss')) |
| 660 |
end |
| 661 |
| SOME (ss', tok, span, strm', ss'') => |
| 662 |
if ss = ss' then |
| 663 |
(tok, span, (strm', ss'')) |
| 664 |
else ( |
| 665 |
memo := NONE; |
| 666 |
lex sm |
| 667 |
(STRM (yystrm, memo), ss)) |
| 668 |
(* end case *)) |
| 669 |
|
| 670 |
fun streamify input = (STRM (yystreamify' 0 input, ref NONE), INITIAL) |
| 671 |
fun streamifyReader readFn strm = (STRM (yystreamifyReader' 0 readFn strm, ref NONE), |
| 672 |
INITIAL) |
| 673 |
fun streamifyInstream strm = (STRM (yystreamifyInstream' 0 strm, ref NONE), |
| 674 |
INITIAL) |
| 675 |
|
| 676 |
fun getPos (STRM (strm, _), _) = ULexBuffer.getpos strm |
| 677 |
|
| 678 |
end |
| 679 |
end |