From fbaa420ed550e9c3e7cdc09d4a8ec22bfbd782a6 Mon Sep 17 00:00:00 2001 From: JSDurand Date: Mon, 27 Feb 2023 12:36:41 +0800 Subject: before a major refactor I decide to adopt a new approach of recording and updating item derivation forests. Since this affects a lot of things, I decide to commit before the refactor, so that I can create a branch for that refactor. --- chain/src/atom/mod.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'chain/src/atom/mod.rs') diff --git a/chain/src/atom/mod.rs b/chain/src/atom/mod.rs index 398edd2..c9dadb2 100644 --- a/chain/src/atom/mod.rs +++ b/chain/src/atom/mod.rs @@ -17,6 +17,16 @@ pub trait Atom: Nfa> + Deref { /// left-linear null closure of `nt` with respect to `t`. fn atom(&self, nt: usize, t: usize) -> Result, GrammarError>; + /// A type that iterates through the rule positions. + type Iter<'a>: Iterator + 'a + where + Self: 'a; + + /// Return an iterator of rule positions responsible for an edge + /// from the virtual node corresponding to the non-terminal `nt` + /// and terminal `t` to `target`. + fn trace(&self, nt: usize, t: usize, target: usize) -> Option<::Iter<'_>>; + /// Return the index of the empty state. fn empty(&self) -> usize; @@ -33,6 +43,9 @@ mod tests { use super::*; use grammar::test_grammar_helper::*; + #[cfg(feature = "test-print-viz")] + use graph::Graph; + #[test] fn atom() -> Result<(), Box> { let grammar = new_notes_grammar()?; @@ -41,6 +54,21 @@ mod tests { println!("atom = {atom}"); + #[cfg(feature = "test-print-viz")] + { + println!("virtual frag for 1, 3: "); + + for (index, frag) in atom + .generate_virtual_frags(1, 3, None) + .iter() + .flatten() + .enumerate() + { + crate::item::default::print_labels(&atom, *frag)?; + frag.print_viz(&format!("frag {index}.gv"))?; + } + } + Ok(()) } } -- cgit v1.2.3-18-g5258