diff options
| author | gingerBill <bill@gingerbill.org> | 2024-04-08 12:04:33 +0100 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2024-04-08 12:04:33 +0100 |
| commit | 0df9c8bffc3f468cab08eaad97b49952a0b6bf3e (patch) | |
| tree | 25f05a5ba8760a412d42539d6477b15b6995d8c7 | |
| parent | 0a73ed0799eae6382162236f912f2b0573c384d2 (diff) | |
Improve error messages for people using keywords instead of identifiers
| -rw-r--r-- | src/parser.cpp | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/src/parser.cpp b/src/parser.cpp index bf16f5c9f..01a3069ff 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -1486,7 +1486,15 @@ gb_internal Token expect_token(AstFile *f, TokenKind kind) { syntax_error(f->curr_token, "Expected '%.*s', got '%.*s'", LIT(c), LIT(p)); if (kind == Token_Ident) switch (prev.kind) { case Token_context: - error_line("\tSuggestion: 'context' is a reserved keyword, would 'ctx' suffice?\n"); + error_line("\tSuggestion: '%.*s' is a keyword, would 'ctx' suffice?\n", LIT(prev.string)); + break; + case Token_package: + error_line("\tSuggestion: '%.*s' is a keyword, would 'pkg' suffice?\n", LIT(prev.string)); + break; + default: + if (token_is_keyword(prev.kind)) { + error_line("\tNote: '%.*s' is a keyword\n", LIT(prev.string)); + } break; } |