From 5b3d46bfefe9351cb94be1366ad68fd1a1860f5c Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Sat, 4 May 2024 10:28:52 +0200 Subject: rebel-parse, rebel-lang: add support for block expressions Our scopes are now actually nested and track bindings lexically. --- crates/rebel-parse/src/ast/expr.rs | 9 ++++++++- crates/rebel-parse/src/grammar/recipe.rs | 1 + 2 files changed, 9 insertions(+), 1 deletion(-) (limited to 'crates/rebel-parse') diff --git a/crates/rebel-parse/src/ast/expr.rs b/crates/rebel-parse/src/ast/expr.rs index 9ac4a38..2e8d750 100644 --- a/crates/rebel-parse/src/ast/expr.rs +++ b/crates/rebel-parse/src/ast/expr.rs @@ -1,6 +1,6 @@ use std::collections::HashSet; -use super::{DestrPat, Ident, Path, ValidationError}; +use super::{Block, DestrPat, Ident, Path, ValidationError}; use crate::token; pub use token::StrKind; @@ -33,6 +33,7 @@ pub enum Expr<'a> { base: Box>, field: Ident<'a>, }, + Block(Block<'a>), Paren(Box>), Path(Path<'a>), Literal(Literal<'a>), @@ -122,6 +123,12 @@ impl<'a> Expr<'a> { base.validate() } Expr::Field { base, field: _ } => base.validate(), + Expr::Block(block) => { + for stmt in &block.0 { + stmt.validate()?; + } + Ok(()) + } Expr::Paren(expr) => expr.validate(), Expr::Path(_) => Ok(()), Expr::Literal(lit) => lit.validate(), diff --git a/crates/rebel-parse/src/grammar/recipe.rs b/crates/rebel-parse/src/grammar/recipe.rs index 3ce06c1..11f1ce6 100644 --- a/crates/rebel-parse/src/grammar/recipe.rs +++ b/crates/rebel-parse/src/grammar/recipe.rs @@ -134,6 +134,7 @@ peg::parser! { base:@ p('.') field:field() { Expr::field(base, field) } -- p('(') e:expr() p(')') { Expr::paren(e) } + p('{') block:block() p('}') { Expr::Block(block) } e:atom() { e } } -- cgit v1.2.3