diff options
author | SoniEx2 <endermoneymod@gmail.com> | 2022-10-30 00:49:56 -0300 |
---|---|---|
committer | SoniEx2 <endermoneymod@gmail.com> | 2022-10-30 00:49:56 -0300 |
commit | a66111d9f9c99f91d9256209b5e9a65e42cde7f5 (patch) | |
tree | aba85fd481ade96ba1be135c459af9d20eb409d7 /src/vm/mod.rs | |
parent | c1210b511af8ffada948550180360859b64009d2 (diff) |
Implement parser
Diffstat (limited to 'src/vm/mod.rs')
-rw-r--r-- | src/vm/mod.rs | 29 |
1 files changed, 12 insertions, 17 deletions
diff --git a/src/vm/mod.rs b/src/vm/mod.rs index 8f20aae..06f12e5 100644 --- a/src/vm/mod.rs +++ b/src/vm/mod.rs @@ -14,7 +14,6 @@ use std::marker::PhantomData; use indexmap::IndexMap; use regex::Regex; use serde::Serialize; -use these::These; use crate::Predicate; //use crate::errors::MatchError; @@ -82,9 +81,10 @@ impl<O: Serialize> std::fmt::Debug for PatternConstants<O> { pub(crate) enum PatternElement { /// A value is the core capturing element. Value { - /// The index of the (string) name to apply to this value and/or the - /// expected value of this entry. - name_and_value: These<usize, Value>, + /// The index of the (string) name to apply to this value. + name: Option<usize>, + /// The expected value of this entry. + value: Option<Value>, }, /// A tag is the core iterative element. It is always followed by a value. Tag { @@ -173,7 +173,7 @@ pub(crate) enum PatternToken { String(usize, bool), Regex(usize, bool), Parameter(usize, bool), - KeySubtree(usize, bool), + KeySubtree(usize), ValueSubtree(usize, bool), /// Represents a predicate which must be applied. @@ -424,19 +424,16 @@ impl<'pat> Frame<'pat> { &self, ) -> Option<(Type, bool)> { match self.op() { - | PatternElement::Value { name_and_value, .. } - if name_and_value.is_there() - => { - match name_and_value.there() { - | Some(Value::String { skippable, .. }) - | Some(Value::Regex { skippable, .. }) + PatternElement::Value { value: Some(value), .. } => { + match value { + | Value::String { skippable, .. } + | Value::Regex { skippable, .. } => { Some((Type::Str, !skippable)) }, - Some(Value::Type { ty, skippable }) => { + Value::Type { ty, skippable } => { Some((ty, !skippable)) }, - None => todo!(), } }, PatternElement::Tag { .. } => panic!("attempt to get type of tag"), @@ -451,10 +448,8 @@ impl<'pat> Frame<'pat> { ) -> Option<&'pat str> { let strings = &pat.strings; match self.op() { - | PatternElement::Value { name_and_value, .. } - if name_and_value.is_here() - => { - Some(&*strings[name_and_value.here().unwrap()]) + PatternElement::Value { name: Some(name), .. } => { + Some(&*strings[name]) }, PatternElement::Tag { .. } => panic!("attempt to get name of tag"), _ => None, |