summaryrefslogtreecommitdiff
path: root/src/syntax/func/maps.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/syntax/func/maps.rs')
-rw-r--r--src/syntax/func/maps.rs67
1 files changed, 33 insertions, 34 deletions
diff --git a/src/syntax/func/maps.rs b/src/syntax/func/maps.rs
index 44d8e1aa..2ac70223 100644
--- a/src/syntax/func/maps.rs
+++ b/src/syntax/func/maps.rs
@@ -1,18 +1,17 @@
//! Deduplicating maps and keys for argument parsing.
-use crate::problem::Problems;
+use crate::diagnostic::Diagnostics;
use crate::layout::prelude::*;
-use crate::size::{PSize, ValueBox};
+use crate::length::{ScaleLength, Value4};
use crate::syntax::span::Spanned;
use super::keys::*;
use super::values::*;
use super::*;
-
/// A map which deduplicates redundant arguments.
///
/// Whenever a duplicate argument is inserted into the map, through the
-/// functions `from_iter`, `insert` or `extend` an problems is added to the error
+/// functions `from_iter`, `insert` or `extend` an diagnostics is added to the error
/// list that needs to be passed to those functions.
///
/// All entries need to have span information to enable the error reporting.
@@ -28,27 +27,27 @@ impl<K, V> DedupMap<K, V> where K: Eq {
}
/// Create a new map from an iterator of spanned keys and values.
- pub fn from_iter<I>(problems: &mut Problems, iter: I) -> DedupMap<K, V>
+ pub fn from_iter<I>(diagnostics: &mut Diagnostics, iter: I) -> DedupMap<K, V>
where I: IntoIterator<Item=Spanned<(K, V)>> {
let mut map = DedupMap::new();
- map.extend(problems, iter);
+ map.extend(diagnostics, iter);
map
}
/// Add a spanned key-value pair.
- pub fn insert(&mut self, problems: &mut Problems, entry: Spanned<(K, V)>) {
+ pub fn insert(&mut self, diagnostics: &mut Diagnostics, entry: Spanned<(K, V)>) {
if self.map.iter().any(|e| e.v.0 == entry.v.0) {
- problems.push(error!(entry.span, "duplicate argument"));
+ diagnostics.push(error!(entry.span, "duplicate argument"));
} else {
self.map.push(entry);
}
}
/// Add multiple spanned key-value pairs.
- pub fn extend<I>(&mut self, problems: &mut Problems, items: I)
+ pub fn extend<I>(&mut self, diagnostics: &mut Diagnostics, items: I)
where I: IntoIterator<Item=Spanned<(K, V)>> {
for item in items.into_iter() {
- self.insert(problems, item);
+ self.insert(diagnostics, item);
}
}
@@ -71,15 +70,15 @@ impl<K, V> DedupMap<K, V> where K: Eq {
}
/// Create a new map where keys and values are mapped to new keys and
- /// values. When the mapping introduces new duplicates, problems are
+ /// values. When the mapping introduces new duplicates, diagnostics are
/// generated.
- pub fn dedup<F, K2, V2>(&self, problems: &mut Problems, mut f: F) -> DedupMap<K2, V2>
+ pub fn dedup<F, K2, V2>(&self, diagnostics: &mut Diagnostics, mut f: F) -> DedupMap<K2, V2>
where F: FnMut(&K, &V) -> (K2, V2), K2: Eq {
let mut map = DedupMap::new();
for Spanned { v: (key, value), span } in self.map.iter() {
let (key, value) = f(key, value);
- map.insert(problems, Spanned { v: (key, value), span: *span });
+ map.insert(diagnostics, Spanned { v: (key, value), span: *span });
}
map
@@ -98,21 +97,21 @@ pub struct AxisMap<V>(DedupMap<AxisKey, V>);
impl<V: Value> AxisMap<V> {
/// Parse an axis map from the object.
pub fn parse<K>(
- problems: &mut Problems,
+ diagnostics: &mut Diagnostics,
object: &mut Object,
) -> AxisMap<V> where K: Key + Into<AxisKey> {
let values: Vec<_> = object
- .get_all_spanned::<K, V>(problems)
+ .get_all_spanned::<K, V>(diagnostics)
.map(|s| s.map(|(k, v)| (k.into(), v)))
.collect();
- AxisMap(DedupMap::from_iter(problems, values))
+ AxisMap(DedupMap::from_iter(diagnostics, values))
}
/// Deduplicate from specific or generic to just specific axes.
- pub fn dedup(&self, problems: &mut Problems, axes: LayoutAxes) -> DedupMap<SpecificAxis, V>
+ pub fn dedup(&self, diagnostics: &mut Diagnostics, axes: LayoutAxes) -> DedupMap<SpecificAxis, V>
where V: Clone {
- self.0.dedup(problems, |key, val| (key.to_specific(axes), val.clone()))
+ self.0.dedup(diagnostics, |key, val| (key.to_specific(axes), val.clone()))
}
}
@@ -124,23 +123,23 @@ pub struct PosAxisMap<V>(DedupMap<PosAxisKey, V>);
impl<V: Value> PosAxisMap<V> {
/// Parse a positional/axis map from the function arguments.
pub fn parse<K>(
- problems: &mut Problems,
+ diagnostics: &mut Diagnostics,
args: &mut FuncArgs,
) -> PosAxisMap<V> where K: Key + Into<AxisKey> {
let mut map = DedupMap::new();
for &key in &[PosAxisKey::First, PosAxisKey::Second] {
- if let Some(Spanned { v, span }) = args.pos.get::<Spanned<V>>(problems) {
- map.insert(problems, Spanned { v: (key, v), span })
+ if let Some(Spanned { v, span }) = args.pos.get::<Spanned<V>>(diagnostics) {
+ map.insert(diagnostics, Spanned { v: (key, v), span })
}
}
let keywords: Vec<_> = args.key
- .get_all_spanned::<K, V>(problems)
+ .get_all_spanned::<K, V>(diagnostics)
.map(|s| s.map(|(k, v)| (PosAxisKey::Keyword(k.into()), v)))
.collect();
- map.extend(problems, keywords);
+ map.extend(diagnostics, keywords);
PosAxisMap(map)
}
@@ -149,7 +148,7 @@ impl<V: Value> PosAxisMap<V> {
/// or specific axes to just generic axes.
pub fn dedup<F>(
&self,
- problems: &mut Problems,
+ diagnostics: &mut Diagnostics,
axes: LayoutAxes,
mut f: F,
) -> DedupMap<GenericAxis, V>
@@ -157,7 +156,7 @@ impl<V: Value> PosAxisMap<V> {
F: FnMut(&V) -> Option<GenericAxis>,
V: Clone,
{
- self.0.dedup(problems, |key, val| {
+ self.0.dedup(diagnostics, |key, val| {
(match key {
PosAxisKey::First => f(val).unwrap_or(GenericAxis::Primary),
PosAxisKey::Second => f(val).unwrap_or(GenericAxis::Secondary),
@@ -171,24 +170,24 @@ impl<V: Value> PosAxisMap<V> {
/// A map for storing padding given for a combination of all sides, opposing
/// sides or single sides.
#[derive(Debug, Clone, PartialEq)]
-pub struct PaddingMap(DedupMap<PaddingKey<AxisKey>, Option<PSize>>);
+pub struct PaddingMap(DedupMap<PaddingKey<AxisKey>, Option<ScaleLength>>);
impl PaddingMap {
/// Parse a padding map from the function arguments.
- pub fn parse(problems: &mut Problems, args: &mut FuncArgs) -> PaddingMap {
+ pub fn parse(diagnostics: &mut Diagnostics, args: &mut FuncArgs) -> PaddingMap {
let mut map = DedupMap::new();
- let all = args.pos.get::<Spanned<Defaultable<PSize>>>(problems);
+ let all = args.pos.get::<Spanned<Defaultable<ScaleLength>>>(diagnostics);
if let Some(Spanned { v, span }) = all {
- map.insert(problems, Spanned { v: (PaddingKey::All, v.into()), span });
+ map.insert(diagnostics, Spanned { v: (PaddingKey::All, v.into()), span });
}
let paddings: Vec<_> = args.key
- .get_all_spanned::<PaddingKey<AxisKey>, Defaultable<PSize>>(problems)
+ .get_all_spanned::<PaddingKey<AxisKey>, Defaultable<ScaleLength>>(diagnostics)
.map(|s| s.map(|(k, v)| (k, v.into())))
.collect();
- map.extend(problems, paddings);
+ map.extend(diagnostics, paddings);
PaddingMap(map)
}
@@ -196,13 +195,13 @@ impl PaddingMap {
/// Apply the specified padding on a value box of optional, scalable sizes.
pub fn apply(
&self,
- problems: &mut Problems,
+ diagnostics: &mut Diagnostics,
axes: LayoutAxes,
- padding: &mut ValueBox<Option<PSize>>
+ padding: &mut Value4<Option<ScaleLength>>
) {
use PaddingKey::*;
- let map = self.0.dedup(problems, |key, &val| {
+ let map = self.0.dedup(diagnostics, |key, &val| {
(match key {
All => All,
Both(axis) => Both(axis.to_specific(axes)),