From 8ddf73dc768a0b223539571126875a89a4e35f41 Mon Sep 17 00:00:00 2001 From: John Date: Mon, 25 Sep 2023 16:49:18 -0500 Subject: [PATCH] lexer: refactor string escape to separate rule (fixes '\\"') --- libconlang/src/lib.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/libconlang/src/lib.rs b/libconlang/src/lib.rs index 9aaee8b..147d1f4 100644 --- a/libconlang/src/lib.rs +++ b/libconlang/src/lib.rs @@ -138,7 +138,7 @@ pub mod lexer { Type::String, Rule::new(self.text()) .char('"') - .and_any(|rule| rule.str(r#"\""#).or(|rule| rule.not_char('"'))) + .and_any(|rule| rule.and(Rule::string_escape).or(|rule| rule.not_char('"'))) .char('"') .end()?, ) @@ -211,6 +211,9 @@ pub mod lexer { pub fn bin_digit(self) -> Self { self.char_between('0', '1') } + pub fn string_escape(self) -> Self { + self.char('\\').and(Rule::any) + } fn has(self, condition: impl Fn(&Self) -> bool, len: usize) -> Self { let len = next_utf8(self.text, len); self.and(|rule| match condition(&rule) && !rule.text.is_empty() {