From 62abc9e8059a70b2f8106238d724428af9bda76b Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Mon, 29 Apr 2024 19:58:35 +0200 Subject: rebel-parse, rebel-lang: rename "body" to "block" --- crates/rebel-parse/examples/parse-string.rs | 8 ++++---- crates/rebel-parse/src/ast/mod.rs | 30 ++++++++++++++--------------- crates/rebel-parse/src/grammar/recipe.rs | 26 ++++++++++++------------- 3 files changed, 32 insertions(+), 32 deletions(-) (limited to 'crates/rebel-parse') diff --git a/crates/rebel-parse/examples/parse-string.rs b/crates/rebel-parse/examples/parse-string.rs index 190d0fa..c023c46 100644 --- a/crates/rebel-parse/examples/parse-string.rs +++ b/crates/rebel-parse/examples/parse-string.rs @@ -9,8 +9,8 @@ enum Rule { Tokenize, Recipe, RecipeStmt, - Body, - BodyStmt, + Block, + BlockStmt, Expr, } @@ -46,8 +46,8 @@ fn main() { Rule::Tokenize => Ok(as_debug(tokens)), Rule::Recipe => recipe::recipe(&tokens).map(as_debug), Rule::RecipeStmt => recipe::recipe_stmt(&tokens).map(as_debug), - Rule::Body => recipe::body(&tokens).map(as_debug), - Rule::BodyStmt => recipe::body_stmt(&tokens).map(as_debug), + Rule::Block => recipe::block(&tokens).map(as_debug), + Rule::BlockStmt => recipe::block_stmt(&tokens).map(as_debug), Rule::Expr => recipe::expr(&tokens).map(as_debug), }; if opts.rule != Rule::Tokenize { diff --git a/crates/rebel-parse/src/ast/mod.rs b/crates/rebel-parse/src/ast/mod.rs index b439873..ebf7241 100644 --- a/crates/rebel-parse/src/ast/mod.rs +++ b/crates/rebel-parse/src/ast/mod.rs @@ -10,39 +10,39 @@ pub type Recipe<'a> = Vec>; #[derive(Debug, Clone, PartialEq, Eq)] pub enum RecipeStmt<'a> { - BodyStmt(BodyStmt<'a>), + BlockStmt(BlockStmt<'a>), Fetch { name: Ident<'a>, - body: Body<'a>, + block: Block<'a>, }, Task { name: Ident<'a>, params: Vec>, - body: Body<'a>, + block: Block<'a>, }, } impl<'a> RecipeStmt<'a> { pub fn validate(&self) -> Result<(), ValidationError> { match self { - RecipeStmt::BodyStmt(stmt) => stmt.validate(), - RecipeStmt::Fetch { name: _, body } => body.validate(), + RecipeStmt::BlockStmt(stmt) => stmt.validate(), + RecipeStmt::Fetch { name: _, block } => block.validate(), RecipeStmt::Task { name: _, params: _, - body, + block, } => { // TODO: Validate params? - body.validate() + block.validate() } } } } #[derive(Debug, Clone, PartialEq, Eq)] -pub struct Body<'a>(pub Vec>); +pub struct Block<'a>(pub Vec>); -impl<'a> Body<'a> { +impl<'a> Block<'a> { pub fn validate(&self) -> Result<(), ValidationError> { for stmt in &self.0 { stmt.validate()?; @@ -52,7 +52,7 @@ impl<'a> Body<'a> { } #[derive(Debug, Clone, PartialEq, Eq)] -pub enum BodyStmt<'a> { +pub enum BlockStmt<'a> { Assign { dest: Box>, expr: Box>, @@ -63,7 +63,7 @@ pub enum BodyStmt<'a> { Empty, } -impl<'a> BodyStmt<'a> { +impl<'a> BlockStmt<'a> { pub(crate) fn assign( dest: TypedPat<'a>, op: Option, @@ -83,7 +83,7 @@ impl<'a> BodyStmt<'a> { } None => expr, }; - BodyStmt::Assign { + BlockStmt::Assign { dest: Box::new(dest), expr: Box::new(expr), } @@ -91,12 +91,12 @@ impl<'a> BodyStmt<'a> { pub fn validate(&self) -> Result<(), ValidationError> { match self { - BodyStmt::Assign { dest: _, expr } => { + BlockStmt::Assign { dest: _, expr } => { // TODO: Destination validation expr.validate() } - BodyStmt::Expr { expr } => expr.validate(), - BodyStmt::Empty => Ok(()), + BlockStmt::Expr { expr } => expr.validate(), + BlockStmt::Empty => Ok(()), } } } diff --git a/crates/rebel-parse/src/grammar/recipe.rs b/crates/rebel-parse/src/grammar/recipe.rs index 7b5d5d6..6b96c85 100644 --- a/crates/rebel-parse/src/grammar/recipe.rs +++ b/crates/rebel-parse/src/grammar/recipe.rs @@ -19,31 +19,31 @@ peg::parser! { = recipe:recipe_stmt()* { recipe } pub rule recipe_stmt() -> ast::RecipeStmt<'a> - = [Token::Keyword(Keyword::Fetch)] name:ident() p('{') body:body() p('}') { - ast::RecipeStmt::Fetch { name, body } + = [Token::Keyword(Keyword::Fetch)] name:ident() p('{') block:block() p('}') { + ast::RecipeStmt::Fetch { name, block } } / [Token::Keyword(Keyword::Task)] name:ident() p('(') params:func_params() p(')') - p('{') body:body() p('}') { - ast::RecipeStmt::Task { name, params, body } + p('{') block:block() p('}') { + ast::RecipeStmt::Task { name, params, block } } - / stmt:body_stmt() p(';') { - ast::RecipeStmt::BodyStmt(stmt) + / stmt:block_stmt() p(';') { + ast::RecipeStmt::BlockStmt(stmt) } - pub rule body() -> ast::Body<'a> - = body:body_stmt() ++ p(';') { ast::Body(body) } + pub rule block() -> ast::Block<'a> + = block:block_stmt() ++ p(';') { ast::Block(block) } - pub rule body_stmt() -> ast::BodyStmt<'a> + pub rule block_stmt() -> ast::BlockStmt<'a> = dest:typed_pat() op:assign_op() expr:expr() { - ast::BodyStmt::assign(dest, op, false, expr) + ast::BlockStmt::assign(dest, op, false, expr) } / dest:typed_pat() p2('=', '+') expr:expr() { - ast::BodyStmt::assign(dest, Some(Add), true, expr) + ast::BlockStmt::assign(dest, Some(Add), true, expr) } / expr:expr() { - ast::BodyStmt::Expr { expr: Box::new(expr) } + ast::BlockStmt::Expr { expr: Box::new(expr) } } - / { ast::BodyStmt::Empty } + / { ast::BlockStmt::Empty } rule assign_op() -> Option = p('=') { None } -- cgit v1.2.3