]> Repositorios git - scryer-prolog.git/commitdiff
treat unexpected EOF as incomplete reduction in bracketed_comment
authorMark <[email protected]>
Fri, 7 Jul 2023 19:04:27 +0000 (13:04 -0600)
committerMark <[email protected]>
Fri, 7 Jul 2023 19:04:27 +0000 (13:04 -0600)
src/parser/char_reader.rs
src/parser/lexer.rs

index 9d6babf4603cf9992509f9676de5e1c7a21ed83e..4b08e008de6b0d70d8759d3874175debabe42c49 100644 (file)
@@ -117,7 +117,7 @@ impl<R: Read> CharReader<R> {
         // Branch using `>=` instead of the more correct `==`
         // to tell the compiler that the pos..cap slice is always valid.
         if self.pos >= self.buf.len() {
-            debug_assert!(self.pos == self.buf.len());
+            debug_assert!(self.pos >= self.buf.len());
 
             self.buf.clear();
 
index 7f5d73ed656dbb0d60dc3174b6662016c5da9048..47ff0a22057af54e9bd7248dc042b52e2565f9eb 100644 (file)
@@ -168,17 +168,32 @@ impl<'a, R: CharRead> Lexer<'a, R> {
 
             let mut c = self.lookahead_char()?;
 
-            loop {
-                while !comment_2_char!(c) {
+            let mut comment_loop = || {
+                loop {
+                    while !comment_2_char!(c) {
+                        self.skip_char(c);
+                        c = self.lookahead_char()?;
+                    }
+
                     self.skip_char(c);
                     c = self.lookahead_char()?;
+
+                    if comment_1_char!(c) {
+                        break;
+                    }
                 }
 
-                self.skip_char(c);
-                c = self.lookahead_char()?;
+                Ok(())
+            };
 
-                if comment_1_char!(c) {
-                    break;
+            match comment_loop() {
+                Err(ParserError::UnexpectedEOF) => {
+                    return Err(ParserError::IncompleteReduction(self.line_num, self.col_num));
+                }
+                Err(e) => {
+                    return Err(e);
+                }
+                Ok(_) => {
                 }
             }