From e662dfa3a074a7603cbb9de473bf8bb45b4bb960 Mon Sep 17 00:00:00 2001 From: Jonas Maier Date: Mon, 1 Jun 2026 22:40:04 +0200 Subject: some more regex tests --- src/parse/regex/mod.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'src/parse/regex/mod.rs') diff --git a/src/parse/regex/mod.rs b/src/parse/regex/mod.rs index 98056cb..51527ae 100644 --- a/src/parse/regex/mod.rs +++ b/src/parse/regex/mod.rs @@ -107,7 +107,7 @@ fn parse_rep(s: &mut super::Cursor<'_>) -> Result { // TODO: non-greedy } -const SYMBOLS: &[u8] = b"{}[]()*+-?|. "; +const SYMBOLS: &[u8] = b"{}[]()*+-?|.\\ "; fn is_symbol(x: u8) -> bool { SYMBOLS.contains(&x) } @@ -183,6 +183,22 @@ fn parse_atom(s: &mut super::Cursor<'_>) -> Result { s.highlight_from(begin, OtherHighlights::RegexSymbol); Ok(Pattern::Range(0, 127)) } + b'\\' => { + s.adv(); + if s.has() { + let escaped = s.adv(); + s.highlight_from(begin, OtherHighlights::RegexSymbol); + + if is_symbol(escaped) { + Ok(Pattern::Byte(escaped)) + } else { + // TODO interpret \w and others + Err(ParseError::Unknown(escaped)) + } + } else { + Err(ParseError::Eof) + } + } x if is_symbol(x) => Ok(Pattern::Nothing), ch => { s.adv(); -- cgit v1.2.3