From efb78831a7a9fe8c807c326a1bfa338b50579938 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Sun, 2 Aug 2020 11:06:45 +0200 Subject: =?UTF-8?q?Unify=20font=20and=20page=20functions=20=F0=9F=92=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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 --- src/syntax/expr.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'src/syntax/expr.rs') 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(&mut self, _: &mut Diagnostics) -> Option { + 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) -- cgit v1.2.3