Fixed block bug

This commit is contained in:
2026-05-15 10:29:02 +02:00
parent 3c5b030bdd
commit 0bb7146d13
2 changed files with 15 additions and 9 deletions
+1 -5
View File
@@ -307,11 +307,7 @@ top_level = {
// ====================================================== // ======================================================
block = { block = {
"{" ~ statement_list ~ "}" "{" ~ (statement | unexpected_statement)* ~ "}"
}
statement_list = {
(statement | unexpected_statement)*
} }
statement = _{ statement = _{
+14 -4
View File
@@ -9,9 +9,19 @@ impl<'a> TryFrom<pest::iterators::Pair<'a, Rule>> for Block {
type Error = AstError<'a, Self>; type Error = AstError<'a, Self>;
fn try_from(pair: pest::iterators::Pair<'a, Rule>) -> Result<Self, Self::Error> { fn try_from(pair: pest::iterators::Pair<'a, Rule>) -> Result<Self, Self::Error> {
Ok(Block( if pair.as_rule() == Rule::block {
collect_recovered(pair.into_inner().next().unwrap().into_inner()).get()?, Ok(Block(collect_recovered(pair.into_inner()).get()?))
)) } else {
Err(AstError {
span: pair.as_span(),
error_code: ErrorCode::InvalidStatement,
error_message: format!(
"BUG: AST requires a block, this isn't a block, it's a {:?}",
pair.as_rule()
),
recovered: None,
})
}
} }
} }
@@ -29,7 +39,7 @@ impl<'a> TryFrom<pest::iterators::Pair<'a, Rule>> for Statement {
Statement::Expression(Expression::try_from(inner.next().unwrap()).get()?) Statement::Expression(Expression::try_from(inner.next().unwrap()).get()?)
} }
Rule::block => Statement::Block(Block::try_from(inner.next().unwrap()).get()?), Rule::block => Statement::Block(pair.try_into().get()?),
Rule::var_decl_statement => Statement::VarDecl(VarDeclStmt::try_from(pair).get()?), Rule::var_decl_statement => Statement::VarDecl(VarDeclStmt::try_from(pair).get()?),