Skip to content

Commit

Permalink
fwd: Make some errors more friendly
Browse files Browse the repository at this point in the history
  • Loading branch information
lhmouse committed Dec 16, 2024
1 parent a4d8488 commit 7539976
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
5 changes: 5 additions & 0 deletions asteria/compiler/statement_sequence.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ do_accept_identifier_opt(Token_Stream& tstrm, bool user_decl)
if(!qtok)
return nullopt;

if(user_decl && qtok->is_keyword())
throw Compiler_Error(xtc_format,
compiler_status_keyword_not_declarable, qtok->sloc(),
"Keyword `$1` not user-declarable", qtok->as_keyword_c_str());

// See whether it is an identifier.
if(!qtok->is_identifier())
return nullopt;
Expand Down
3 changes: 3 additions & 0 deletions asteria/fwd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,9 @@ describe_compiler_status(Compiler_Status status) noexcept
case compiler_status_interval_closure_expected:
return "`)` or `]` expected";

case compiler_status_keyword_not_declarable:
return "keyword not declarable";

default:
return "[unknown compiler status]";
}
Expand Down
1 change: 1 addition & 0 deletions asteria/fwd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -742,6 +742,7 @@ enum Compiler_Status : uint32_t
compiler_status_multiple_default = 3004,
compiler_status_duplicate_name_in_structured_binding = 3005,
compiler_status_duplicate_name_in_parameter_list = 3006,
compiler_status_keyword_not_declarable = 3007,
};

ROCKET_CONST
Expand Down

0 comments on commit 7539976

Please sign in to comment.