diff options
Diffstat (limited to 'src')
| -rwxr-xr-x | src/main.rs | 3 | ||||
| -rw-r--r-- | src/nfa.rs | 5 | ||||
| -rw-r--r-- | src/regex.rs | 12 |
3 files changed, 18 insertions, 2 deletions
diff --git a/src/main.rs b/src/main.rs index 0fa03d5..14919f2 100755 --- a/src/main.rs +++ b/src/main.rs @@ -5,10 +5,11 @@ use regex::*; fn test(regex: &str, input: &str) -> bool { let regex = Regex::new(regex); + println!("{:#?}", regex); let nfa = NFA::from(regex); nfa.matches(input) } fn main() { - dbg!(test("regexisawesome", "regexisawesome")); + dbg!(test("aa*", "aa ")); } @@ -130,8 +130,13 @@ impl NFA { // TODO: chars.nth() Work at O(n) consider using bytes instead of losing UTF-8 support Trans::Symbol(ch) => match input.chars().nth(idx) { Some(nxt) if nxt == *ch => { + // choose idx += 1; + + //explore result |= self.matches_helper(self.states.get(id).unwrap(), input, idx); + + // unchoose idx -= 1; } None => {} diff --git a/src/regex.rs b/src/regex.rs index 6d05a54..6f1472e 100644 --- a/src/regex.rs +++ b/src/regex.rs @@ -64,6 +64,7 @@ impl Regex { chars: &mut std::iter::Peekable<std::str::Chars>, ) -> Regex { while let Some(&next) = chars.peek() { + dbg!(next); match next { '|' => { chars.next(); // Consume '|' @@ -87,6 +88,7 @@ impl Regex { )); } _ => { + // it must be a char let right = Self::parse_token(chars); if let Regex::None = right { // do nothing @@ -106,8 +108,16 @@ impl Regex { chars.next(); // Skip ')' token } + Some('$') => { + let token = Self::parse(&chars.into_iter().collect::<String>()); + chars.next(); // Skip '$' + token + } Some('.') => Regex::Dot, - Some(c) if c.is_ascii_alphanumeric() => Sym!(c), + Some(' ') => Sym!(' '), + Some(c) if c.is_ascii_alphanumeric() => { + Sym!(c) + } _ => Regex::None, } } |
