From f7f97271467a1f9be1b6a35f9026d134f3caf63e Mon Sep 17 00:00:00 2001 From: RunasSudo Date: Sun, 20 Nov 2022 18:57:30 +1100 Subject: [PATCH] Allow escaped quotation marks in BLT parser --- src/parser/blt.rs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/parser/blt.rs b/src/parser/blt.rs index e01018f..f438879 100644 --- a/src/parser/blt.rs +++ b/src/parser/blt.rs @@ -255,9 +255,27 @@ impl> BLTParser { if self.lookahead() == '"' { self.accept(); // Opening quotation mark let mut result = String::new(); + + loop { + // Read string contents + if self.lookahead() == '"' { + break; + } else if self.lookahead() == '\\' { + // Escape sequence + self.accept(); + if self.lookahead() == '"' || self.lookahead() == '\\' { + result.push(self.accept()); + } else { + return Err(ParseError::Unexpected(self.line_no, self.col_no, self.lookahead())); + } + } else { + result.push(self.accept()); + } + } + while self.lookahead() != '"' { // TODO: BufRead::read_until ? - result.push(self.accept()); + } self.accept(); // Closing quotation mark if !self.eof() {