diff options
author | SoniEx2 <endermoneymod@gmail.com> | 2021-01-12 22:15:26 -0300 |
---|---|---|
committer | SoniEx2 <endermoneymod@gmail.com> | 2021-01-12 22:15:26 -0300 |
commit | bcdba3431c72cd0804d9a95972a907b828fb5fad (patch) | |
tree | 210f263e64f5e90726fcf92ec60eb088711787d4 /src/pattern.rs |
Prepare VM design
Diffstat (limited to 'src/pattern.rs')
-rw-r--r-- | src/pattern.rs | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/pattern.rs b/src/pattern.rs new file mode 100644 index 0000000..8c57f00 --- /dev/null +++ b/src/pattern.rs @@ -0,0 +1,22 @@ +use crate::PatternTypes; +use crate::errors::PatternError; +use crate::parser::parse; +use crate::vm::Matcher; +use crate::vm::PatternConstants; +use crate::vm::MAX_CALLS; + +pub struct Pattern<T: PatternTypes> { + constants: PatternConstants<T>, +} + +impl<T: PatternTypes> Pattern<T> { + pub fn compile(s: &str) -> Result<Self, PatternError> { + Ok(Self { + constants: parse(s)? + }) + } + + pub fn attempt_match<'a, 'b>(&'a self, value: &'b T::Value) -> Matcher<'a, 'b, T> { + Matcher::new(value, &self.constants, self.constants.protos.len() - 1, MAX_CALLS).ok().expect("datafu internal error: MAX_CALLS must not be 0") + } +} |