diff options
| author | nsfisis <nsfisis@gmail.com> | 2025-08-26 21:57:09 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2025-08-26 21:57:09 +0900 |
| commit | dd08b39ac5fc2eeb555bf40596279487fcea5f95 (patch) | |
| tree | 859e4c45cc783f9fd9e29a5968f3964c04d5fb1f /src/token.c | |
| parent | a70bc7804c4c1cb07976d684b64b5a2fe3b68f93 (diff) | |
| download | ducc-dd08b39ac5fc2eeb555bf40596279487fcea5f95.tar.gz ducc-dd08b39ac5fc2eeb555bf40596279487fcea5f95.tar.zst ducc-dd08b39ac5fc2eeb555bf40596279487fcea5f95.zip | |
feat: improve handling of non-directive preprocessing directives
Diffstat (limited to 'src/token.c')
| -rw-r--r-- | src/token.c | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/src/token.c b/src/token.c index 71eabaf..e08e07f 100644 --- a/src/token.c +++ b/src/token.c @@ -44,6 +44,8 @@ const char* token_kind_stringify(TokenKind k) { return "#include"; else if (k == TokenKind_pp_directive_line) return "#line"; + else if (k == TokenKind_pp_directive_non_directive) + return "#<non-directive>"; else if (k == TokenKind_pp_directive_nop) return "#"; else if (k == TokenKind_pp_directive_pragma) @@ -272,7 +274,11 @@ const char* token_kind_stringify(TokenKind k) { const char* token_stringify(Token* t) { TokenKind k = t->kind; - if (k == TokenKind_literal_int) { + if (k == TokenKind_pp_directive_non_directive) { + char* buf = calloc(strlen(t->value.string) + 1 + 1, sizeof(char)); + sprintf(buf, "#%s", t->value.string); + return buf; + } else if (k == TokenKind_literal_int) { const char* kind_str = token_kind_stringify(k); char* buf = calloc(10 + strlen(kind_str) + 3 + 1, sizeof(char)); sprintf(buf, "%d (%s)", t->value.integer, kind_str); |
