Fixed unsafe
This commit is contained in:
@@ -4,14 +4,13 @@ use super::*;
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Default)]
|
||||
pub struct Block {
|
||||
pub is_unsafe: bool,
|
||||
|
||||
pub statements: Vec<Spanned<Expression>>,
|
||||
pub soft_return: Option<Spanned<Expression>>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub enum Statement {
|
||||
UnsafeBlock(Block),
|
||||
Block(Block),
|
||||
If {
|
||||
initial: StatementBranch,
|
||||
|
||||
@@ -64,8 +64,6 @@ static_path = {
|
||||
identifier ~ ("::" ~ identifier)*
|
||||
}
|
||||
|
||||
unsafe_kw = { "unsafe" }
|
||||
|
||||
// ======================================================
|
||||
// PROGRAM
|
||||
// ======================================================
|
||||
@@ -345,7 +343,11 @@ top_level = {
|
||||
// ======================================================
|
||||
|
||||
block = {
|
||||
unsafe_kw? ~ "{" ~ statement_list ~ expr? ~ "}"
|
||||
"{" ~ statement_list ~ expr? ~ "}"
|
||||
}
|
||||
|
||||
unsafe_block = {
|
||||
"unsafe" ~ block
|
||||
}
|
||||
|
||||
statement_list = {
|
||||
@@ -396,6 +398,7 @@ control_flow = {
|
||||
| match_stmt
|
||||
| loop_stmt
|
||||
| block
|
||||
| unsafe_block
|
||||
}
|
||||
|
||||
statement_branch = { expr ~ block }
|
||||
|
||||
@@ -100,7 +100,7 @@ impl<'a> TryFrom<pest::iterators::Pair<'a, Rule>> for Expression {
|
||||
Rule::static_path => ast_expr!(Expression::Path(pair.try_into())),
|
||||
Rule::literal => ast_expr!(Expression::Literal(pair.try_into())),
|
||||
Rule::expr_path => ast_expr!(Expression::Path(pair.try_into())),
|
||||
Rule::statement | Rule::basic_stmt | Rule::control_flow | Rule::block => ast_expr!(
|
||||
Rule::statement | Rule::basic_stmt | Rule::control_flow | Rule::block | Rule::unsafe_block => ast_expr!(
|
||||
Expression::Statement(pair.try_into().get_map(Box::new).map(Box::new))
|
||||
),
|
||||
|
||||
|
||||
@@ -2,8 +2,7 @@ use crate::{
|
||||
Rule,
|
||||
ast::*,
|
||||
ast_ensure, ast_expr,
|
||||
error::{AstError, AstResult, IntoErr, collect_recovered},
|
||||
parser::listen_rule,
|
||||
error::{AstError, IntoErr, collect_recovered},
|
||||
};
|
||||
|
||||
impl<'a> TryFrom<pest::iterators::Pair<'a, Rule>> for Block {
|
||||
@@ -14,7 +13,6 @@ impl<'a> TryFrom<pest::iterators::Pair<'a, Rule>> for Block {
|
||||
|
||||
ast_ensure!(pair, Rule::block => {
|
||||
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(),
|
||||
})
|
||||
@@ -49,6 +47,8 @@ impl<'a> TryFrom<pest::iterators::Pair<'a, Rule>> for Statement {
|
||||
Statement::try_from(inner.next().unwrap())
|
||||
}
|
||||
|
||||
Rule::unsafe_block => ast_expr!(Statement::UnsafeBlock(inner.next().unwrap().try_into())),
|
||||
|
||||
Rule::block => ast_expr!(Statement::Block(pair.try_into())),
|
||||
|
||||
Rule::var_decl_statement => ast_expr!(Statement::VarDecl(pair.try_into())),
|
||||
|
||||
Reference in New Issue
Block a user