From d4e537b87496298e2fbb83d70bdb3dfaae6807c9 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Tue, 23 Apr 2024 20:31:27 +0200 Subject: rebel-parse: introduce method calls as an Expr variant Methods and fields exist in separate namespaces. --- crates/rebel-parse/src/ast.rs | 13 +++++++++++++ crates/rebel-parse/src/grammar/recipe.rs | 1 + 2 files changed, 14 insertions(+) diff --git a/crates/rebel-parse/src/ast.rs b/crates/rebel-parse/src/ast.rs index 1f98f15..ae5d61f 100644 --- a/crates/rebel-parse/src/ast.rs +++ b/crates/rebel-parse/src/ast.rs @@ -50,6 +50,11 @@ pub enum Expr<'a> { expr: Box>, args: Vec>, }, + Method { + expr: Box>, + method: Ident<'a>, + args: Vec>, + }, Index { expr: Box>, index: Box>, @@ -86,6 +91,14 @@ impl<'a> Expr<'a> { } } + pub(crate) fn method(expr: Expr<'a>, method: Ident<'a>, args: Args<'a>) -> Self { + Expr::Method { + expr: Box::new(expr), + method, + args, + } + } + pub(crate) fn index(expr: Expr<'a>, index: Expr<'a>) -> Self { Expr::Index { expr: Box::new(expr), diff --git a/crates/rebel-parse/src/grammar/recipe.rs b/crates/rebel-parse/src/grammar/recipe.rs index d1deba4..a00d150 100644 --- a/crates/rebel-parse/src/grammar/recipe.rs +++ b/crates/rebel-parse/src/grammar/recipe.rs @@ -66,6 +66,7 @@ peg::parser! { expr:@ p('(') args:args() p(')') { Expr::apply(expr, args) } expr:@ p('[') index:expr() p(']') { Expr::index(expr, index) } -- + expr:@ p('.') method:field() p('(') args:args() p(')') { Expr::method(expr, method, args) } expr:@ p('.') field:field() { Expr::field(expr, field) } -- p('(') e:expr() p(')') { Expr::paren(e) } -- cgit v1.2.3