diff options
author | JSDurand <mmemmew@gmail.com> | 2023-08-01 11:47:44 +0800 |
---|---|---|
committer | JSDurand <mmemmew@gmail.com> | 2023-08-01 11:47:44 +0800 |
commit | 81854107bcf0b4480cfb11e8af7fec6894240c0c (patch) | |
tree | db85df073d1f5201545aa463ef34307d763e7095 /chain/src/item/reduction.rs | |
parent | ca56b918b48cc08d8a43660a5e6f82c946fad8a0 (diff) |
Fix some bugs
Some bugs are fixed:
1. If a non-terminal expansion can be reduced immediately, previously
an extra node would be created that had no parents. Now this strange
behaviour is corrected.
2. When performing reductions, a leaf non-terminal node would
previously be regarded as completed. Now we will first try to
complete that node, and then determine if the completion is
successful, and finally determine the completedness according to the
result.
Of course some more tests are still pending, before I can confirm that
no more bugs lurk around.
Diffstat (limited to 'chain/src/item/reduction.rs')
-rw-r--r-- | chain/src/item/reduction.rs | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/chain/src/item/reduction.rs b/chain/src/item/reduction.rs index 3c76c1e..512862a 100644 --- a/chain/src/item/reduction.rs +++ b/chain/src/item/reduction.rs @@ -139,6 +139,10 @@ impl DefaultForest<ForestLabel<GrammarLabel>> { ) -> Result<usize, Error> { let mut result = node; + // if node == 15 && pos == 2 { + // let _ = self.print_viz("pos really before splone.gv"); + // } + // step 1: Determine if this needs reductions. if !accept_root && self.root() == Some(node) { @@ -346,10 +350,14 @@ impl DefaultForest<ForestLabel<GrammarLabel>> { panic!("a terminal node {top} has no ending position?"); } Some(TNT::Non(nt)) => { - correct_ends.insert(top, Correct); - self.close_pavi(atom.borrow(), PaVi::Virtual(nt, ter, top), pos)?; + // dbg!(top, nt, ter, pos, self.degree(top)?, degree); + + let correctness = self.degree(top)? > 0; + + correct_ends.insert(top, correctness.into()); + continue 'stack_loop; } None => { @@ -404,6 +412,11 @@ impl DefaultForest<ForestLabel<GrammarLabel>> { // NOTE: We must fix the order from top to bottom: this is the // reverse order of `order_of_correct_ends` . + // if node == 15 && pos == 2 { + // dbg!(&order_of_correct_ends); + // let _ = self.print_viz("pos before splone.gv"); + // } + for node in order_of_correct_ends.into_iter().rev() { let label = self.vertex_label(node)?.ok_or(Error::NodeNoLabel(node))?; let degree = self.degree(node)?; @@ -421,6 +434,10 @@ impl DefaultForest<ForestLabel<GrammarLabel>> { let last_index = degree - 1; + // if node == 15 && pos == 2 { + // let _ = self.print_viz("before splone.gv"); + // } + self.splone(node, Some(pos), last_index, false)?; } |