From aae67bd572ad86f4c57e364daa51a9dc883b8913 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Sun, 3 Jan 2021 00:12:09 +0100 Subject: =?UTF-8?q?Move=20and=20rename=20many=20things=20=F0=9F=9A=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/syntax/expr.rs | 53 +++++++++++++++++++++++++++-------------------------- 1 file changed, 27 insertions(+), 26 deletions(-) (limited to 'src/syntax/expr.rs') diff --git a/src/syntax/expr.rs b/src/syntax/expr.rs index 905ade04..94d07b07 100644 --- a/src/syntax/expr.rs +++ b/src/syntax/expr.rs @@ -1,5 +1,3 @@ -//! Expressions. - use super::*; use crate::color::RgbaColor; use crate::geom::Unit; @@ -7,7 +5,7 @@ use crate::geom::Unit; /// An expression. #[derive(Debug, Clone, PartialEq)] pub enum Expr { - /// A literal: `true`, `1cm`, `"hi"`, `{_Hey!_}`. + /// A literal: `true`, `1cm`, `"hi"`. Lit(Lit), /// An invocation of a function: `[foo ...]`, `foo(...)`. Call(ExprCall), @@ -15,6 +13,12 @@ pub enum Expr { Unary(ExprUnary), /// A binary operation: `a + b`, `a / b`. Binary(ExprBinary), + /// An array expression: `(1, "hi", 12cm)`. + Array(ExprArray), + /// A dictionary expression: `(color: #f79143, pattern: dashed)`. + Dict(ExprDict), + /// A content expression: `{*Hello* there!}`. + Content(ExprContent), } /// An invocation of a function: `[foo ...]`, `foo(...)`. @@ -23,14 +27,14 @@ pub struct ExprCall { /// The name of the function. pub name: Spanned, /// The arguments to the function. - pub args: Spanned, + pub args: Spanned, } /// The arguments to a function: `12, draw: false`. /// /// 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 type Arguments = Vec; +pub type ExprArgs = Vec; /// An argument to a function call: `12` or `draw: false`. #[derive(Debug, Clone, PartialEq)] @@ -41,6 +45,15 @@ pub enum Argument { Named(Named), } +/// A pair of a name and an expression: `pattern: dashed`. +#[derive(Debug, Clone, PartialEq)] +pub struct Named { + /// The name: `pattern`. + pub name: Spanned, + /// The right-hand side of the pair: `dashed`. + pub expr: Spanned, +} + /// A unary operation: `-x`. #[derive(Debug, Clone, PartialEq)] pub struct ExprUnary { @@ -81,6 +94,15 @@ pub enum BinOp { Div, } +/// An array expression: `(1, "hi", 12cm)`. +pub type ExprArray = SpanVec; + +/// A dictionary expression: `(color: #f79143, pattern: dashed)`. +pub type ExprDict = Vec; + +/// A content expression: `{*Hello* there!}`. +pub type ExprContent = Tree; + /// A literal. #[derive(Debug, Clone, PartialEq)] pub enum Lit { @@ -103,25 +125,4 @@ pub enum Lit { Color(RgbaColor), /// A string literal: `"hello!"`. Str(String), - /// An array literal: `(1, "hi", 12cm)`. - Array(Array), - /// A dictionary literal: `(color: #f79143, pattern: dashed)`. - Dict(Dict), - /// A content literal: `{*Hello* there!}`. - Content(SynTree), -} - -/// An array literal: `(1, "hi", 12cm)`. -pub type Array = SpanVec; - -/// A dictionary literal: `(color: #f79143, pattern: dashed)`. -pub type Dict = Vec; - -/// A pair of a name and an expression: `pattern: dashed`. -#[derive(Debug, Clone, PartialEq)] -pub struct Named { - /// The name: `pattern`. - pub name: Spanned, - /// The right-hand side of the pair: `dashed`. - pub expr: Spanned, } -- cgit v1.2.3