]> Repositorios git - scryer-prolog.git/commitdiff
refine EOF handling more (#1873)
authorMark <[email protected]>
Sun, 9 Jul 2023 07:53:40 +0000 (01:53 -0600)
committerMark <[email protected]>
Sun, 9 Jul 2023 16:29:47 +0000 (10:29 -0600)
src/parser/lexer.rs
src/parser/parser.rs
src/read.rs
src/toplevel.pl

index 1eacc80b3673328fe6279a7d3e4fc1e4aa4cb7ac..664af935c01a1ff8cfb49305464ad74fb61b7cb9 100644 (file)
@@ -24,9 +24,9 @@ macro_rules! consume_chars_with {
 }
 
 #[derive(Debug, Default)]
-pub struct LayoutInfo {
-    pub inserted: bool,
-    pub more: bool,
+struct LayoutInfo {
+    inserted: bool,
+    more: bool,
 }
 
 #[derive(Debug, PartialEq)]
@@ -909,7 +909,7 @@ impl<'a, R: CharRead> Lexer<'a, R> {
         }
     }
 
-    pub fn consume_layout(
+    fn consume_layout(
         &mut self,
         c: Option<char>,
         layout_info: &mut LayoutInfo,
@@ -938,19 +938,28 @@ impl<'a, R: CharRead> Lexer<'a, R> {
         Ok(())
     }
 
-    fn scan_for_layout(&mut self) -> Result<bool, ParserError> {
-        let mut layout_info = LayoutInfo { inserted: false, more: true };
+    pub fn scan_for_layout(&mut self) -> Result<bool, ParserError> {
+        match self.lookahead_char() {
+            Err(e) => {
+                Err(e)
+            }
+            Ok(c) => {
+                let mut layout_info = LayoutInfo { inserted: false, more: true };
+                let mut cr = Some(c);
 
-        loop {
-            let cr = self.lookahead_char();
-            self.consume_layout(cr.ok(), &mut layout_info)?;
+                loop {
+                    self.consume_layout(cr, &mut layout_info)?;
 
-            if !layout_info.more {
-                break;
+                    if !layout_info.more {
+                        break;
+                    }
+
+                    cr = self.lookahead_char().ok();
+                }
+
+                Ok(layout_info.inserted)
             }
         }
-
-        Ok(layout_info.inserted)
     }
 
     pub fn next_token(&mut self) -> Result<Token, ParserError> {
index 41cc108ca0e57603832bc22666e42751aab4e6b7..a952f73fa97c305488ebadf242044d24bffdc4a1 100644 (file)
@@ -620,30 +620,6 @@ impl<'a, R: CharRead> Parser<'a, R> {
         false
     }
 
-    pub fn devour_whitespace(&mut self) -> Result<(), ParserError> {
-        match self.lexer.lookahead_char() {
-            Err(e) => { // if e.is_unexpected_eof() => {
-                return Err(e);
-            }
-            Ok(c) => {
-                let mut layout_info = LayoutInfo { inserted: false, more: true };
-                let mut cr = Some(c);
-
-                loop {
-                    self.lexer.consume_layout(cr, &mut layout_info)?;
-
-                    if !layout_info.more {
-                        break;
-                    }
-
-                    cr = self.lexer.lookahead_char().ok();
-                }
-            }
-        }
-
-        Ok(())
-    }
-
     pub fn reset(&mut self) {
         self.stack.clear()
     }
index 6094b38e9671ce5585afdd4dbb53459c31d47577..9a191dadb7ca6fed20cc9593252f512dcabf30cc 100644 (file)
@@ -25,12 +25,12 @@ use std::io::{Cursor, Error, ErrorKind, Read};
 type SubtermDeque = VecDeque<(usize, usize)>;
 
 pub(crate) fn devour_whitespace<'a, R: CharRead>(parser: &mut Parser<'a, R>) -> Result<bool, ParserError> {
-    match parser.devour_whitespace() {
+    match parser.lexer.scan_for_layout() {
         Err(e) if e.is_unexpected_eof() => {
             Ok(true)
         }
         Err(e) => Err(e),
-        Ok(()) => {
+        Ok(_) => {
             Ok(false)
         }
     }
index 6a87df3c93d19814a8b50abd7d6b406427d2ee33..989e083a83277a00cdb0ba4fddf3d5f6ac190481 100644 (file)
@@ -152,6 +152,7 @@ expand_op_list([Op | OtherOps], Pred, Spec, [(:- op(Pred, Spec, Op)) | OtherResu
 
 
 read_and_match :-
+    '$debug_hook',
     '$read_query_term'(_, Term, _, _, VarList),
     instruction_match(Term, VarList).