Skip to content

Commit a69303d

Browse files
author
Mark Thom
committed
throw syntax error after parsing infinite floats (#2998)
1 parent 7780681 commit a69303d

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/parser/ast.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,7 @@ pub enum ParserError {
432432
BackQuotedString(usize, usize),
433433
IO(IOError),
434434
IncompleteReduction(usize, usize),
435+
InfiniteFloat(usize, usize),
435436
InvalidSingleQuotedCharacter(char),
436437
LexicalError(lexical::Error),
437438
MissingQuote(usize, usize),
@@ -447,6 +448,7 @@ impl ParserError {
447448
match self {
448449
&ParserError::BackQuotedString(line_num, col_num)
449450
| &ParserError::IncompleteReduction(line_num, col_num)
451+
| &ParserError::InfiniteFloat(line_num, col_num)
450452
| &ParserError::MissingQuote(line_num, col_num)
451453
| &ParserError::NonPrologChar(line_num, col_num)
452454
| &ParserError::ParseBigInt(line_num, col_num)
@@ -463,6 +465,9 @@ impl ParserError {
463465
ParserError::InvalidSingleQuotedCharacter(..) => {
464466
atom!("invalid_single_quoted_character")
465467
}
468+
ParserError::InfiniteFloat(..) => {
469+
atom!("infinite_float")
470+
}
466471
ParserError::IO(e) if e.kind() == ErrorKind::UnexpectedEof => {
467472
atom!("unexpected_end_of_file")
468473
}

src/parser/parser.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -976,11 +976,17 @@ impl<'a, R: CharRead> Parser<'a, R> {
976976
Token::Literal(Literal::Rational(n)) => {
977977
self.negate_number(n, negate_rat_rc, |r, _| Literal::Rational(r))
978978
}
979-
Token::Literal(Literal::Float(n)) => self.negate_number(
979+
Token::Literal(Literal::Float(n)) if F64Ptr::from_offset(n).is_infinite() => {
980+
return Err(ParserError::InfiniteFloat(
981+
self.lexer.line_num,
982+
self.lexer.col_num,
983+
));
984+
}
985+
Token::Literal(Literal::Float(n)) => self.negate_number(
980986
**n.as_ptr(),
981987
|n, _| -n,
982988
|n, arena| Literal::from(float_alloc!(n, arena)),
983-
),
989+
),
984990
Token::Literal(c) => {
985991
let atomized = atomize_constant(&self.lexer.machine_st.atom_tbl, c);
986992

0 commit comments

Comments
 (0)