@@ -6100,7 +6100,7 @@ Parser<ManagedTokenSource>::parse_named_function_param (
6100
6100
// Parses a statement (will further disambiguate any statement).
6101
6101
template <typename ManagedTokenSource>
6102
6102
std::unique_ptr<AST::Stmt>
6103
- Parser<ManagedTokenSource>::parse_stmt (bool allow_no_semi )
6103
+ Parser<ManagedTokenSource>::parse_stmt (ParseRestrictions restrictions )
6104
6104
{
6105
6105
// quick exit for empty statement
6106
6106
// FIXME: Can we have empty statements without semicolons? Just nothing?
@@ -6125,7 +6125,7 @@ Parser<ManagedTokenSource>::parse_stmt (bool allow_no_semi)
6125
6125
{
6126
6126
case LET:
6127
6127
// let statement
6128
- return parse_let_stmt (std::move (outer_attrs), allow_no_semi );
6128
+ return parse_let_stmt (std::move (outer_attrs), restrictions );
6129
6129
case PUB:
6130
6130
case MOD:
6131
6131
case EXTERN_TOK:
@@ -6180,7 +6180,7 @@ Parser<ManagedTokenSource>::parse_stmt (bool allow_no_semi)
6180
6180
// TODO: find out how to disable gcc "implicit fallthrough" warning
6181
6181
default :
6182
6182
// fallback: expression statement
6183
- return parse_expr_stmt (std::move (outer_attrs), allow_no_semi );
6183
+ return parse_expr_stmt (std::move (outer_attrs), restrictions );
6184
6184
break ;
6185
6185
}
6186
6186
}
@@ -6189,7 +6189,7 @@ Parser<ManagedTokenSource>::parse_stmt (bool allow_no_semi)
6189
6189
template <typename ManagedTokenSource>
6190
6190
std::unique_ptr<AST::LetStmt>
6191
6191
Parser<ManagedTokenSource>::parse_let_stmt (AST::AttrVec outer_attrs,
6192
- bool allow_no_semi )
6192
+ ParseRestrictions restrictions )
6193
6193
{
6194
6194
Location locus = lexer.peek_token ()->get_locus ();
6195
6195
skip_token (LET);
@@ -6244,13 +6244,9 @@ Parser<ManagedTokenSource>::parse_let_stmt (AST::AttrVec outer_attrs,
6244
6244
}
6245
6245
}
6246
6246
6247
- if (!maybe_skip_token (SEMICOLON) && !allow_no_semi)
6248
- {
6249
- // skip after somewhere
6247
+ if (restrictions.consume_semi )
6248
+ if (!skip_token (SEMICOLON))
6250
6249
return nullptr ;
6251
- /* TODO: how wise is it to ditch a mostly-valid let statement just
6252
- * because a semicolon is missing? */
6253
- }
6254
6250
6255
6251
return std::unique_ptr<AST::LetStmt> (
6256
6252
new AST::LetStmt (std::move (pattern), std::move (expr), std::move (type),
@@ -7085,7 +7081,7 @@ Parser<ManagedTokenSource>::parse_method ()
7085
7081
template <typename ManagedTokenSource>
7086
7082
std::unique_ptr<AST::ExprStmt>
7087
7083
Parser<ManagedTokenSource>::parse_expr_stmt (AST::AttrVec outer_attrs,
7088
- bool allow_no_semi )
7084
+ ParseRestrictions restrictions )
7089
7085
{
7090
7086
/* potential thoughts - define new virtual method "has_block()" on expr. parse
7091
7087
* expr and then determine whether semicolon is needed as a result of this
@@ -7125,7 +7121,7 @@ Parser<ManagedTokenSource>::parse_expr_stmt (AST::AttrVec outer_attrs,
7125
7121
else
7126
7122
{
7127
7123
return parse_expr_stmt_without_block (std::move (outer_attrs),
7128
- allow_no_semi );
7124
+ restrictions );
7129
7125
}
7130
7126
}
7131
7127
case UNSAFE: {
@@ -7139,7 +7135,7 @@ Parser<ManagedTokenSource>::parse_expr_stmt (AST::AttrVec outer_attrs,
7139
7135
else
7140
7136
{
7141
7137
return parse_expr_stmt_without_block (std::move (outer_attrs),
7142
- allow_no_semi );
7138
+ restrictions );
7143
7139
}
7144
7140
}
7145
7141
default :
@@ -7148,7 +7144,7 @@ Parser<ManagedTokenSource>::parse_expr_stmt (AST::AttrVec outer_attrs,
7148
7144
* initial tokens in order to prevent more syntactical errors at parse
7149
7145
* time. */
7150
7146
return parse_expr_stmt_without_block (std::move (outer_attrs),
7151
- allow_no_semi );
7147
+ restrictions );
7152
7148
}
7153
7149
}
7154
7150
@@ -7264,7 +7260,7 @@ Parser<ManagedTokenSource>::parse_expr_stmt_with_block (
7264
7260
template <typename ManagedTokenSource>
7265
7261
std::unique_ptr<AST::ExprStmtWithoutBlock>
7266
7262
Parser<ManagedTokenSource>::parse_expr_stmt_without_block (
7267
- AST::AttrVec outer_attrs, bool allow_no_semi )
7263
+ AST::AttrVec outer_attrs, ParseRestrictions restrictions )
7268
7264
{
7269
7265
/* TODO: maybe move more logic for expr without block in here for better error
7270
7266
* handling */
@@ -7273,7 +7269,6 @@ Parser<ManagedTokenSource>::parse_expr_stmt_without_block (
7273
7269
std::unique_ptr<AST::ExprWithoutBlock> expr = nullptr ;
7274
7270
Location locus = lexer.peek_token ()->get_locus ();
7275
7271
7276
- auto restrictions = ParseRestrictions ();
7277
7272
restrictions.expr_can_be_stmt = true ;
7278
7273
7279
7274
expr = parse_expr_without_block (std::move (outer_attrs), restrictions);
@@ -7288,12 +7283,9 @@ Parser<ManagedTokenSource>::parse_expr_stmt_without_block (
7288
7283
return nullptr ;
7289
7284
}
7290
7285
7291
- // skip semicolon at end that is required
7292
- if (!maybe_skip_token (SEMICOLON) && !allow_no_semi)
7293
- {
7294
- // skip somewhere?
7286
+ if (restrictions.consume_semi )
7287
+ if (!skip_token (SEMICOLON))
7295
7288
return nullptr ;
7296
- }
7297
7289
7298
7290
return std::unique_ptr<AST::ExprStmtWithoutBlock> (
7299
7291
new AST::ExprStmtWithoutBlock (std::move (expr), locus));
0 commit comments