From a66111d9f9c99f91d9256209b5e9a65e42cde7f5 Mon Sep 17 00:00:00 2001 From: SoniEx2 Date: Sun, 30 Oct 2022 00:49:56 -0300 Subject: Implement parser --- src/vm/mod.rs | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) (limited to 'src/vm/mod.rs') 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 std::fmt::Debug for PatternConstants { 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, + /// The index of the (string) name to apply to this value. + name: Option, + /// The expected value of this entry. + value: Option, }, /// 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, -- cgit 1.4.1