aboutsummaryrefslogtreecommitdiffstats
path: root/src/parse/regex.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/parse/regex.rs')
-rw-r--r--src/parse/regex.rs16
1 files changed, 14 insertions, 2 deletions
diff --git a/src/parse/regex.rs b/src/parse/regex.rs
index 22c3b9c..4134c88 100644
--- a/src/parse/regex.rs
+++ b/src/parse/regex.rs
@@ -1,5 +1,5 @@
use super::{Cursor, OtherHighlights, Parse, ParseError, Result};
-use crate::regex::{Class, GreedyBehavior, LookDirection, LookPolarity, Pattern};
+use crate::{parse::VarName, regex::{Class, GreedyBehavior, LookDirection, LookPolarity, Pattern}};
const SYMBOLS: &[u8] = b"{}[]()*+-?|.\\ ";
fn is_symbol(x: u8) -> bool {
@@ -155,6 +155,7 @@ fn parse_atom(s: &mut super::Cursor<'_>) -> Result<Pattern> {
b'(' => {
s.adv();
+ let mut match_name = None;
let mut assertion = None;
if s.buf.starts_with(b"?=") {
s.advance(2);
@@ -168,6 +169,15 @@ fn parse_atom(s: &mut super::Cursor<'_>) -> Result<Pattern> {
} else if s.buf.starts_with(b"?<!") {
s.advance(3);
assertion = Some((LookDirection::Behind, LookPolarity::Negative));
+ } else if s.buf.starts_with(b"?<") && s.buf.len() > 2 && s.buf[2].is_ascii_alphabetic() {
+ s.advance(2);
+ match_name = Some(VarName::parse(s)?.name);
+ if !s.has() {
+ return Err(ParseError::Eof);
+ }
+ if s.adv() != b'>' {
+ return Err(ParseError::Expected('>'));
+ }
}
s.highlight_from(begin, OtherHighlights::RegexSymbol);
@@ -183,8 +193,10 @@ fn parse_atom(s: &mut super::Cursor<'_>) -> Result<Pattern> {
if let Some((dir, pol)) = assertion {
Ok(Pattern::Assertion(dir, pol, Box::new(inner)))
+ } else if let Some(match_name) = match_name {
+ Ok(Pattern::Submatch(match_name, Box::new(inner)))
} else {
- Ok(Pattern::Submatch(Box::new(inner)))
+ Ok(inner)
}
}
b'.' => {