Working soft return

This commit is contained in:
2026-05-21 07:59:00 +02:00
parent 70e6eb6276
commit 7688599504
5 changed files with 25 additions and 5 deletions
+4 -1
View File
@@ -3,7 +3,10 @@ use serde::Serialize;
use super::*;
#[derive(Debug, Clone, Serialize, Default)]
pub struct Block(pub Vec<Spanned<Expression>>);
pub struct Block(
pub Vec<Spanned<Expression>>,
pub Option<Spanned<Expression>>,
);
#[derive(Debug, Clone, Serialize)]
pub enum Statement {
+7 -2
View File
@@ -339,7 +339,11 @@ top_level = {
// ======================================================
block = {
"{" ~ (statement | unexpected_statement)* ~ "}"
"{" ~ statement_list ~ expr? ~ "}"
}
statement_list = {
(statement | (!expr ~ unexpected_statement))*
}
statement = _{
@@ -472,7 +476,8 @@ expr_path = {
}
primary = {
basic_stmt
control_flow
| basic_stmt
| literal
| expr_path
| tuple
+6 -2
View File
@@ -10,8 +10,10 @@ impl<'a> TryFrom<pest::iterators::Pair<'a, Rule>> for Block {
type Error = AstError<'a, Self>;
fn try_from(pair: pest::iterators::Pair<'a, Rule>) -> Result<Self, Self::Error> {
let mut inner = pair.clone().into_inner();
ast_ensure!(pair, Rule::block => {
ast_expr!(Block(collect_recovered(pair.into_inner())))
ast_expr!(Block(collect_recovered(inner.next().unwrap().into_inner()), inner.next().map(Spanned::try_from).transpose()))
})
}
}
@@ -39,7 +41,9 @@ impl<'a> TryFrom<pest::iterators::Pair<'a, Rule>> for Statement {
let mut inner = pair.clone().into_inner();
match rule {
Rule::statement | Rule::basic_stmt | Rule::control_flow => Statement::try_from(inner.next().unwrap()),
Rule::statement | Rule::basic_stmt | Rule::control_flow => {
Statement::try_from(inner.next().unwrap())
}
Rule::block => ast_expr!(Statement::Block(pair.try_into())),