From 0de4f3ed7bb20a94fd58f93b0793d3b5a8e13972 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Wed, 20 Jan 2021 21:50:51 +0100 Subject: [PATCH] =?UTF-8?q?Reorder=20and=20fix=20docs=20=E2=9C=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/eval/mod.rs | 4 ++-- src/syntax/expr.rs | 28 ++++++++++++++-------------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/eval/mod.rs b/src/eval/mod.rs index 500436980..54fe23247 100644 --- a/src/eval/mod.rs +++ b/src/eval/mod.rs @@ -175,11 +175,11 @@ impl Eval for Spanned<&Expr> { Expr::Array(v) => Value::Array(v.with_span(self.span).eval(ctx)), Expr::Dict(v) => Value::Dict(v.with_span(self.span).eval(ctx)), Expr::Template(v) => Value::Template(v.clone()), + Expr::Group(v) => v.as_ref().eval(ctx), + Expr::Block(v) => v.as_ref().eval(ctx), Expr::Call(v) => v.with_span(self.span).eval(ctx), Expr::Unary(v) => v.with_span(self.span).eval(ctx), Expr::Binary(v) => v.with_span(self.span).eval(ctx), - Expr::Group(v) => v.as_ref().eval(ctx), - Expr::Block(v) => v.as_ref().eval(ctx), Expr::Let(v) => v.with_span(self.span).eval(ctx), Expr::If(v) => v.with_span(self.span).eval(ctx), } diff --git a/src/syntax/expr.rs b/src/syntax/expr.rs index 29e143b24..c1af23354 100644 --- a/src/syntax/expr.rs +++ b/src/syntax/expr.rs @@ -34,16 +34,16 @@ pub enum Expr { Dict(ExprDict), /// A template expression: `[*Hi* there!]`. Template(ExprTemplate), + /// A grouped expression: `(1 + 2)`. + Group(ExprGroup), + /// A block expression: `{1 + 2}`. + Block(ExprBlock), /// A unary operation: `-x`. Unary(ExprUnary), /// A binary operation: `a + b`, `a / b`. Binary(ExprBinary), /// An invocation of a function: `[foo ...]`, `foo(...)`. Call(ExprCall), - /// A grouped expression: `(1 + 2)`. - Group(ExprGroup), - /// A block expression: `{1 + 2}`. - Block(ExprBlock), /// A let expression: `let x = 1`. Let(ExprLet), /// An if expression: `if x { y } else { z }`. @@ -70,9 +70,6 @@ impl Pretty for Expr { v.pretty(p); p.push_str("]"); } - Self::Unary(v) => v.pretty(p), - Self::Binary(v) => v.pretty(p), - Self::Call(v) => v.pretty(p), Self::Group(v) => { p.push_str("("); v.v.pretty(p); @@ -83,6 +80,9 @@ impl Pretty for Expr { v.v.pretty(p); p.push_str("}"); } + Self::Unary(v) => v.pretty(p), + Self::Binary(v) => v.pretty(p), + Self::Call(v) => v.pretty(p), Self::Let(v) => v.pretty(p), Self::If(v) => v.pretty(p), } @@ -121,6 +121,12 @@ impl Pretty for ExprDict { /// A template expression: `[*Hi* there!]`. pub type ExprTemplate = Tree; +/// A grouped expression: `(1 + 2)`. +pub type ExprGroup = Box>; + +/// A block expression: `{1 + 2}`. +pub type ExprBlock = Box>; + /// An invocation of a function: `[foo ...]`, `foo(...)`. #[derive(Debug, Clone, PartialEq)] pub struct ExprCall { @@ -306,12 +312,6 @@ impl Pretty for BinOp { } } -/// A grouped expression: `(1 + 2)`. -pub type ExprGroup = Box>; - -/// A block expression: `{1 + 2}`. -pub type ExprBlock = Box>; - /// A let expression: `let x = 1`. #[derive(Debug, Clone, PartialEq)] pub struct ExprLet { @@ -335,7 +335,7 @@ impl Pretty for ExprLet { /// An if expression: `if x { y } else { z }`. #[derive(Debug, Clone, PartialEq)] pub struct ExprIf { - /// The pattern to assign to. + /// The condition which selects the body to evaluate. pub condition: Box>, /// The expression to evaluate if the condition is true. pub if_body: Box>,