Add Token::original_span rather than making Token::span pub

This commit is contained in:
Louis Dureuil 2023-02-02 15:03:34 +01:00
parent d80ce00623
commit ae8660e585
No known key found for this signature in database
2 changed files with 10 additions and 5 deletions

View File

@ -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<String>,
@ -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<f64, Error> {
let value: f64 = self.value().parse().map_err(|e| self.as_external_error(e))?;
if value.is_finite() {

View File

@ -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 {