Change token to use FloatWrapper.
This commit is contained in:
parent
aea5ec50c9
commit
2846d1b63f
12
src/ast.rs
12
src/ast.rs
@ -10,6 +10,7 @@ use crate::stdlib::{
|
|||||||
hash::Hash,
|
hash::Hash,
|
||||||
num::{NonZeroU64, NonZeroUsize},
|
num::{NonZeroU64, NonZeroUsize},
|
||||||
ops::{Add, AddAssign},
|
ops::{Add, AddAssign},
|
||||||
|
str::FromStr,
|
||||||
string::String,
|
string::String,
|
||||||
vec,
|
vec,
|
||||||
vec::Vec,
|
vec::Vec,
|
||||||
@ -1126,7 +1127,7 @@ pub struct FnCallExpr {
|
|||||||
|
|
||||||
/// A type that wraps a [`FLOAT`] and implements [`Hash`].
|
/// A type that wraps a [`FLOAT`] and implements [`Hash`].
|
||||||
#[cfg(not(feature = "no_float"))]
|
#[cfg(not(feature = "no_float"))]
|
||||||
#[derive(Clone, Copy)]
|
#[derive(Clone, Copy, PartialEq, PartialOrd)]
|
||||||
pub struct FloatWrapper(FLOAT);
|
pub struct FloatWrapper(FLOAT);
|
||||||
|
|
||||||
#[cfg(not(feature = "no_float"))]
|
#[cfg(not(feature = "no_float"))]
|
||||||
@ -1195,6 +1196,15 @@ impl From<FLOAT> for FloatWrapper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(not(feature = "no_float"))]
|
||||||
|
impl FromStr for FloatWrapper {
|
||||||
|
type Err = <FLOAT as FromStr>::Err;
|
||||||
|
|
||||||
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||||
|
FLOAT::from_str(s).map(Into::<Self>::into)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(not(feature = "no_float"))]
|
#[cfg(not(feature = "no_float"))]
|
||||||
impl FloatWrapper {
|
impl FloatWrapper {
|
||||||
pub const fn new(value: FLOAT) -> Self {
|
pub const fn new(value: FLOAT) -> Self {
|
||||||
|
@ -15,7 +15,7 @@ use crate::stdlib::{
|
|||||||
use crate::{Engine, LexError, StaticVec, INT};
|
use crate::{Engine, LexError, StaticVec, INT};
|
||||||
|
|
||||||
#[cfg(not(feature = "no_float"))]
|
#[cfg(not(feature = "no_float"))]
|
||||||
use crate::FLOAT;
|
use crate::ast::FloatWrapper;
|
||||||
|
|
||||||
type LERR = LexError;
|
type LERR = LexError;
|
||||||
|
|
||||||
@ -153,7 +153,7 @@ impl fmt::Debug for Position {
|
|||||||
/// # Volatile Data Structure
|
/// # Volatile Data Structure
|
||||||
///
|
///
|
||||||
/// This type is volatile and may change.
|
/// This type is volatile and may change.
|
||||||
#[derive(Debug, PartialEq, Clone)]
|
#[derive(Debug, PartialEq, Clone, Hash)]
|
||||||
pub enum Token {
|
pub enum Token {
|
||||||
/// An `INT` constant.
|
/// An `INT` constant.
|
||||||
IntegerConstant(INT),
|
IntegerConstant(INT),
|
||||||
@ -161,7 +161,7 @@ pub enum Token {
|
|||||||
///
|
///
|
||||||
/// Reserved under the `no_float` feature.
|
/// Reserved under the `no_float` feature.
|
||||||
#[cfg(not(feature = "no_float"))]
|
#[cfg(not(feature = "no_float"))]
|
||||||
FloatConstant(FLOAT),
|
FloatConstant(FloatWrapper),
|
||||||
/// An identifier.
|
/// An identifier.
|
||||||
Identifier(String),
|
Identifier(String),
|
||||||
/// A character constant.
|
/// A character constant.
|
||||||
@ -1180,7 +1180,8 @@ fn get_next_token_inner(
|
|||||||
|
|
||||||
// If integer parsing is unnecessary, try float instead
|
// If integer parsing is unnecessary, try float instead
|
||||||
#[cfg(not(feature = "no_float"))]
|
#[cfg(not(feature = "no_float"))]
|
||||||
let num = num.or_else(|_| FLOAT::from_str(&out).map(Token::FloatConstant));
|
let num =
|
||||||
|
num.or_else(|_| FloatWrapper::from_str(&out).map(Token::FloatConstant));
|
||||||
|
|
||||||
return Some((
|
return Some((
|
||||||
num.unwrap_or_else(|_| {
|
num.unwrap_or_else(|_| {
|
||||||
|
Loading…
Reference in New Issue
Block a user