summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2021-01-20 21:50:51 +0100
committerLaurenz <laurmaedje@gmail.com>2021-01-20 21:50:51 +0100
commit0de4f3ed7bb20a94fd58f93b0793d3b5a8e13972 (patch)
tree9576820bd26e92e8e526a23058e8c53e94b257f7 /src
parent84ba547c7c80e45cc8edafcde8714973bb2a3a2f (diff)
Reorder and fix docs ✔
Diffstat (limited to 'src')
-rw-r--r--src/eval/mod.rs4
-rw-r--r--src/syntax/expr.rs28
2 files changed, 16 insertions, 16 deletions
diff --git a/src/eval/mod.rs b/src/eval/mod.rs
index 50043698..54fe2324 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 29e143b2..c1af2335 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<Spanned<Expr>>;
+
+/// A block expression: `{1 + 2}`.
+pub type ExprBlock = Box<Spanned<Expr>>;
+
/// 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<Spanned<Expr>>;
-
-/// A block expression: `{1 + 2}`.
-pub type ExprBlock = Box<Spanned<Expr>>;
-
/// 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<Spanned<Expr>>,
/// The expression to evaluate if the condition is true.
pub if_body: Box<Spanned<Expr>>,