diff options
| author | nsfisis <nsfisis@gmail.com> | 2025-07-19 15:46:22 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2025-07-19 18:03:57 +0900 |
| commit | d3b8c1a53d21936b2aa99bd331fea3548c06b44c (patch) | |
| tree | a5a3d56afdb82735acb1df8e9f043497586817bd /src/vm.rs | |
| parent | 145efc39d14c242266c574063ffcba329c62e8a3 (diff) | |
| download | regulus-d3b8c1a53d21936b2aa99bd331fea3548c06b44c.tar.gz regulus-d3b8c1a53d21936b2aa99bd331fea3548c06b44c.tar.zst regulus-d3b8c1a53d21936b2aa99bd331fea3548c06b44c.zip | |
implement vm-based engine
Diffstat (limited to 'src/vm.rs')
| -rw-r--r-- | src/vm.rs | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/vm.rs b/src/vm.rs new file mode 100644 index 0000000..e780e96 --- /dev/null +++ b/src/vm.rs @@ -0,0 +1,36 @@ +use crate::syntax::ast::Regex; + +pub mod compile; +pub mod instr; +pub mod vm; + +pub fn is_match(re: Regex, s: &str) -> bool { + let instrs = compile::compile(&re); + vm::run(&instrs, s.as_bytes()) +} + +#[cfg(test)] +mod tests { + use super::*; + + fn re(p: &str) -> Regex { + use crate::syntax::parse::parse; + parse(p).unwrap() + } + + #[test] + fn matches() { + assert!(is_match(re("a"), "a")); + assert!(is_match(re("a*"), "")); + assert!(is_match(re("a*"), "a")); + assert!(is_match(re("a|b*"), "a")); + assert!(is_match(re("a|b*"), "bb")); + assert!(is_match(re("(a|b)*"), "abababaa")); + assert!(is_match(re("a*b*"), "abb")); + } + + #[test] + fn does_not_match() { + assert!(!is_match(re("a"), "b")); + } +} |
