Macro system done in theory
too afraid to begin debugging, resting for a moment
This commit is contained in:
@@ -3,7 +3,7 @@ use std::ops::Range;
|
||||
|
||||
use ordered_float::NotNan;
|
||||
|
||||
use crate::error::{OrcErr, mk_err};
|
||||
use crate::error::{OrcErrv, mk_errv};
|
||||
use crate::interner::Interner;
|
||||
use crate::location::SrcRange;
|
||||
use crate::name::Sym;
|
||||
@@ -55,20 +55,20 @@ pub struct NumError {
|
||||
pub kind: NumErrorKind,
|
||||
}
|
||||
|
||||
pub async fn num_to_err(
|
||||
pub async fn num_to_errv(
|
||||
NumError { kind, range }: NumError,
|
||||
offset: u32,
|
||||
source: &Sym,
|
||||
i: &Interner,
|
||||
) -> OrcErr {
|
||||
mk_err(
|
||||
) -> OrcErrv {
|
||||
mk_errv(
|
||||
i.i("Failed to parse number").await,
|
||||
match kind {
|
||||
NumErrorKind::NaN => "NaN emerged during parsing",
|
||||
NumErrorKind::InvalidDigit => "non-digit character encountered",
|
||||
NumErrorKind::Overflow => "The number being described is too large or too accurate",
|
||||
},
|
||||
[SrcRange::new(offset + range.start as u32..offset + range.end as u32, source).pos().into()],
|
||||
[SrcRange::new(offset + range.start as u32..offset + range.end as u32, source)],
|
||||
)
|
||||
}
|
||||
|
||||
@@ -92,11 +92,11 @@ pub fn parse_num(string: &str) -> Result<Numeric, NumError> {
|
||||
match base_s.split_once('.') {
|
||||
None => {
|
||||
let base = int_parse(base_s, radix, pos)?;
|
||||
if let Ok(pos_exp) = u32::try_from(exponent) {
|
||||
if let Some(radical) = u64::from(radix).checked_pow(pos_exp) {
|
||||
let num = base.checked_mul(radical).and_then(|m| m.try_into().ok()).ok_or(overflow_e)?;
|
||||
return Ok(Numeric::Int(num));
|
||||
}
|
||||
if let Ok(pos_exp) = u32::try_from(exponent)
|
||||
&& let Some(radical) = u64::from(radix).checked_pow(pos_exp)
|
||||
{
|
||||
let num = base.checked_mul(radical).and_then(|m| m.try_into().ok()).ok_or(overflow_e)?;
|
||||
return Ok(Numeric::Int(num));
|
||||
}
|
||||
let f = (base as f64) * (radix as f64).powi(exponent);
|
||||
let err = NumError { range: 0..string.len(), kind: NumErrorKind::NaN };
|
||||
|
||||
Reference in New Issue
Block a user