summaryrefslogtreecommitdiff
path: root/chain/src/atom
diff options
context:
space:
mode:
Diffstat (limited to 'chain/src/atom')
-rw-r--r--chain/src/atom/default.rs41
1 files changed, 4 insertions, 37 deletions
diff --git a/chain/src/atom/default.rs b/chain/src/atom/default.rs
index a55087a..6883907 100644
--- a/chain/src/atom/default.rs
+++ b/chain/src/atom/default.rs
@@ -10,6 +10,8 @@ use nfa::{
LabelType, NfaLabel,
};
+use graph_macro::Graph;
+
use core::fmt::Display;
use std::{
collections::{hash_set::Iter, BTreeMap as Map, HashMap, HashSet},
@@ -68,9 +70,10 @@ type VirtualFrag = DefaultForest<ForestLabel<GrammarLabel>>;
type VirtualFragMap = Map<VirtualNode, Map<usize, VirtualFrag>>;
/// The type of atomic languages.
-#[derive(Debug, Clone, Default)]
+#[derive(Debug, Clone, Default, Graph)]
pub struct DefaultAtom {
grammar: Grammar,
+ #[graph]
nfa: DefaultNFA<LabelType<TNT>>,
accepting_vec: Vec<bool>,
// NOTE: This is mostly for printing and debugging
@@ -189,42 +192,6 @@ impl Display for DefaultAtom {
// Some boiler-plate delegation implementations for Graph and
// LabelGraph, in order to implement Nfa.
-impl Graph for DefaultAtom {
- type Iter<'b> = <DefaultNFA<LabelType<TNT>> as Graph>::Iter<'b>
- where
- Self: 'b;
-
- fn is_empty(&self) -> bool {
- self.nfa.is_empty()
- }
-
- fn nodes_len(&self) -> usize {
- self.nfa.nodes_len()
- }
-
- fn children_of(&self, node_id: usize) -> Result<Self::Iter<'_>, GraphError> {
- self.nfa.children_of(node_id)
- }
-
- fn degree(&self, node_id: usize) -> Result<usize, GraphError> {
- self.nfa.degree(node_id)
- }
-
- fn is_empty_node(&self, node_id: usize) -> Result<bool, GraphError> {
- self.nfa.is_empty_node(node_id)
- }
-
- fn has_edge(&self, source: usize, target: usize) -> Result<bool, GraphError> {
- self.nfa.has_edge(source, target)
- }
-
- fn replace_by_builder(&mut self, _builder: impl graph::Builder<Result = Self>) {
- // NOTE: We cannot replace by a builder whose result is an
- // atom, not the underlying graph type.
- unimplemented!()
- }
-}
-
impl LabelGraph<LabelType<TNT>> for DefaultAtom {
type Iter<'b> = <DefaultNFA<LabelType<TNT>> as LabelGraph<LabelType<TNT>>>::Iter<'b>
where