summaryrefslogtreecommitdiff
path: root/src/syntax/expr.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2020-10-10 22:41:56 +0200
committerLaurenz <laurmaedje@gmail.com>2020-10-10 22:41:56 +0200
commitc216a4fc26c72938ddad60bc5fe4fa9e45263b30 (patch)
tree0a563e3076a8d0724d0361b5d81a2b8d07d15cbe /src/syntax/expr.rs
parent51bf3268ddf5db1bdd61e59bfb4a30f0463a4bfb (diff)
Flatten ast module back into syntax module 🌪
Diffstat (limited to 'src/syntax/expr.rs')
-rw-r--r--src/syntax/expr.rs68
1 files changed, 68 insertions, 0 deletions
diff --git a/src/syntax/expr.rs b/src/syntax/expr.rs
new file mode 100644
index 00000000..09729f52
--- /dev/null
+++ b/src/syntax/expr.rs
@@ -0,0 +1,68 @@
+//! Expressions.
+
+use super::*;
+
+/// An expression.
+#[derive(Debug, Clone, PartialEq)]
+pub enum Expr {
+ /// A literal: `true`, `1cm`, `"hi"`, `{_Hey!_}`.
+ Lit(Lit),
+ /// An invocation of a function: `[foo: ...]`, `foo(...)`.
+ Call(ExprCall),
+ /// A unary operation: `-x`.
+ Unary(ExprUnary),
+ /// A binary operation: `a + b`, `a / b`.
+ Binary(ExprBinary),
+}
+
+/// An invocation of a function: `[foo: ...]`, `foo(...)`.
+#[derive(Debug, Clone, PartialEq)]
+pub struct ExprCall {
+ /// The name of the function.
+ pub name: Spanned<Ident>,
+ /// The arguments to the function.
+ ///
+ /// In case of a bracketed invocation with a body, the body is _not_
+ /// included in the span for the sake of clearer error messages.
+ pub args: Spanned<LitDict>,
+}
+
+/// A unary operation: `-x`.
+#[derive(Debug, Clone, PartialEq)]
+pub struct ExprUnary {
+ /// The operator: `-`.
+ pub op: Spanned<UnOp>,
+ /// The expression to operator on: `x`.
+ pub expr: Spanned<Box<Expr>>,
+}
+
+/// A unary operator.
+#[derive(Debug, Copy, Clone, Eq, PartialEq)]
+pub enum UnOp {
+ /// The negation operator: `-`.
+ Neg,
+}
+
+/// A binary operation: `a + b`, `a / b`.
+#[derive(Debug, Clone, PartialEq)]
+pub struct ExprBinary {
+ /// The left-hand side of the operation: `a`.
+ pub lhs: Spanned<Box<Expr>>,
+ /// The operator: `+`.
+ pub op: Spanned<BinOp>,
+ /// The right-hand side of the operation: `b`.
+ pub rhs: Spanned<Box<Expr>>,
+}
+
+/// A binary operator.
+#[derive(Debug, Copy, Clone, Eq, PartialEq)]
+pub enum BinOp {
+ /// The addition operator: `+`.
+ Add,
+ /// The subtraction operator: `-`.
+ Sub,
+ /// The multiplication operator: `*`.
+ Mul,
+ /// The division operator: `/`.
+ Div,
+}