From 481e423ab99bdece32dba6f526d902799702e9d7 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Tue, 23 Apr 2024 22:55:12 +0200 Subject: rebel-parse: use positional arguments for now Keyword arguments need more design. --- crates/rebel-parse/src/ast.rs | 23 ++++++++--------------- crates/rebel-parse/src/grammar/recipe.rs | 28 +++++++++++++++------------- 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>, + params: Vec>, body: Body<'a>, }, } @@ -48,12 +48,12 @@ pub enum Expr<'a> { }, Apply { expr: Box>, - args: Vec>, + params: Vec>, }, Method { expr: Box>, method: Ident<'a>, - args: Vec>, + params: Vec>, }, Index { expr: Box>, @@ -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>) -> 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>) -> Self { Expr::Method { expr: Box::new(expr), method, - args, + params, } } @@ -124,15 +124,8 @@ pub struct TypedExpr<'a> { pub typ: Option>, } -pub type Args<'a> = Vec>; - -#[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> - = args:delimited(, ) { args } - - rule arg() -> ast::Arg<'a> - = expr:expr() { ast::Arg { expr } } + rule call_params() -> Vec> + = args:delimited(, ) { args } - rule argtypes() -> Vec> - = args:delimited(, ) { args } + rule func_params() -> Vec> + = params:delimited(, ) { 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) } -- cgit v1.2.3