summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2024-04-23 22:55:12 +0200
committerMatthias Schiffer <mschiffer@universe-factory.net>2024-04-23 22:56:08 +0200
commit481e423ab99bdece32dba6f526d902799702e9d7 (patch)
tree8d2f450d46de1e5f63f816f98f70b1994de18e52
parentd4e537b87496298e2fbb83d70bdb3dfaae6807c9 (diff)
downloadrebel-481e423ab99bdece32dba6f526d902799702e9d7.tar
rebel-481e423ab99bdece32dba6f526d902799702e9d7.zip
rebel-parse: use positional arguments for now
Keyword arguments need more design.
-rw-r--r--crates/rebel-parse/src/ast.rs23
-rw-r--r--crates/rebel-parse/src/grammar/recipe.rs28
2 files changed, 23 insertions, 28 deletions
diff --git a/crates/rebel-parse/src/ast.rs b/crates/rebel-parse/src/ast.rs
index ae5d61f..8f86acd 100644
--- a/crates/rebel-parse/src/ast.rs
+++ b/crates/rebel-parse/src/ast.rs
@@ -9,7 +9,7 @@ pub enum RecipeStmt<'a> {
},
Task {
name: Ident<'a>,
- args: Vec<ArgType<'a>>,
+ params: Vec<FuncParam<'a>>,
body: Body<'a>,
},
}
@@ -48,12 +48,12 @@ pub enum Expr<'a> {
},
Apply {
expr: Box<Expr<'a>>,
- args: Vec<Arg<'a>>,
+ params: Vec<Expr<'a>>,
},
Method {
expr: Box<Expr<'a>>,
method: Ident<'a>,
- args: Vec<Arg<'a>>,
+ params: Vec<Expr<'a>>,
},
Index {
expr: Box<Expr<'a>>,
@@ -84,18 +84,18 @@ impl<'a> Expr<'a> {
}
}
- pub(crate) fn apply(expr: Expr<'a>, args: Args<'a>) -> Self {
+ pub(crate) fn apply(expr: Expr<'a>, params: Vec<Expr<'a>>) -> Self {
Expr::Apply {
expr: Box::new(expr),
- args,
+ params,
}
}
- pub(crate) fn method(expr: Expr<'a>, method: Ident<'a>, args: Args<'a>) -> Self {
+ pub(crate) fn method(expr: Expr<'a>, method: Ident<'a>, params: Vec<Expr<'a>>) -> Self {
Expr::Method {
expr: Box::new(expr),
method,
- args,
+ params,
}
}
@@ -124,15 +124,8 @@ pub struct TypedExpr<'a> {
pub typ: Option<Expr<'a>>,
}
-pub type Args<'a> = Vec<Arg<'a>>;
-
-#[derive(Debug, Clone)]
-pub struct Arg<'a> {
- pub expr: Expr<'a>,
-}
-
#[derive(Debug, Clone)]
-pub struct ArgType<'a> {
+pub struct FuncParam<'a> {
pub name: Ident<'a>,
pub typ: Expr<'a>,
}
diff --git a/crates/rebel-parse/src/grammar/recipe.rs b/crates/rebel-parse/src/grammar/recipe.rs
index a00d150..92ab7f8 100644
--- a/crates/rebel-parse/src/grammar/recipe.rs
+++ b/crates/rebel-parse/src/grammar/recipe.rs
@@ -15,8 +15,9 @@ peg::parser! {
= keyword_fetch() name:ident() p('{') body:body() p('}') {
ast::RecipeStmt::Fetch { name, body: Vec::new() }
}
- / keyword_task() name:ident() p('(') args:argtypes() p(')') p('{') body:body() p('}') {
- ast::RecipeStmt::Task { name, args, body }
+ / keyword_task() name:ident() p('(') params:func_params() p(')')
+ p('{') body:body() p('}') {
+ ast::RecipeStmt::Task { name, params, body }
}
/ stmt:body_stmt() {
ast::RecipeStmt::BodyStmt(stmt)
@@ -63,10 +64,14 @@ peg::parser! {
p('-') expr:@ { Expr::unary(Neg, expr) }
p('!') expr:@ { Expr::unary(Not, expr) }
--
- expr:@ p('(') args:args() p(')') { Expr::apply(expr, args) }
+ expr:@ p('(') params:call_params() p(')') {
+ Expr::apply(expr, params)
+ }
expr:@ p('[') index:expr() p(']') { Expr::index(expr, index) }
--
- expr:@ p('.') method:field() p('(') args:args() p(')') { Expr::method(expr, method, args) }
+ expr:@ p('.') method:field() p('(') params:call_params() p(')') {
+ Expr::method(expr, method, params)
+ }
expr:@ p('.') field:field() { Expr::field(expr, field) }
--
p('(') e:expr() p(')') { Expr::paren(e) }
@@ -77,17 +82,14 @@ peg::parser! {
= lit:literal() { Expr::Literal(lit) }
/ path:path() { Expr::Path(path) }
- rule args() -> Vec<ast::Arg<'a>>
- = args:delimited(<arg()>, <p(',')>) { args }
-
- rule arg() -> ast::Arg<'a>
- = expr:expr() { ast::Arg { expr } }
+ rule call_params() -> Vec<ast::Expr<'a>>
+ = args:delimited(<expr()>, <p(',')>) { args }
- rule argtypes() -> Vec<ast::ArgType<'a>>
- = args:delimited(<argtype()>, <p(',')>) { args }
+ rule func_params() -> Vec<ast::FuncParam<'a>>
+ = params:delimited(<func_param()>, <p(',')>) { params }
- rule argtype() -> ast::ArgType<'a>
- = name:ident() p(':') typ:expr() { ast::ArgType { name, typ } }
+ rule func_param() -> ast::FuncParam<'a>
+ = name:ident() p(':') typ:expr() { ast::FuncParam { name, typ } }
rule literal() -> ast::Literal<'a>
= keyword_true() { ast::Literal::Boolean(true) }