From 2173a8e3cb549fd282a6000513d9ba10e22ff340 Mon Sep 17 00:00:00 2001 From: Mark Thom Date: Tue, 22 Mar 2022 22:48:51 -0600 Subject: [PATCH] recognize missing syntax errors (#1354, #1361) --- src/heap_print.rs | 9 +-------- src/parser/lexer.rs | 8 ++------ src/read.rs | 2 -- 3 files changed, 3 insertions(+), 16 deletions(-) diff --git a/src/heap_print.rs b/src/heap_print.rs index 7d00c0d0..8ee3ec67 100644 --- a/src/heap_print.rs +++ b/src/heap_print.rs @@ -176,15 +176,8 @@ fn char_to_string(is_quoted: bool, c: char) -> String { '\'' | '\n' | '\r' | '\t' | '\u{0b}' | '\u{0c}' | '\u{08}' | '\u{07}' | '"' | '\\' => { c.to_string() } - '\u{0}'..='\u{1f}' => format!("\\x{:x}", c as u32), // print all other control characters in hex. + '\u{0}'..='\u{1f}' => format!("\\x{:x}\\", c as u32), // print all other control characters in hex. _ => c.to_string(), - /* - '\u{a0}'..='\u{d6}' => c.to_string(), - '\u{d8}'..='\u{f6}' => c.to_string(), - '\u{f8}'..='\u{74f}' => c.to_string(), - '\x20'..='\x7e' => c.to_string(), - _ => format!("\\x{:x}\\", c as u32), - */ } } diff --git a/src/parser/lexer.rs b/src/parser/lexer.rs index 4696b226..4c541016 100644 --- a/src/parser/lexer.rs +++ b/src/parser/lexer.rs @@ -367,7 +367,7 @@ impl<'a, R: CharRead> Lexer<'a, R> { if hexadecimal_digit_char!(c) { self.escape_sequence_to_char(|c| hexadecimal_digit_char!(c), 16) } else { - Err(ParserError::UnexpectedChar(c, self.line_num, self.col_num)) + Err(ParserError::IncompleteReduction(self.line_num, self.col_num)) } } @@ -400,11 +400,7 @@ impl<'a, R: CharRead> Lexer<'a, R> { }, ) } else { - // on failure, restore the token characters and backslash. - // self.reader.put_back_all(token.chars().map(Ok)); - // self.reader.put_back(Ok('\\')); - - Err(ParserError::UnexpectedChar(c, self.line_num, self.col_num)) + Err(ParserError::IncompleteReduction(self.line_num, self.col_num)) } } diff --git a/src/read.rs b/src/read.rs index 256d805b..20af4836 100644 --- a/src/read.rs +++ b/src/read.rs @@ -21,8 +21,6 @@ use std::io::{Cursor, Error, ErrorKind, Read}; type SubtermDeque = VecDeque<(usize, usize)>; -// pub(crate) type PrologStream = ParsingStream; - impl MachineState { pub(crate) fn devour_whitespace( &mut self, -- 2.54.0