diff options
| author | Laurenz <laurmaedje@gmail.com> | 2021-01-03 00:12:09 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2021-01-03 00:12:09 +0100 |
| commit | aae67bd572ad86f4c57e364daa51a9dc883b8913 (patch) | |
| tree | 0aba021e0748ebad2197ea390385ec5f93ccbc6e /src/syntax/expr.rs | |
| parent | 1c40dc42e7bc7b799b77f06d25414aca59a044ba (diff) | |
Move and rename many things 🚛
Diffstat (limited to 'src/syntax/expr.rs')
| -rw-r--r-- | src/syntax/expr.rs | 53 |
1 files changed, 27 insertions, 26 deletions
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<Ident>, /// The arguments to the function. - pub args: Spanned<Arguments>, + pub args: Spanned<ExprArgs>, } /// 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<Argument>; +pub type ExprArgs = Vec<Argument>; /// 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<Ident>, + /// The right-hand side of the pair: `dashed`. + pub expr: Spanned<Expr>, +} + /// 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<Expr>; + +/// A dictionary expression: `(color: #f79143, pattern: dashed)`. +pub type ExprDict = Vec<Named>; + +/// 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<Expr>; - -/// A dictionary literal: `(color: #f79143, pattern: dashed)`. -pub type Dict = Vec<Named>; - -/// A pair of a name and an expression: `pattern: dashed`. -#[derive(Debug, Clone, PartialEq)] -pub struct Named { - /// The name: `pattern`. - pub name: Spanned<Ident>, - /// The right-hand side of the pair: `dashed`. - pub expr: Spanned<Expr>, } |
