Refine errors on "begin; case"

This will also give better errors for unbalanced braces (which are
sigils for begin/end), see a following commit.
This commit is contained in:
Johannes Altmanninger
2024-12-11 09:13:50 +01:00
parent debfdf0a39
commit 67ccbdae96
2 changed files with 10 additions and 1 deletions

View File

@@ -2970,6 +2970,15 @@ fn did_visit_fields_of<'a>(&'a mut self, node: &'a dyn NodeMut, flow: VisitResul
};
if let Some((header_kw_range, enclosing_stmt)) = header {
let next_token = self.peek_token(0);
if next_token.typ == ParseTokenType::string
&& matches!(
next_token.keyword,
ParseKeyword::kw_case | ParseKeyword::kw_else | ParseKeyword::kw_end
)
{
self.consume_excess_token_generating_error();
}
parse_error_range!(
self,
header_kw_range,

View File

@@ -602,7 +602,7 @@ macro_rules! validate {
validate!("if true ; end ; else", ParseErrorCode::unbalancing_else);
validate!("case", ParseErrorCode::unbalancing_case);
validate!("if true ; case ; end", ParseErrorCode::generic);
validate!("if true ; case ; end", ParseErrorCode::unbalancing_case);
validate!("true | and", ParseErrorCode::andor_in_pipeline);