diff options
| author | gingerBill <bill@gingerbill.org> | 2024-04-04 17:01:31 +0100 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2024-04-04 17:01:31 +0100 |
| commit | 83e2f5ff74a6f2224983ac4c5631b8f65024a239 (patch) | |
| tree | fd4aae36aee5ed2ff0ddb0d2aec6c3d66f74906c /src | |
| parent | 2375ac22a7535981b5177c09ca16f36f42fc2cda (diff) | |
Add better error messages with suggestions for using `context` as an identifier
Diffstat (limited to 'src')
| -rw-r--r-- | src/parser.cpp | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/parser.cpp b/src/parser.cpp index 13225f622..bf16f5c9f 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -1482,7 +1482,16 @@ gb_internal Token expect_token(AstFile *f, TokenKind kind) { if (prev.kind != kind) { String c = token_strings[kind]; String p = token_to_string(prev); + begin_error_block(); 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"); + break; + } + + end_error_block(); + if (prev.kind == Token_EOF) { exit_with_errors(); } @@ -4055,7 +4064,12 @@ gb_internal Array<Ast *> convert_to_ident_list(AstFile *f, Array<AstAndFlags> li case Ast_BadExpr: break; case Ast_Implicit: + begin_error_block(); syntax_error(ident, "Expected an identifier, '%.*s' which is a keyword", LIT(ident->Implicit.string)); + if (ident->Implicit.kind == Token_context) { + error_line("\tSuggestion: Would 'ctx' suffice as an alternative name?\n"); + } + end_error_block(); ident = ast_ident(f, blank_token); break; |