From 015369ad7a9c4a90873066b5f43a3ac12b1c7ea4 Mon Sep 17 00:00:00 2001 From: sleshep <9625413+sleshep@users.noreply.github.com> Date: Thu, 7 Aug 2025 17:03:32 +0800 Subject: [PATCH] pattern: Support double quote escape --- src/proc-macros/pattern.rs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/proc-macros/pattern.rs b/src/proc-macros/pattern.rs index 4524668..ba34b46 100644 --- a/src/proc-macros/pattern.rs +++ b/src/proc-macros/pattern.rs @@ -493,12 +493,16 @@ fn parse_helper(pat: &mut &str, result: &mut Vec) -> Result<(), PatError> // Match raw bytes b'"' => loop { if let Some(chr) = iter.next().cloned() { - if chr != b'"' { - result.push(Atom::Byte(chr)); - } - else { + if chr == b'"' { + // Handle escaped quotes `""` + if iter.as_slice().first() == Some(&b'"') { + iter.next(); + result.push(Atom::Byte(b'"')); + continue; + } break; } + result.push(Atom::Byte(chr)); } else { return Err(PatError::UnclosedQuote); @@ -641,6 +645,12 @@ mod tests { Save(0), Byte(115), Byte(116), Byte(114), Byte(105), Byte(110), Byte(103) ])); + assert_eq!(parse("\"string\"\"quote\"\"string\""), Ok(vec![ + Save(0), Byte(115), Byte(116), Byte(114), Byte(105), Byte(110), Byte(103), + Byte(34), Byte(113), Byte(117), Byte(111), Byte(116), Byte(101), Byte(34), + Byte(115), Byte(116), Byte(114), Byte(105), Byte(110), Byte(103) + ])); + assert_eq!(parse("*{FF D8 42}"), Ok(vec![ Save(0), Push(PTR_SKIP), Ptr, Byte(0xFF), Byte(0xD8), Byte(0x42) ]));