summaryrefslogtreecommitdiff
path: root/chain/src/item/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'chain/src/item/mod.rs')
-rw-r--r--chain/src/item/mod.rs25
1 files changed, 14 insertions, 11 deletions
diff --git a/chain/src/item/mod.rs b/chain/src/item/mod.rs
index 5efa710..54ca946 100644
--- a/chain/src/item/mod.rs
+++ b/chain/src/item/mod.rs
@@ -32,8 +32,9 @@ use core::borrow::Borrow;
/// Also this might be empty if it represents the root node.
#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Default)]
pub enum PaVi {
- /// An edge from a node, as the n-th child.
- Parent(usize, usize),
+ /// An edge from a node, as the n-th child, along with the
+ /// nth-child node number.
+ Parent(usize, usize, usize),
/// A virtual segment from a non-terminal by a terminal, rooted at
/// a node.
///
@@ -50,16 +51,12 @@ pub enum PaVi {
Empty,
}
-impl From<Parent> for PaVi {
- fn from(value: Parent) -> Self {
- Self::Parent(value.node(), value.edge())
- }
-}
-
-impl core::fmt::Display for PaVi {
+impl std::fmt::Display for PaVi {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
- Self::Parent(node, edge) => write!(f, "the {edge}-th edge from {node}"),
+ Self::Parent(node, edge, child) => {
+ write!(f, "the {edge}-th edge from {node} to {child}")
+ }
Self::Virtual(nt, t, node) => write!(
f,
"a virtual node for non-terminal {nt} and terminal {t} at node {node}"
@@ -72,13 +69,17 @@ impl core::fmt::Display for PaVi {
impl PaVi {
/// Get the Parent variant.
fn parent(self) -> Option<Parent> {
- if let Self::Parent(node, edge) = self {
+ if let Self::Parent(node, edge, _) = self {
Some(Parent::new(node, edge))
} else {
None
}
}
+ fn is_virtual(self) -> bool {
+ matches!(self, Self::Virtual(_, _, _))
+ }
+
/// Is this an empty segment?
fn is_empty(self) -> bool {
self == Self::Empty
@@ -290,3 +291,5 @@ pub mod default;
pub mod genins;
pub use genins::generate_fragment;
+
+pub mod reduction;