summaryrefslogtreecommitdiffstats
path: root/crates/rebel-parse
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2024-04-29 19:58:35 +0200
committerMatthias Schiffer <mschiffer@universe-factory.net>2024-04-29 19:58:35 +0200
commit62abc9e8059a70b2f8106238d724428af9bda76b (patch)
tree772eb2242b970662f7c15b6069239f799390631f /crates/rebel-parse
parent889abdf277e4e846d4becac94d79c06078cf8e39 (diff)
downloadrebel-62abc9e8059a70b2f8106238d724428af9bda76b.tar
rebel-62abc9e8059a70b2f8106238d724428af9bda76b.zip
rebel-parse, rebel-lang: rename "body" to "block"
Diffstat (limited to 'crates/rebel-parse')
-rw-r--r--crates/rebel-parse/examples/parse-string.rs8
-rw-r--r--crates/rebel-parse/src/ast/mod.rs30
-rw-r--r--crates/rebel-parse/src/grammar/recipe.rs26
3 files changed, 32 insertions, 32 deletions
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 }