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/library/mod.rs | 81 ++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 55 insertions(+), 26 deletions(-) (limited to 'src/library/mod.rs') diff --git a/src/library/mod.rs b/src/library/mod.rs index 806b0275..1cc7b9e9 100644 --- a/src/library/mod.rs +++ b/src/library/mod.rs @@ -8,31 +8,60 @@ pub use insert::*; pub use layout::*; pub use style::*; -use crate::eval::{Scope, ValueFunc}; - -macro_rules! std { - ($($func:expr $(=> $name:expr)?),* $(,)?) => { - /// The scope containing all standard library functions. - pub fn _std() -> Scope { - let mut std = Scope::new(); - $( - let _name = stringify!($func); - $(let _name = $name;)? - std.set(_name, ValueFunc::new($func)); - )* - std - } - }; -} +use fontdock::{FontStretch, FontStyle, FontWeight}; + +use crate::eval::Scope; +use crate::geom::Dir; + +/// The scope containing the standard library. +pub fn _std() -> Scope { + let mut std = Scope::new(); + + // Functions. + std.set("align", align); + std.set("box", boxed); + std.set("font", font); + std.set("h", h); + std.set("image", image); + std.set("page", page); + std.set("pagebreak", pagebreak); + std.set("rgb", rgb); + std.set("v", v); + + // Constants. + std.set("left", Alignment::Left); + std.set("center", Alignment::Center); + std.set("right", Alignment::Right); + std.set("top", Alignment::Top); + std.set("bottom", Alignment::Bottom); + std.set("ltr", Dir::LTR); + std.set("rtl", Dir::RTL); + std.set("ttb", Dir::TTB); + std.set("btt", Dir::BTT); + std.set("serif", FontFamily::Serif); + std.set("sans-serif", FontFamily::SansSerif); + std.set("monospace", FontFamily::Monospace); + std.set("normal", FontStyle::Normal); + std.set("italic", FontStyle::Italic); + std.set("oblique", FontStyle::Oblique); + std.set("thin", FontWeight::THIN); + std.set("extralight", FontWeight::EXTRALIGHT); + std.set("light", FontWeight::LIGHT); + std.set("regular", FontWeight::REGULAR); + std.set("medium", FontWeight::MEDIUM); + std.set("semibold", FontWeight::SEMIBOLD); + std.set("bold", FontWeight::BOLD); + std.set("extrabold", FontWeight::EXTRABOLD); + std.set("black", FontWeight::BLACK); + std.set("ultra-condensed", FontStretch::UltraCondensed); + std.set("extra-condensed", FontStretch::ExtraCondensed); + std.set("condensed", FontStretch::Condensed); + std.set("semi-condensed", FontStretch::SemiCondensed); + std.set("normal", FontStretch::Normal); + std.set("semi-expanded", FontStretch::SemiExpanded); + std.set("expanded", FontStretch::Expanded); + std.set("extra-expanded", FontStretch::ExtraExpanded); + std.set("ultra-expanded", FontStretch::UltraExpanded); -std! { - align, - boxed => "box", - font, - h, - image, - page, - pagebreak, - rgb, - v, + std } -- cgit v1.2.3