Fix lexer throwing errors when parsing a too large tuple index.
This commit is contained in:
parent
df722d6f0f
commit
8a2af4cd2e
|
@ -20,6 +20,7 @@
|
|||
- **aiken-lang**: assignment and clause guard are now always formatted on a new line
|
||||
- **aiken-lang**: unused let-bindings are now fully removed from generated code and discarded unused let-binding now raise a warning
|
||||
- **aiken-lang**: support multi-clause patterns (only as a syntactic sugar)
|
||||
- **aiken-lang**: fix lexer panic when parsing too large (> u32) tuple-indexes
|
||||
|
||||
## [v0.0.29] - 2023-MM-DD
|
||||
|
||||
|
|
|
@ -1110,7 +1110,11 @@ pub fn expr_parser(
|
|||
})
|
||||
.validate(|index, span, emit| {
|
||||
if index < 1 {
|
||||
emit(ParseError::invalid_tuple_index(span, index, None));
|
||||
emit(ParseError::invalid_tuple_index(
|
||||
span,
|
||||
index.to_string(),
|
||||
None,
|
||||
));
|
||||
Chain::TupleIndex(0, span)
|
||||
} else {
|
||||
Chain::TupleIndex(index as usize - 1, span)
|
||||
|
|
|
@ -25,7 +25,7 @@ impl ParseError {
|
|||
self
|
||||
}
|
||||
|
||||
pub fn invalid_tuple_index(span: Span, index: u32, suffix: Option<String>) -> Self {
|
||||
pub fn invalid_tuple_index(span: Span, index: String, suffix: Option<String>) -> Self {
|
||||
let hint = suffix.map(|suffix| format!("Did you mean '{index}{suffix}'?"));
|
||||
Self {
|
||||
kind: ErrorKind::InvalidTupleIndex { hint },
|
||||
|
|
|
@ -10,22 +10,26 @@ pub fn lexer() -> impl Parser<char, Vec<(Token, Span)>, Error = ParseError> {
|
|||
let int = text::int(10).map(|value| Token::Int { value });
|
||||
|
||||
let ordinal = text::int(10)
|
||||
.from_str()
|
||||
.unwrapped()
|
||||
.then_with(|index: u32| {
|
||||
.then_with(|index: String| {
|
||||
choice((just("st"), just("nd"), just("rd"), just("th")))
|
||||
.map(move |suffix| (index, suffix))
|
||||
.map(move |suffix| (index.to_string(), suffix))
|
||||
})
|
||||
.validate(|(index, suffix), span, emit| {
|
||||
let expected_suffix = Ordinal(index).suffix();
|
||||
.validate(|(index, suffix), span, emit| match index.parse() {
|
||||
Err { .. } => {
|
||||
emit(ParseError::invalid_tuple_index(span, index, None));
|
||||
Token::Ordinal { index: 0 }
|
||||
}
|
||||
Ok(index) => {
|
||||
let expected_suffix = Ordinal::<u32>(index).suffix();
|
||||
if expected_suffix != suffix {
|
||||
emit(ParseError::invalid_tuple_index(
|
||||
span,
|
||||
index,
|
||||
index.to_string(),
|
||||
Some(expected_suffix.to_string()),
|
||||
))
|
||||
}
|
||||
Token::Ordinal { index }
|
||||
}
|
||||
});
|
||||
|
||||
let op = choice((
|
||||
|
|
|
@ -1864,6 +1864,15 @@ fn parse_tuple2() {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn large_integer_constants() {
|
||||
let code = indoc! {r#"
|
||||
pub const my_big_int = 999999999999999999999999
|
||||
"#};
|
||||
|
||||
assert_definitions(code, vec![])
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn plain_bytearray_literals() {
|
||||
let code = indoc! {r#"
|
||||
|
|
Loading…
Reference in New Issue