diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2024-04-23 20:31:27 +0200 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2024-04-23 20:35:14 +0200 |
commit | d4e537b87496298e2fbb83d70bdb3dfaae6807c9 (patch) | |
tree | 92d63cb322e9c570a894d6eb0fac909ef9421f83 | |
parent | a0853a06d3e729ddfd93caa05f9581d00f5d30bf (diff) | |
download | rebel-d4e537b87496298e2fbb83d70bdb3dfaae6807c9.tar rebel-d4e537b87496298e2fbb83d70bdb3dfaae6807c9.zip |
rebel-parse: introduce method calls as an Expr variant
Methods and fields exist in separate namespaces.
-rw-r--r-- | crates/rebel-parse/src/ast.rs | 13 | ||||
-rw-r--r-- | crates/rebel-parse/src/grammar/recipe.rs | 1 |
2 files changed, 14 insertions, 0 deletions
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<Expr<'a>>, args: Vec<Arg<'a>>, }, + Method { + expr: Box<Expr<'a>>, + method: Ident<'a>, + args: Vec<Arg<'a>>, + }, Index { expr: Box<Expr<'a>>, index: Box<Expr<'a>>, @@ -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) } |