| 567 | } |
| 568 | |
| 569 | reshadefx::token reshadefx::lexer::lex() |
| 570 | { |
| 571 | bool is_at_line_begin = _cur_location.column <= 1; |
| 572 | |
| 573 | token tok; |
| 574 | next_token: |
| 575 | // Reset token data |
| 576 | tok.location = _cur_location; |
| 577 | tok.offset = input_offset(); |
| 578 | tok.length = 1; |
| 579 | tok.literal_as_double = 0; |
| 580 | tok.literal_as_string.clear(); |
| 581 | |
| 582 | assert(_cur <= _end); |
| 583 | |
| 584 | // Do a character type lookup for the current character |
| 585 | switch (s_type_lookup[uint8_t(*_cur)]) |
| 586 | { |
| 587 | case 0xFF: // EOF |
| 588 | tok.id = tokenid::end_of_file; |
| 589 | return tok; |
| 590 | case SPACE: |
| 591 | skip_space(); |
| 592 | if (_ignore_whitespace || is_at_line_begin || *_cur == '\n') |
| 593 | goto next_token; |
| 594 | tok.id = tokenid::space; |
| 595 | tok.length = input_offset() - tok.offset; |
| 596 | return tok; |
| 597 | case '\n': |
| 598 | _cur++; |
| 599 | _cur_location.line++; |
| 600 | _cur_location.column = 1; |
| 601 | is_at_line_begin = true; |
| 602 | if (_ignore_whitespace) |
| 603 | goto next_token; |
| 604 | tok.id = tokenid::end_of_line; |
| 605 | return tok; |
| 606 | case DIGIT: |
| 607 | parse_numeric_literal(tok); |
| 608 | break; |
| 609 | case IDENT: |
| 610 | parse_identifier(tok); |
| 611 | break; |
| 612 | case '!': |
| 613 | if (_cur[1] == '=') |
| 614 | tok.id = tokenid::exclaim_equal, |
| 615 | tok.length = 2; |
| 616 | else |
| 617 | tok.id = tokenid::exclaim; |
| 618 | break; |
| 619 | case '"': |
| 620 | parse_string_literal(tok, _escape_string_literals); |
| 621 | break; |
| 622 | case '#': |
| 623 | if (is_at_line_begin) |
| 624 | { |
| 625 | if (!parse_pp_directive(tok) || _ignore_pp_directives) |
| 626 | { |