| 404 | } |
| 405 | |
| 406 | static void tm_next(tm_lex_t *lx, tm_tok_t *tok) { |
| 407 | memset(tok, 0, sizeof(*tok)); |
| 408 | while (lx->p < lx->end) { |
| 409 | char c = *lx->p; |
| 410 | if (c == '\n') { |
| 411 | lx->line++; |
| 412 | lx->line_start = true; |
| 413 | lx->p++; |
| 414 | } else if (isspace((unsigned char)c)) { |
| 415 | lx->p++; |
| 416 | } else if (c == '/' && lx->p + 1 < lx->end && lx->p[1] == '/') { |
| 417 | tm_skip_line_comment(lx); |
| 418 | } else if (c == '/' && lx->p + 1 < lx->end && lx->p[1] == '*') { |
| 419 | tm_skip_block_comment(lx); |
| 420 | } else if (lx->directive && tm_splice_len(lx->p, lx->end)) { |
| 421 | /* A continuation tm_read_directive already followed and judged. */ |
| 422 | lx->line++; |
| 423 | lx->p += tm_splice_len(lx->p, lx->end); |
| 424 | } else { |
| 425 | break; |
| 426 | } |
| 427 | } |
| 428 | tok->line = lx->line; |
| 429 | if (lx->p >= lx->end) { |
| 430 | return; /* TM_TOK_EOF */ |
| 431 | } |
| 432 | char c = *lx->p; |
| 433 | if (tm_raw_literal_starts(lx->p, lx->end)) { |
| 434 | tm_lex_uncertain(lx); |
| 435 | } |
| 436 | if (tm_splice_len(lx->p, lx->end)) { |
| 437 | tm_lex_uncertain(lx); /* a splice in plain code can join tokens */ |
| 438 | } |
| 439 | bool line_start = lx->line_start; |
| 440 | lx->line_start = false; |
| 441 | if (c == '#' && line_start) { |
| 442 | tm_read_directive(lx, tok); |
| 443 | } else if (c == '"' || c == '\'') { |
| 444 | tm_skip_literal(lx); |
| 445 | tok->kind = TM_TOK_PUNCT; |
| 446 | tok->ch = c; |
| 447 | } else if (tm_ident_start(c)) { |
| 448 | tok->kind = TM_TOK_IDENT; |
| 449 | tok->text = lx->p; |
| 450 | while (lx->p < lx->end && tm_ident_char(*lx->p)) { |
| 451 | lx->p++; |
| 452 | } |
| 453 | tok->len = (size_t)(lx->p - tok->text); |
| 454 | } else if (isdigit((unsigned char)c)) { |
| 455 | /* A number, suffix included: `0x1F`, `10u`. Never an identifier. */ |
| 456 | while (lx->p < lx->end && tm_ident_char(*lx->p)) { |
| 457 | lx->p++; |
| 458 | } |
| 459 | tok->kind = TM_TOK_PUNCT; |
| 460 | tok->ch = '0'; |
| 461 | } else { |
| 462 | tok->kind = TM_TOK_PUNCT; |
| 463 | tok->ch = c; |
no test coverage detected