| 532 | */ |
| 533 | |
| 534 | unsigned C_tokenize_int(const char **token, enum TokenClass *type, |
| 535 | unsigned *line, unsigned *col, unsigned *pos) |
| 536 | { |
| 537 | int cc; |
| 538 | *type = ENDOFFILE; |
| 539 | |
| 540 | do { // infinite loop; after token recognized breaks out. |
| 541 | // Start collecting a token. |
| 542 | token_buf_reset(); |
| 543 | *line = linenr; |
| 544 | *col = column; |
| 545 | *pos = char_count; |
| 546 | // white-space tokens see continuation lines: |
| 547 | logical_lines = 0; |
| 548 | cc = get(); |
| 549 | |
| 550 | restart: |
| 551 | // cc already read; coordinates for it are correct. |
| 552 | |
| 553 | /*** WHITE-SPACE ***/ |
| 554 | |
| 555 | /* In principle all consecutive white-space including \n and \r (and some |
| 556 | other control chars) are collected and form a single whitespace token. |
| 557 | However, when newlines are requested to be reported as separate tokens, |
| 558 | they break this pattern. Note that we cannot issues multiple tokens |
| 559 | in a single call to this function. |
| 560 | |
| 561 | Token buf will only hold some white-space chars when implicitly |
| 562 | requested via whitespace_token; otherwise stays empty. |
| 563 | Same for the \n and \r requests. |
| 564 | */ |
| 565 | |
| 566 | if (cc == '\n' && newline_token) { // end of a logical line |
| 567 | // Here we assume the buf is empty. |
| 568 | token_buf_push(cc); |
| 569 | *type = NEWLINE; |
| 570 | break; |
| 571 | } |
| 572 | |
| 573 | if (cc == '\r' && continuation_token) { // end of a physical line |
| 574 | // Here we assume the buf is empty. |
| 575 | token_buf_push('\\'); |
| 576 | token_buf_push('\n'); |
| 577 | *type = CONTINUATION; |
| 578 | break; |
| 579 | } |
| 580 | |
| 581 | // Aggregate as much white-space as possible. |
| 582 | // FIXME: officially a NUL should be considered white-space. |
| 583 | while (isspace(cc)) { // i.e., cc in [ \f\n\r\t\v] |
| 584 | // Here: !newline_token (!continuation_token) |
| 585 | if (whitespace_token) |
| 586 | if (cc == '\r') { // line continuation |
| 587 | // Convert back to original char sequence: |
| 588 | token_buf_push('\\'); |
| 589 | token_buf_push('\n'); |
| 590 | } |
| 591 | else |
no test coverage detected