From 6ce44bb3bdb79e8e727ee6fc7f5c6cd7fa0bb51e Mon Sep 17 00:00:00 2001 From: JSDurand Date: Fri, 2 Jun 2023 22:43:33 +0800 Subject: review of previous bug fix Generally speaking the algorithm now works correctly and produces the right shape of forest for the test ambiguous grammar as well. It does not correctly perform the "reductions". It seems that I deliberately disabled this part of the functionalities in a previous debugging tour. So I have to enable it again and see if it works. --- chain/src/item/genins.rs | 28 ++++++++++++++++++++-------- grammar/src/lib.rs | 6 ++---- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/chain/src/item/genins.rs b/chain/src/item/genins.rs index 97d7ba9..a2bb22c 100644 --- a/chain/src/item/genins.rs +++ b/chain/src/item/genins.rs @@ -142,8 +142,6 @@ pub fn virtual_generate_fragment( Ok(result) } -// TODO: Refactor `insert_item`. - impl DefaultForest> { /// Insert an item derivation forest into a recording forest. /// @@ -252,8 +250,24 @@ impl DefaultForest> { atom.borrow(), )?; - self.print_viz(&format!("pos {pos} {tnt_string} {num} stage 1.gv")) - .unwrap(); + /// A cute little macro to produce compact representations + /// of Parents, Virtual nodes, or empty. + macro_rules! pavi_to_short_str { + ($pavi:ident) => { + match $pavi { + PaVi::Parent(node, edge) => format!("{node} {edge}"), + PaVi::Virtual(nt, t, node) => format!("{nt} {t} {node}"), + PaVi::Empty => "ε".to_string(), + } + }; + } + + self.print_viz(&format!( + "pos {pos} {tnt_string} {num} stage 1 {}, {}.gv", + pavi_to_short_str!(true_source), + pavi_to_short_str!(pavi) + )) + .unwrap(); // Ensure the last node in the PaVi is a terminal or a // non-terminal node, as an extra safety guard during @@ -296,10 +310,6 @@ impl DefaultForest> { } } - // TODO: Print each and every step. - - // TODO: Refactor this. - let is_empty_segment = pavi.is_empty(); let mut parents: Vec = { @@ -602,6 +612,8 @@ impl DefaultForest> { Ok(result) } + // REVIEW: Is this function really correct? + /// Perform extra reductions. /// /// To be precise, this function first splones the bottom node, diff --git a/grammar/src/lib.rs b/grammar/src/lib.rs index 135f668..11cb161 100644 --- a/grammar/src/lib.rs +++ b/grammar/src/lib.rs @@ -8,8 +8,6 @@ // words, the current focus is not on the optimisations, whereas // scanners are for optimisations only, so to speak. -// REVIEW: Separate contents into modules. - use nfa::{ default::{ nfa::DefaultNFA, @@ -37,8 +35,8 @@ pub const START_NONTERMINAL: usize = 0; /// future it may hold more information of scanners. #[derive(Debug, Clone, Eq, PartialEq)] pub struct Terminal { - // If we want to use scanners, per chance add them as a new field - // here. + // NOTE: If we want to use scanners, per chance add them as a new + // field here. name: String, } -- cgit v1.2.3-18-g5258