| 282 | |
| 283 | |
| 284 | static void read_string (LexState *ls, int del, SemInfo *seminfo) { |
| 285 | save_and_next(ls); |
| 286 | while (ls->current != del) { |
| 287 | switch (ls->current) { |
| 288 | case EOZ: |
| 289 | luaX_lexerror(ls, "unfinished string", TK_EOS); |
| 290 | continue; /* to avoid warnings */ |
| 291 | case '\n': |
| 292 | case '\r': |
| 293 | luaX_lexerror(ls, "unfinished string", TK_STRING); |
| 294 | continue; /* to avoid warnings */ |
| 295 | case '\\': { |
| 296 | int c; |
| 297 | next(ls); /* do not save the `\' */ |
| 298 | switch (ls->current) { |
| 299 | case 'a': c = '\a'; break; |
| 300 | case 'b': c = '\b'; break; |
| 301 | case 'f': c = '\f'; break; |
| 302 | case 'n': c = '\n'; break; |
| 303 | case 'r': c = '\r'; break; |
| 304 | case 't': c = '\t'; break; |
| 305 | case 'v': c = '\v'; break; |
| 306 | case '\n': /* go through */ |
| 307 | case '\r': save(ls, '\n'); inclinenumber(ls); continue; |
| 308 | case EOZ: continue; /* will raise an error next loop */ |
| 309 | default: { |
| 310 | if (!isdigit(ls->current)) |
| 311 | save_and_next(ls); /* handles \\, \", \', and \? */ |
| 312 | else { /* \xxx */ |
| 313 | int i = 0; |
| 314 | c = 0; |
| 315 | do { |
| 316 | c = 10*c + (ls->current-'0'); |
| 317 | next(ls); |
| 318 | } while (++i<3 && isdigit(ls->current)); |
| 319 | if (c > UCHAR_MAX) |
| 320 | luaX_lexerror(ls, "escape sequence too large", TK_STRING); |
| 321 | save(ls, c); |
| 322 | } |
| 323 | continue; |
| 324 | } |
| 325 | } |
| 326 | save(ls, c); |
| 327 | next(ls); |
| 328 | continue; |
| 329 | } |
| 330 | default: |
| 331 | save_and_next(ls); |
| 332 | } |
| 333 | } |
| 334 | save_and_next(ls); /* skip delimiter */ |
| 335 | seminfo->ts = luaX_newstring(ls, luaZ_buffer(ls->buff) + 1, |
| 336 | luaZ_bufflen(ls->buff) - 2); |
| 337 | } |
| 338 | |
| 339 | |
| 340 | static int llex (LexState *ls, SemInfo *seminfo) { |
no test coverage detected