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() {