From 73276b620782a93bad16a0d5eb7cbd14caf985e6 Mon Sep 17 00:00:00 2001 From: Christian Duerr Date: Sun, 27 Aug 2023 18:48:55 +0200 Subject: Update regex-automata to v0.3.6 This seems like a sensible first step before looking into #7097. --- alacritty/src/config/ui_config.rs | 21 ++++++++++++--------- alacritty/src/display/hint.rs | 5 +++-- 2 files changed, 15 insertions(+), 11 deletions(-) (limited to 'alacritty/src') diff --git a/alacritty/src/config/ui_config.rs b/alacritty/src/config/ui_config.rs index d2e8e600..eb64f5b8 100644 --- a/alacritty/src/config/ui_config.rs +++ b/alacritty/src/config/ui_config.rs @@ -483,11 +483,11 @@ pub struct LazyRegex(Rc>); impl LazyRegex { /// Execute a function with the compiled regex DFAs as parameter. - pub fn with_compiled(&self, mut f: F) -> T + pub fn with_compiled(&self, f: F) -> Option where F: FnMut(&RegexSearch) -> T, { - f(self.0.borrow_mut().compiled()) + self.0.borrow_mut().compiled().map(f) } } @@ -506,6 +506,7 @@ impl<'de> Deserialize<'de> for LazyRegex { pub enum LazyRegexVariant { Compiled(Box), Pattern(String), + Uncompilable, } impl LazyRegexVariant { @@ -513,27 +514,29 @@ impl LazyRegexVariant { /// /// If the regex is not already compiled, this will compile the DFAs and store them for future /// access. - fn compiled(&mut self) -> &RegexSearch { + fn compiled(&mut self) -> Option<&RegexSearch> { // Check if the regex has already been compiled. let regex = match self { - Self::Compiled(regex_search) => return regex_search, + Self::Compiled(regex_search) => return Some(regex_search), + Self::Uncompilable => return None, Self::Pattern(regex) => regex, }; // Compile the regex. let regex_search = match RegexSearch::new(regex) { Ok(regex_search) => regex_search, - Err(error) => { - error!("hint regex is invalid: {}", error); - RegexSearch::new("").unwrap() + Err(err) => { + error!("could not compile hint regex: {err}"); + *self = Self::Uncompilable; + return None; }, }; *self = Self::Compiled(Box::new(regex_search)); // Return a reference to the compiled DFAs. match self { - Self::Compiled(dfas) => dfas, - Self::Pattern(_) => unreachable!(), + Self::Compiled(dfas) => Some(dfas), + _ => unreachable!(), } } } diff --git a/alacritty/src/display/hint.rs b/alacritty/src/display/hint.rs index 57087e45..774b3cdb 100644 --- a/alacritty/src/display/hint.rs +++ b/alacritty/src/display/hint.rs @@ -387,9 +387,10 @@ pub fn highlighted_at( }); } - if let Some(bounds) = hint.content.regex.as_ref().and_then(|regex| { + let bounds = hint.content.regex.as_ref().and_then(|regex| { regex.with_compiled(|regex| regex_match_at(term, point, regex, hint.post_processing)) - }) { + }); + if let Some(bounds) = bounds.flatten() { return Some(HintMatch { bounds, action: hint.action.clone(), hyperlink: None }); } -- cgit