diff options
| author | Laurenz <laurmaedje@gmail.com> | 2021-01-02 19:37:10 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2021-01-02 19:37:10 +0100 |
| commit | 1c40dc42e7bc7b799b77f06d25414aca59a044ba (patch) | |
| tree | ea8bdedaebf59f5bc601346b0108236c7264a29d /src/library/mod.rs | |
| parent | 8cad78481cd52680317032c3bb84cacda5666489 (diff) | |
Dynamic values, Types, Arrays, and Dictionaries 🚀
- 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
Diffstat (limited to 'src/library/mod.rs')
| -rw-r--r-- | src/library/mod.rs | 81 |
1 files changed, 55 insertions, 26 deletions
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 } |
