From: Mark Thom Date: Tue, 8 Jul 2025 04:30:04 +0000 (-0700) Subject: throw syntax error after parsing infinite floats (#2998) X-Git-Tag: v0.10.0~39 X-Git-Url: https://git.sagredo.dev/?a=commitdiff_plain;h=a69303dc9315592bedc3374ca5a92e13f2be0b8b;p=scryer-prolog.git throw syntax error after parsing infinite floats (#2998) --- diff --git a/src/parser/ast.rs b/src/parser/ast.rs index 06c1ab9e..9a400c36 100644 --- a/src/parser/ast.rs +++ b/src/parser/ast.rs @@ -432,6 +432,7 @@ pub enum ParserError { BackQuotedString(usize, usize), IO(IOError), IncompleteReduction(usize, usize), + InfiniteFloat(usize, usize), InvalidSingleQuotedCharacter(char), LexicalError(lexical::Error), MissingQuote(usize, usize), @@ -447,6 +448,7 @@ impl ParserError { match self { &ParserError::BackQuotedString(line_num, col_num) | &ParserError::IncompleteReduction(line_num, col_num) + | &ParserError::InfiniteFloat(line_num, col_num) | &ParserError::MissingQuote(line_num, col_num) | &ParserError::NonPrologChar(line_num, col_num) | &ParserError::ParseBigInt(line_num, col_num) @@ -463,6 +465,9 @@ impl ParserError { ParserError::InvalidSingleQuotedCharacter(..) => { atom!("invalid_single_quoted_character") } + ParserError::InfiniteFloat(..) => { + atom!("infinite_float") + } ParserError::IO(e) if e.kind() == ErrorKind::UnexpectedEof => { atom!("unexpected_end_of_file") } diff --git a/src/parser/parser.rs b/src/parser/parser.rs index eee22294..dd7b007b 100644 --- a/src/parser/parser.rs +++ b/src/parser/parser.rs @@ -976,11 +976,17 @@ impl<'a, R: CharRead> Parser<'a, R> { Token::Literal(Literal::Rational(n)) => { self.negate_number(n, negate_rat_rc, |r, _| Literal::Rational(r)) } - Token::Literal(Literal::Float(n)) => self.negate_number( + Token::Literal(Literal::Float(n)) if F64Ptr::from_offset(n).is_infinite() => { + return Err(ParserError::InfiniteFloat( + self.lexer.line_num, + self.lexer.col_num, + )); + } + Token::Literal(Literal::Float(n)) => self.negate_number( **n.as_ptr(), |n, _| -n, |n, arena| Literal::from(float_alloc!(n, arena)), - ), + ), Token::Literal(c) => { let atomized = atomize_constant(&self.lexer.machine_st.atom_tbl, c);