From 4db0b385f3e382cb00b78e6381b990389c9a5121 Mon Sep 17 00:00:00 2001 From: Mark Date: Fri, 7 Jul 2023 13:04:27 -0600 Subject: [PATCH] treat unexpected EOF as incomplete reduction in bracketed_comment --- src/parser/char_reader.rs | 2 +- src/parser/lexer.rs | 27 +++++++++++++++++++++------ 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/src/parser/char_reader.rs b/src/parser/char_reader.rs index 9d6babf4..4b08e008 100644 --- a/src/parser/char_reader.rs +++ b/src/parser/char_reader.rs @@ -117,7 +117,7 @@ impl CharReader { // 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(); diff --git a/src/parser/lexer.rs b/src/parser/lexer.rs index 7f5d73ed..47ff0a22 100644 --- a/src/parser/lexer.rs +++ b/src/parser/lexer.rs @@ -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(_) => { } } -- 2.54.0