]> Repositorios git - scryer-prolog.git/commitdiff
throw syntax error after parsing infinite floats (#2998)
authorMark Thom <[email protected]>
Tue, 8 Jul 2025 04:30:04 +0000 (21:30 -0700)
committerMark Thom <[email protected]>
Tue, 8 Jul 2025 04:30:04 +0000 (21:30 -0700)
src/parser/ast.rs
src/parser/parser.rs

index 06c1ab9e0eed4666f9c91fe682ab14449369f430..9a400c361be0163dcdd36d59af85faa331d22638 100644 (file)
@@ -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")
             }
index eee22294d0758019e8ee537dcbd0bf967a4db5cc..dd7b007b8edbe36a317e104de3e0cc4cc7051ba7 100644 (file)
@@ -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);