diff options
| author | nsfisis <nsfisis@gmail.com> | 2025-07-13 19:55:56 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2025-08-15 10:04:20 +0900 |
| commit | 286a9b6254e88ac5ee6537ef3a11db8060ce06c5 (patch) | |
| tree | feeb5707a3b3e79c882d21536406aedb2cf322f7 | |
| parent | 64a77c44a5316c19bbc2486e462095f36c718314 (diff) | |
| download | ducc-286a9b6254e88ac5ee6537ef3a11db8060ce06c5.tar.gz ducc-286a9b6254e88ac5ee6537ef3a11db8060ce06c5.tar.zst ducc-286a9b6254e88ac5ee6537ef3a11db8060ce06c5.zip | |
feat: implement single line comment
| -rw-r--r-- | main.c | 23 | ||||
| -rw-r--r-- | tests/052.sh | 11 |
2 files changed, 29 insertions, 5 deletions
@@ -223,9 +223,22 @@ void pp_tokenize_all(Preprocessor* pp) { tok->raw.len = 1; tok->raw.data = pp->src + pp->pos - tok->raw.len; } else if (c == '/') { - tok->kind = PpTokenKind_punctuator; - tok->raw.len = 1; - tok->raw.data = pp->src + pp->pos - tok->raw.len; + if (pp->src[pp->pos] == '/') { + start = pp->pos - 1; + ++pp->pos; + while (pp->src[pp->pos] && pp->src[pp->pos] != '\n' && pp->src[pp->pos] != '\r') { + ++pp->pos; + } + tok->kind = PpTokenKind_whitespace; + tok->raw.len = pp->pos - start; + tok->raw.data = pp->src + pp->pos - tok->raw.len; + } else if (pp->src[pp->pos] == '*') { + fatal_error("unimplemented"); + } else { + tok->kind = PpTokenKind_punctuator; + tok->raw.len = 1; + tok->raw.data = pp->src + pp->pos - tok->raw.len; + } } else if (c == '%') { tok->kind = PpTokenKind_punctuator; tok->raw.len = 1; @@ -368,8 +381,8 @@ void pp_execute_pp_directive(Preprocessor* pp) { PpToken* tok = pp->pp_tokens; PpToken* define_dest; while (tok->kind != PpTokenKind_eof) { - "TODO: check if the token is at the beginning of line."; - "TODO: check if skipped whitespaces do not contain line breaks."; + // TODO: check if the token is at the beginning of line. + // TODO: check if skipped whitespaces do not contain line breaks. if (tok->kind == PpTokenKind_punctuator && string_equals_cstr(&tok->raw, "#")) { PpToken* tok2 = tok + 1; while (tok2->kind != PpTokenKind_eof && tok2->kind == PpTokenKind_whitespace) diff --git a/tests/052.sh b/tests/052.sh new file mode 100644 index 0000000..df479d3 --- /dev/null +++ b/tests/052.sh @@ -0,0 +1,11 @@ +set -e + +cat <<'EOF' > expected +EOF +bash ../../test_diff.sh <<'EOF' +// TODO: check if the token is at the beginning of line. +// TODO: check if skipped whitespaces do not contain line breaks. +int main() { + return 0; +} +EOF |
