Generating body
This commit is contained in:
@@ -3,10 +3,12 @@ use serde::Serialize;
|
||||
use super::*;
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Default)]
|
||||
pub struct Block(
|
||||
pub Vec<Spanned<Expression>>,
|
||||
pub Option<Spanned<Expression>>,
|
||||
);
|
||||
pub struct Block {
|
||||
pub is_unsafe: bool,
|
||||
|
||||
pub statements: Vec<Spanned<Expression>>,
|
||||
pub soft_return: Option<Spanned<Expression>>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub enum StatementBody {
|
||||
|
||||
@@ -63,6 +63,8 @@ static_path = {
|
||||
identifier ~ ("::" ~ identifier)*
|
||||
}
|
||||
|
||||
unsafe_kw = { "unsafe" }
|
||||
|
||||
// ======================================================
|
||||
// PROGRAM
|
||||
// ======================================================
|
||||
@@ -340,7 +342,7 @@ top_level = {
|
||||
// ======================================================
|
||||
|
||||
block = {
|
||||
"{" ~ statement_list ~ expr? ~ "}"
|
||||
unsafe_kw? ~ "{" ~ statement_list ~ expr? ~ "}"
|
||||
}
|
||||
|
||||
statement_list = {
|
||||
|
||||
@@ -2,7 +2,8 @@ use crate::{
|
||||
Rule,
|
||||
ast::*,
|
||||
ast_ensure, ast_expr,
|
||||
error::{AstError, IntoErr, collect_recovered},
|
||||
error::{AstError, AstResult, IntoErr, collect_recovered},
|
||||
parser::listen_rule,
|
||||
};
|
||||
|
||||
impl<'a> TryFrom<pest::iterators::Pair<'a, Rule>> for Block {
|
||||
@@ -12,7 +13,11 @@ impl<'a> TryFrom<pest::iterators::Pair<'a, Rule>> for Block {
|
||||
let mut inner = pair.clone().into_inner();
|
||||
|
||||
ast_ensure!(pair, Rule::block => {
|
||||
ast_expr!(Block(collect_recovered(inner.next().unwrap().into_inner()), inner.next().map(Spanned::try_from).transpose()))
|
||||
ast_expr!(Block {
|
||||
is_unsafe: Ok(listen_rule(&mut inner, Rule::unsafe_kw)) as AstResult<bool>,
|
||||
statements: collect_recovered(inner.next().unwrap().into_inner()),
|
||||
soft_return: inner.next().map(Spanned::try_from).transpose(),
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user