Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prohibit semicolons in parameter list #1100

Merged
merged 2 commits into from
Jun 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 17 additions & 7 deletions source/parse.h
Original file line number Diff line number Diff line change
Expand Up @@ -7731,7 +7731,7 @@ class parser

// Now the main declaration
//
if (!(n->declaration = declaration(false, true, is_template))) {
if (!(n->declaration = declaration(false, true, is_template, {}, false))) {
pos = start_pos; // backtrack
return {};
}
Expand Down Expand Up @@ -8198,7 +8198,8 @@ class parser
std::unique_ptr<unqualified_id_node> id = {},
accessibility access = {},
bool is_variadic = false,
statement_node* my_stmt = {}
statement_node* my_stmt = {},
bool semicolon_allowed = true
)
-> std::unique_ptr<declaration_node>
{
Expand Down Expand Up @@ -8504,11 +8505,18 @@ class parser
}

// Then there may be a semicolon
// If there is a semicolon, eat it
// If there is a semicolon...
if (!done() && curr().type() == lexeme::Semicolon) {
next();
// If it's allowed, eat it
if (semicolon_allowed) {
next();
}
// Otherwise, diagnose an error
else {
error("unexpected semicolon after declaration", {}, {}, {});
}
}
// But if there isn't one and it was required, diagnose an error
// Otherwise if there isn't one and it was required, diagnose an error
else if (semicolon_required) {
if (curr().type() == lexeme::LeftBrace) {
error("expected '=' before '{' - did you mean '= {' ?", true, {}, true);
Expand Down Expand Up @@ -8932,7 +8940,8 @@ class parser
bool semicolon_required = true,
bool is_parameter = false,
bool is_template_parameter = false,
statement_node* my_stmt = {}
statement_node* my_stmt = {},
bool semicolon_allowed = true
)
-> std::unique_ptr<declaration_node>
{
Expand Down Expand Up @@ -9089,7 +9098,8 @@ class parser
std::move(id),
access,
is_variadic,
my_stmt
my_stmt,
semicolon_allowed
);
if (!n) {
pos = start_pos; // backtrack
Expand Down
Loading