summaryrefslogtreecommitdiff
path: root/src/syntax/expr.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2020-08-02 11:06:45 +0200
committerLaurenz <laurmaedje@gmail.com>2020-08-02 11:06:45 +0200
commitefb78831a7a9fe8c807c326a1bfa338b50579938 (patch)
tree7bbba4130ac47809c72efeac796b2ca71b72e659 /src/syntax/expr.rs
parent659248d52ff9e6be4dad7c4555bd62899671ad55 (diff)
Unify font and page functions 💕
- Removes font weight and width warnings for now, will be added again later - Adds a bit hacky get_first function for tuples, will be refactored soon anyway
Diffstat (limited to 'src/syntax/expr.rs')
-rw-r--r--src/syntax/expr.rs19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/syntax/expr.rs b/src/syntax/expr.rs
index d849366c..51daf304 100644
--- a/src/syntax/expr.rs
+++ b/src/syntax/expr.rs
@@ -268,6 +268,25 @@ impl Tuple {
None
}
+ /// Extract (and remove) the first matching value without removing and
+ /// generating diagnostics for all previous items that did not match.
+ pub fn get_first<V: Value>(&mut self, _: &mut Diagnostics) -> Option<V> {
+ let mut i = 0;
+ while i < self.items.len() {
+ let expr = self.items[i].clone();
+ match V::parse(expr) {
+ Ok(output) => {
+ self.items.remove(i);
+ return Some(output)
+ }
+ Err(_) => {},
+ }
+ i += 1;
+ }
+
+ None
+ }
+
/// Extract and return an iterator over all values that match and generate
/// diagnostics for all items that do not match.
pub fn get_all<'a, V: Value>(&'a mut self, diagnostics: &'a mut Diagnostics)