From 422b8e640f00977177a5a7250a3c56009eed10c4 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Sat, 26 Jun 2021 18:07:05 +0200 Subject: With expressions --- src/syntax/expr.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'src/syntax/expr.rs') diff --git a/src/syntax/expr.rs b/src/syntax/expr.rs index 24850d65..62f02399 100644 --- a/src/syntax/expr.rs +++ b/src/syntax/expr.rs @@ -52,6 +52,8 @@ pub enum Expr { Call(CallExpr), /// A closure expression: `(x, y) => z`. Closure(ClosureExpr), + /// A with expression: `f with (x, y: 1)`. + With(WithExpr), /// A let expression: `let x = 1`. Let(LetExpr), /// An if-else expression: `if x { y } else { z }`. @@ -91,6 +93,7 @@ impl Expr { Self::Binary(ref v) => v.span, Self::Call(ref v) => v.span, Self::Closure(ref v) => v.span, + Self::With(ref v) => v.span, Self::Let(ref v) => v.span, Self::If(ref v) => v.span, Self::While(ref v) => v.span, @@ -383,7 +386,7 @@ pub enum Associativity { pub struct CallExpr { /// The source code location. pub span: Span, - /// The callee of the function. + /// The function to call. pub callee: Box, /// The arguments to the function. pub args: CallArgs, @@ -435,6 +438,19 @@ pub struct ClosureExpr { pub body: Rc, } +/// A with expression: `f with (x, y: 1)`. +/// +/// Applies arguments to a function. +#[derive(Debug, Clone, PartialEq)] +pub struct WithExpr { + /// The source code location. + pub span: Span, + /// The function to apply the arguments to. + pub callee: Box, + /// The arguments to apply to the function. + pub args: CallArgs, +} + /// A let expression: `let x = 1`. #[derive(Debug, Clone, PartialEq)] pub struct LetExpr { -- cgit v1.2.3