]> Repositorios git - scryer-prolog.git/commitdiff
issue an imcomplete reduction error if stream ends with tokens remaining to be parsed...
authorMark Thom <[email protected]>
Wed, 17 Mar 2021 20:23:34 +0000 (14:23 -0600)
committerMark Thom <[email protected]>
Wed, 17 Mar 2021 20:23:34 +0000 (14:23 -0600)
crates/prolog_parser/src/parser.rs

index c72d64533e00789ca7445b4f94b63285320b6d9f..364b021371a10ede11250db152c3928542c02733 100644 (file)
@@ -199,13 +199,21 @@ fn read_tokens<R: Read>(lexer: &mut Lexer<R>) -> Result<Vec<Token>, ParserError>
     let mut tokens = vec![];
 
     loop {
-        let token = lexer.next_token()?;
-        let at_end = token.is_end();
+        match lexer.next_token() {
+            Ok(token) => {
+                let at_end = token.is_end();
+                tokens.push(token);
 
-        tokens.push(token);
-
-        if at_end {
-            break;
+                if at_end {
+                    break;
+                }
+            }
+            Err(ParserError::UnexpectedEOF) if !tokens.is_empty() => {
+                return Err(ParserError::IncompleteReduction(lexer.line_num, lexer.col_num));
+            }
+            Err(e) => {
+                return Err(e);
+            }
         }
     }