From ae8660e585a7fc50515e61c9ff5b1e1806d7f9b7 Mon Sep 17 00:00:00 2001 From: Louis Dureuil Date: Thu, 2 Feb 2023 15:03:34 +0100 Subject: [PATCH] Add Token::original_span rather than making Token::span pub --- filter-parser/src/lib.rs | 7 ++++++- milli/src/search/facet/filter.rs | 8 ++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/filter-parser/src/lib.rs b/filter-parser/src/lib.rs index 231050401..3f6b81ea4 100644 --- a/filter-parser/src/lib.rs +++ b/filter-parser/src/lib.rs @@ -71,7 +71,7 @@ const MAX_FILTER_DEPTH: usize = 200; #[derive(Debug, Clone, Eq)] pub struct Token<'a> { /// The token in the original input, it should be used when possible. - pub span: Span<'a>, + span: Span<'a>, /// If you need to modify the original input you can use the `value` field /// to store your modified input. value: Option, @@ -100,6 +100,11 @@ impl<'a> Token<'a> { Error::new_from_external(self.span, error) } + /// Returns a copy of the span this token was created with. + pub fn original_span(&self) -> Span<'a> { + self.span + } + pub fn parse_finite_float(&self) -> Result { let value: f64 = self.value().parse().map_err(|e| self.as_external_error(e))?; if value.is_finite() { diff --git a/milli/src/search/facet/filter.rs b/milli/src/search/facet/filter.rs index 15edb1249..903f4fa94 100644 --- a/milli/src/search/facet/filter.rs +++ b/milli/src/search/facet/filter.rs @@ -413,7 +413,7 @@ impl<'a> Filter<'a> { } let geo_lat_token = - Token::new(top_left_point[0].span, Some("_geo.lat".to_string())); + Token::new(top_left_point[0].original_span(), Some("_geo.lat".to_string())); let condition_lat = FilterCondition::Condition { fid: geo_lat_token, @@ -430,11 +430,11 @@ impl<'a> Filter<'a> { )?; let geo_lng_token = - Token::new(top_left_point[1].span, Some("_geo.lng".to_string())); + Token::new(top_left_point[1].original_span(), Some("_geo.lng".to_string())); let min_lng_token = - Token::new(top_left_point[1].span, Some("-180.0".to_string())); + Token::new(top_left_point[1].original_span(), Some("-180.0".to_string())); let max_lng_token = - Token::new(top_left_point[1].span, Some("180.0".to_string())); + Token::new(top_left_point[1].original_span(), Some("180.0".to_string())); let selected_lng = if top_left[1] > bottom_right[1] { let condition_left = FilterCondition::Condition {