diff options
| author | nsfisis <nsfisis@gmail.com> | 2025-08-16 02:05:42 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2025-08-16 02:05:42 +0900 |
| commit | 6d57589705a83a32b9da4dabb7e4a717d2d01c9d (patch) | |
| tree | 5c1f69e3a3692f8f77c26aed4e00d76287a0f8f7 | |
| parent | c1f7732c1902745180e77d0abcf73714cb2e2ead (diff) | |
| download | ducc-6d57589705a83a32b9da4dabb7e4a717d2d01c9d.tar.gz ducc-6d57589705a83a32b9da4dabb7e4a717d2d01c9d.tar.zst ducc-6d57589705a83a32b9da4dabb7e4a717d2d01c9d.zip | |
refactor: merge contiguous whitespaces into one token
| -rw-r--r-- | preprocess.c | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/preprocess.c b/preprocess.c index 468ff3e..3dc6926 100644 --- a/preprocess.c +++ b/preprocess.c @@ -778,12 +778,17 @@ void pplexer_tokenize_all(PpLexer* ppl) { tok->kind = TokenKind_ident; } } else if (isspace(c)) { - if (c == '\n' || c == '\r') { - ++ppl->line; + --ppl->pos; + int start = ppl->pos; + while (isspace((c = ppl->src[ppl->pos]))) { + if (c == '\n' || c == '\r') { + ++ppl->line; + } + ++ppl->pos; } tok->kind = TokenKind_whitespace; - tok->raw.len = 1; - tok->raw.data = ppl->src + ppl->pos - tok->raw.len; + tok->raw.data = ppl->src + start; + tok->raw.len = ppl->pos - start; } else { tok->kind = TokenKind_other; tok->raw.len = 1; |
