mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-29 06:44:46 +00:00
Add granular errors regarding numeric literal parsing
This commit is contained in:
parent
f55e767035
commit
17c5fe0bff
4 changed files with 197 additions and 16 deletions
|
@ -152,7 +152,9 @@ fn chomp_number_base<'a>(
|
|||
},
|
||||
new,
|
||||
)),
|
||||
Some(NumWidth::Float(_)) => Err((Progress::MadeProgress, ENumber::End, state)),
|
||||
Some(NumWidth::Float(_)) => {
|
||||
Err((Progress::MadeProgress, ENumber::IntHasFloatSuffix, state))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -201,7 +203,9 @@ fn chomp_number_dec<'a>(
|
|||
NumLiteral::Int(string, NumericBound::Exact(iw)),
|
||||
new,
|
||||
)),
|
||||
(true, Some(NumWidth::Int(_))) => Err((Progress::MadeProgress, ENumber::End, state)),
|
||||
(true, Some(NumWidth::Int(_))) => {
|
||||
Err((Progress::MadeProgress, ENumber::FloatHasIntSuffix, state))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -282,6 +286,20 @@ fn chomp_number<'a>(
|
|||
return Err((Progress::NoProgress, ENumber::End, state));
|
||||
}
|
||||
|
||||
if bytes
|
||||
.get(0)
|
||||
.copied()
|
||||
.unwrap_or_default()
|
||||
.is_ascii_alphabetic()
|
||||
{
|
||||
// The user likely mistyped a literal suffix type here.
|
||||
return Err((
|
||||
Progress::MadeProgress,
|
||||
ENumber::LiteralSuffix,
|
||||
state.advance(start_bytes_len - bytes.len()),
|
||||
));
|
||||
}
|
||||
|
||||
return Err((Progress::MadeProgress, ENumber::End, state));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -338,6 +338,9 @@ pub enum EExpr<'a> {
|
|||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub enum ENumber {
|
||||
End,
|
||||
LiteralSuffix,
|
||||
IntHasFloatSuffix,
|
||||
FloatHasIntSuffix,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue