From 0fa0622a24dbdf0c2bd0fbf6bedf4cad5ed8d311 Mon Sep 17 00:00:00 2001 From: JSDurand Date: Tue, 18 Jul 2023 16:22:56 +0800 Subject: chain/src/atom/default.rs: Add function to print nullables * chain/src/atom/default.rs (print_nullables): This functions prints the nullables nodes of an atomic language. This is useful whe designing unit tests, as it enables us to know which rule positions are considered accepting by the underlying testing atomic language. --- chain/src/atom/default.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'chain/src') diff --git a/chain/src/atom/default.rs b/chain/src/atom/default.rs index 317090e..bd71c1c 100644 --- a/chain/src/atom/default.rs +++ b/chain/src/atom/default.rs @@ -115,6 +115,22 @@ impl DefaultAtom { )?) } + /// Print nullable nodes. + pub(crate) fn print_nullables(&self) { + print!("printing nullables for the atom: "); + + for nullable in self + .accepting_vec + .iter() + .enumerate() + .filter_map(|(index, pred)| (*pred).then(|| index)) + { + print!("{nullable}, "); + } + + println!(); + } + /// Print the underlying NFA. pub fn print_nfa>(&self, filename: S) -> Result<(), std::io::Error> { self.nfa.print_viz(filename.as_ref())?; -- cgit v1.2.3-18-g5258