From 1c40dc42e7bc7b799b77f06d25414aca59a044ba Mon Sep 17 00:00:00 2001 From: Laurenz Date: Sat, 2 Jan 2021 19:37:10 +0100 Subject: =?UTF-8?q?Dynamic=20values,=20Types,=20Arrays,=20and=20Dictionari?= =?UTF-8?q?es=20=F0=9F=9A=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Identifiers are now evaluated as variables instead of being plain values - Constants like `left` or `bold` are stored as dynamic values containing the respective rust types - We now distinguish between arrays and dictionaries to make things more intuitive (at the cost of a bit more complex parsing) - Spans were removed from collections (arrays, dictionaries), function arguments still have spans for the top-level values to enable good diagnostics --- src/syntax/expr.rs | 52 ++++++++++++++++++++++++++++++---------------------- src/syntax/node.rs | 2 +- 2 files changed, 31 insertions(+), 23 deletions(-) (limited to 'src/syntax') diff --git a/src/syntax/expr.rs b/src/syntax/expr.rs index 4c6ce872..905ade04 100644 --- a/src/syntax/expr.rs +++ b/src/syntax/expr.rs @@ -2,7 +2,6 @@ use super::*; use crate::color::RgbaColor; -use crate::eval::DictKey; use crate::geom::Unit; /// An expression. @@ -24,10 +23,22 @@ pub struct ExprCall { /// The name of the function. pub name: Spanned, /// 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, + 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; + +/// An argument to a function call: `12` or `draw: false`. +#[derive(Debug, Clone, PartialEq)] +pub enum Argument { + /// A positional arguments. + Pos(Spanned), + /// A named argument. + Named(Named), } /// A unary operation: `-x`. @@ -92,28 +103,25 @@ pub enum Lit { Color(RgbaColor), /// A string literal: `"hello!"`. Str(String), - /// A dictionary literal: `(false, 12cm, greeting: "hi")`. - Dict(LitDict), + /// An array literal: `(1, "hi", 12cm)`. + Array(Array), + /// A dictionary literal: `(color: #f79143, pattern: dashed)`. + Dict(Dict), /// A content literal: `{*Hello* there!}`. Content(SynTree), } -/// A dictionary literal: `(false, 12cm, greeting: "hi")`. -#[derive(Debug, Default, Clone, PartialEq)] -pub struct LitDict(pub Vec); +/// An array literal: `(1, "hi", 12cm)`. +pub type Array = SpanVec; -/// An entry in a dictionary literal: `false` or `greeting: "hi"`. +/// 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 LitDictEntry { - /// The key of the entry if there was one: `greeting`. - pub key: Option>, - /// The value of the entry: `"hi"`. +pub struct Named { + /// The name: `pattern`. + pub name: Spanned, + /// The right-hand side of the pair: `dashed`. pub expr: Spanned, } - -impl LitDict { - /// Create an empty dict literal. - pub fn new() -> Self { - Self::default() - } -} diff --git a/src/syntax/node.rs b/src/syntax/node.rs index b7691a70..cee810a2 100644 --- a/src/syntax/node.rs +++ b/src/syntax/node.rs @@ -30,7 +30,7 @@ pub enum SynNode { Expr(Expr), } -/// A section heading: `# ...`. +/// A section heading: `# Introduction`. #[derive(Debug, Clone, PartialEq)] pub struct NodeHeading { /// The section depth (numer of hashtags minus 1). -- cgit v1.2.3