summaryrefslogtreecommitdiffstats
path: root/crates/rebel-parse
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2024-05-04 10:28:52 +0200
committerMatthias Schiffer <mschiffer@universe-factory.net>2024-05-04 17:57:43 +0200
commit5b3d46bfefe9351cb94be1366ad68fd1a1860f5c (patch)
treefc8406e1423947e30887b6c24514c85153979076 /crates/rebel-parse
parenta7837ad230f318801e148488cfa411da71ab2269 (diff)
downloadrebel-5b3d46bfefe9351cb94be1366ad68fd1a1860f5c.tar
rebel-5b3d46bfefe9351cb94be1366ad68fd1a1860f5c.zip
rebel-parse, rebel-lang: add support for block expressions
Our scopes are now actually nested and track bindings lexically.
Diffstat (limited to 'crates/rebel-parse')
-rw-r--r--crates/rebel-parse/src/ast/expr.rs9
-rw-r--r--crates/rebel-parse/src/grammar/recipe.rs1
2 files changed, 9 insertions, 1 deletions
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<Expr<'a>>,
field: Ident<'a>,
},
+ Block(Block<'a>),
Paren(Box<Expr<'a>>),
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 }
}