diff options
| author | nsfisis <nsfisis@gmail.com> | 2025-07-13 20:07:10 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2025-08-15 10:04:20 +0900 |
| commit | 88d01cd637ae2b7d6c7c2e721eb98a72160c44e2 (patch) | |
| tree | 0c46c8b032715d6f9132be8e2667882e4ef678b9 | |
| parent | 286a9b6254e88ac5ee6537ef3a11db8060ce06c5 (diff) | |
| download | ducc-88d01cd637ae2b7d6c7c2e721eb98a72160c44e2.tar.gz ducc-88d01cd637ae2b7d6c7c2e721eb98a72160c44e2.tar.zst ducc-88d01cd637ae2b7d6c7c2e721eb98a72160c44e2.zip | |
feat: implement some of escape sequences
| -rw-r--r-- | main.c | 21 | ||||
| -rw-r--r-- | tests/053.sh | 33 |
2 files changed, 47 insertions, 7 deletions
@@ -319,13 +319,8 @@ void pp_tokenize_all(Preprocessor* pp) { } } else if (c == '\'') { start = pp->pos - 1; - ch = pp->src[pp->pos]; - if (ch == '\\') { + if (pp->src[pp->pos] == '\\') { ++pp->pos; - ch = pp->src[pp->pos]; - if (ch == 'n') { - ch = '\n'; - } } pp->pos += 2; tok->kind = PpTokenKind_character_constant; @@ -576,8 +571,20 @@ void tokenize_all(Lexer* l) { ch = pp_tok->raw.data[1]; if (ch == '\\') { ch = pp_tok->raw.data[2]; - if (ch == 'n') { + if (ch == 'a') { + ch = '\a'; + } else if (ch == 'b') { + ch = '\b'; + } else if (ch == 'f') { + ch = '\f'; + } else if (ch == 'n') { ch = '\n'; + } else if (ch == 'r') { + ch = '\r'; + } else if (ch == 't') { + ch = '\t'; + } else if (ch == 'v') { + ch = '\v'; } } buf = calloc(4, sizeof(char)); diff --git a/tests/053.sh b/tests/053.sh new file mode 100644 index 0000000..c4350b8 --- /dev/null +++ b/tests/053.sh @@ -0,0 +1,33 @@ +set -e + +cat <<'EOF' > expected +39 +34 +63 +92 +7 +8 +12 +10 +13 +9 +11 +EOF +bash ../../test_diff.sh <<'EOF' +int printf(); + +int main() { + printf("%d\n", '\''); + printf("%d\n", '\"'); + printf("%d\n", '\?'); + printf("%d\n", '\\'); + printf("%d\n", '\a'); + printf("%d\n", '\b'); + printf("%d\n", '\f'); + printf("%d\n", '\n'); + printf("%d\n", '\r'); + printf("%d\n", '\t'); + printf("%d\n", '\v'); + return 0; +} +EOF |
