@@ -6091,7 +6091,7 @@ Parser<ManagedTokenSource>::parse_named_function_param (
6091
6091
// Parses a statement (will further disambiguate any statement).
6092
6092
template <typename ManagedTokenSource>
6093
6093
std::unique_ptr<AST::Stmt>
6094
- Parser<ManagedTokenSource>::parse_stmt (bool allow_no_semi )
6094
+ Parser<ManagedTokenSource>::parse_stmt (ParseRestrictions restrictions )
6095
6095
{
6096
6096
// quick exit for empty statement
6097
6097
// FIXME: Can we have empty statements without semicolons? Just nothing?
@@ -6116,7 +6116,7 @@ Parser<ManagedTokenSource>::parse_stmt (bool allow_no_semi)
6116
6116
{
6117
6117
case LET:
6118
6118
// let statement
6119
- return parse_let_stmt (std::move (outer_attrs), allow_no_semi );
6119
+ return parse_let_stmt (std::move (outer_attrs), restrictions );
6120
6120
case PUB:
6121
6121
case MOD:
6122
6122
case EXTERN_TOK:
@@ -6171,7 +6171,7 @@ Parser<ManagedTokenSource>::parse_stmt (bool allow_no_semi)
6171
6171
// TODO: find out how to disable gcc "implicit fallthrough" warning
6172
6172
default :
6173
6173
// fallback: expression statement
6174
- return parse_expr_stmt (std::move (outer_attrs), allow_no_semi );
6174
+ return parse_expr_stmt (std::move (outer_attrs), restrictions );
6175
6175
break ;
6176
6176
}
6177
6177
}
@@ -6180,7 +6180,7 @@ Parser<ManagedTokenSource>::parse_stmt (bool allow_no_semi)
6180
6180
template <typename ManagedTokenSource>
6181
6181
std::unique_ptr<AST::LetStmt>
6182
6182
Parser<ManagedTokenSource>::parse_let_stmt (AST::AttrVec outer_attrs,
6183
- bool allow_no_semi )
6183
+ ParseRestrictions restrictions )
6184
6184
{
6185
6185
Location locus = lexer.peek_token ()->get_locus ();
6186
6186
skip_token (LET);
@@ -6235,13 +6235,9 @@ Parser<ManagedTokenSource>::parse_let_stmt (AST::AttrVec outer_attrs,
6235
6235
}
6236
6236
}
6237
6237
6238
- if (!maybe_skip_token (SEMICOLON) && !allow_no_semi)
6239
- {
6240
- // skip after somewhere
6238
+ if (restrictions.consume_semi )
6239
+ if (!skip_token (SEMICOLON))
6241
6240
return nullptr ;
6242
- /* TODO: how wise is it to ditch a mostly-valid let statement just
6243
- * because a semicolon is missing? */
6244
- }
6245
6241
6246
6242
return std::unique_ptr<AST::LetStmt> (
6247
6243
new AST::LetStmt (std::move (pattern), std::move (expr), std::move (type),
@@ -7076,7 +7072,7 @@ Parser<ManagedTokenSource>::parse_method ()
7076
7072
template <typename ManagedTokenSource>
7077
7073
std::unique_ptr<AST::ExprStmt>
7078
7074
Parser<ManagedTokenSource>::parse_expr_stmt (AST::AttrVec outer_attrs,
7079
- bool allow_no_semi )
7075
+ ParseRestrictions restrictions )
7080
7076
{
7081
7077
/* potential thoughts - define new virtual method "has_block()" on expr. parse
7082
7078
* expr and then determine whether semicolon is needed as a result of this
@@ -7116,7 +7112,7 @@ Parser<ManagedTokenSource>::parse_expr_stmt (AST::AttrVec outer_attrs,
7116
7112
else
7117
7113
{
7118
7114
return parse_expr_stmt_without_block (std::move (outer_attrs),
7119
- allow_no_semi );
7115
+ restrictions );
7120
7116
}
7121
7117
}
7122
7118
case UNSAFE: {
@@ -7130,7 +7126,7 @@ Parser<ManagedTokenSource>::parse_expr_stmt (AST::AttrVec outer_attrs,
7130
7126
else
7131
7127
{
7132
7128
return parse_expr_stmt_without_block (std::move (outer_attrs),
7133
- allow_no_semi );
7129
+ restrictions );
7134
7130
}
7135
7131
}
7136
7132
default :
@@ -7139,7 +7135,7 @@ Parser<ManagedTokenSource>::parse_expr_stmt (AST::AttrVec outer_attrs,
7139
7135
* initial tokens in order to prevent more syntactical errors at parse
7140
7136
* time. */
7141
7137
return parse_expr_stmt_without_block (std::move (outer_attrs),
7142
- allow_no_semi );
7138
+ restrictions );
7143
7139
}
7144
7140
}
7145
7141
@@ -7255,7 +7251,7 @@ Parser<ManagedTokenSource>::parse_expr_stmt_with_block (
7255
7251
template <typename ManagedTokenSource>
7256
7252
std::unique_ptr<AST::ExprStmtWithoutBlock>
7257
7253
Parser<ManagedTokenSource>::parse_expr_stmt_without_block (
7258
- AST::AttrVec outer_attrs, bool allow_no_semi )
7254
+ AST::AttrVec outer_attrs, ParseRestrictions restrictions )
7259
7255
{
7260
7256
/* TODO: maybe move more logic for expr without block in here for better error
7261
7257
* handling */
@@ -7264,7 +7260,6 @@ Parser<ManagedTokenSource>::parse_expr_stmt_without_block (
7264
7260
std::unique_ptr<AST::ExprWithoutBlock> expr = nullptr ;
7265
7261
Location locus = lexer.peek_token ()->get_locus ();
7266
7262
7267
- auto restrictions = ParseRestrictions ();
7268
7263
restrictions.expr_can_be_stmt = true ;
7269
7264
7270
7265
expr = parse_expr_without_block (std::move (outer_attrs), restrictions);
@@ -7279,12 +7274,9 @@ Parser<ManagedTokenSource>::parse_expr_stmt_without_block (
7279
7274
return nullptr ;
7280
7275
}
7281
7276
7282
- // skip semicolon at end that is required
7283
- if (!maybe_skip_token (SEMICOLON) && !allow_no_semi)
7284
- {
7285
- // skip somewhere?
7277
+ if (restrictions.consume_semi )
7278
+ if (!skip_token (SEMICOLON))
7286
7279
return nullptr ;
7287
- }
7288
7280
7289
7281
return std::unique_ptr<AST::ExprStmtWithoutBlock> (
7290
7282
new AST::ExprStmtWithoutBlock (std::move (expr), locus));
0 commit comments