diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2024-04-29 19:58:35 +0200 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2024-04-29 19:58:35 +0200 |
commit | 62abc9e8059a70b2f8106238d724428af9bda76b (patch) | |
tree | 772eb2242b970662f7c15b6069239f799390631f | |
parent | 889abdf277e4e846d4becac94d79c06078cf8e39 (diff) | |
download | rebel-62abc9e8059a70b2f8106238d724428af9bda76b.tar rebel-62abc9e8059a70b2f8106238d724428af9bda76b.zip |
rebel-parse, rebel-lang: rename "body" to "block"
-rw-r--r-- | crates/rebel-lang/benches/recipe.rs | 2 | ||||
-rw-r--r-- | crates/rebel-lang/examples/repl.rs | 2 | ||||
-rw-r--r-- | crates/rebel-lang/src/scope.rs | 16 | ||||
-rw-r--r-- | crates/rebel-lang/src/typing.rs | 8 | ||||
-rw-r--r-- | crates/rebel-parse/examples/parse-string.rs | 8 | ||||
-rw-r--r-- | crates/rebel-parse/src/ast/mod.rs | 30 | ||||
-rw-r--r-- | crates/rebel-parse/src/grammar/recipe.rs | 26 |
7 files changed, 46 insertions, 46 deletions
diff --git a/crates/rebel-lang/benches/recipe.rs b/crates/rebel-lang/benches/recipe.rs index b1e08c2..3506416 100644 --- a/crates/rebel-lang/benches/recipe.rs +++ b/crates/rebel-lang/benches/recipe.rs @@ -62,7 +62,7 @@ fn typecheck(bencher: divan::Bencher) { let mut ctx = divan::black_box(ctx.clone()); for stmt in divan::black_box(&recipe) { - let ast::RecipeStmt::BodyStmt(stmt) = stmt else { + let ast::RecipeStmt::BlockStmt(stmt) = stmt else { // TODO: Check other statements continue; }; diff --git a/crates/rebel-lang/examples/repl.rs b/crates/rebel-lang/examples/repl.rs index 42e8d62..b7b91ca 100644 --- a/crates/rebel-lang/examples/repl.rs +++ b/crates/rebel-lang/examples/repl.rs @@ -77,7 +77,7 @@ fn main() { continue; } }; - let stmt = match recipe::body_stmt(&tokens) { + let stmt = match recipe::block_stmt(&tokens) { Ok(value) => value, Err(err) => { println!("Parse error: {err}"); diff --git a/crates/rebel-lang/src/scope.rs b/crates/rebel-lang/src/scope.rs index 559dc28..c57fd3c 100644 --- a/crates/rebel-lang/src/scope.rs +++ b/crates/rebel-lang/src/scope.rs @@ -42,9 +42,9 @@ impl Default for Context { } impl Context { - pub fn record_type(&mut self, stmt: &ast::BodyStmt) -> typing::Result<Type> { + pub fn record_type(&mut self, stmt: &ast::BlockStmt) -> typing::Result<Type> { match stmt { - ast::BodyStmt::Assign { dest, expr } => { + ast::BlockStmt::Assign { dest, expr } => { let typ = Type::ast_expr_type(self, expr)?; // TODO: Handle explicit type @@ -68,14 +68,14 @@ impl Context { Ok(typ) } - ast::BodyStmt::Expr { expr } => Type::ast_expr_type(self, expr), - ast::BodyStmt::Empty => Ok(Type::Unit), + ast::BlockStmt::Expr { expr } => Type::ast_expr_type(self, expr), + ast::BlockStmt::Empty => Ok(Type::Unit), } } - pub fn execute(&mut self, stmt: &ast::BodyStmt) -> value::Result<Value> { + pub fn execute(&mut self, stmt: &ast::BlockStmt) -> value::Result<Value> { match stmt { - ast::BodyStmt::Assign { dest, expr } => { + ast::BlockStmt::Assign { dest, expr } => { let value = Value::eval(self, expr)?; let typ = value.typ().or(Err(EvalError))?; @@ -100,8 +100,8 @@ impl Context { Ok(value) } - ast::BodyStmt::Expr { expr } => Value::eval(self, expr), - ast::BodyStmt::Empty => Ok(Value::Unit), + ast::BlockStmt::Expr { expr } => Value::eval(self, expr), + ast::BlockStmt::Empty => Ok(Value::Unit), } } } diff --git a/crates/rebel-lang/src/typing.rs b/crates/rebel-lang/src/typing.rs index 2af8d33..6bb0fb5 100644 --- a/crates/rebel-lang/src/typing.rs +++ b/crates/rebel-lang/src/typing.rs @@ -123,16 +123,16 @@ impl Type { }) } - pub fn ast_stmt_type(ctx: &Context, stmt: &ast::BodyStmt<'_>) -> Result<Type> { + pub fn ast_stmt_type(ctx: &Context, stmt: &ast::BlockStmt<'_>) -> Result<Type> { match stmt { - ast::BodyStmt::Assign { dest: _, expr } => { + ast::BlockStmt::Assign { dest: _, expr } => { // TODO: Assignability, dest type let dest_type = Type::Free; let expr_type = Self::ast_expr_type(ctx, expr)?; dest_type.unify(expr_type, Coerce::Assign) } - ast::BodyStmt::Expr { expr } => Self::ast_expr_type(ctx, expr), - ast::BodyStmt::Empty => Ok(Type::Unit), + ast::BlockStmt::Expr { expr } => Self::ast_expr_type(ctx, expr), + ast::BlockStmt::Empty => Ok(Type::Unit), } } 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<RecipeStmt<'a>>; #[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<FuncParam<'a>>, - 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<BodyStmt<'a>>); +pub struct Block<'a>(pub Vec<BlockStmt<'a>>); -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<TypedPat<'a>>, expr: Box<Expr<'a>>, @@ -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<OpBinary>, @@ -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<expr::OpBinary> = p('=') { None } |