summaryrefslogtreecommitdiff
path: root/chain/src/default.rs
diff options
context:
space:
mode:
authorJSDurand <mmemmew@gmail.com>2023-07-18 11:55:03 +0800
committerJSDurand <mmemmew@gmail.com>2023-07-18 11:58:00 +0800
commit5a5f7e5be9498af219a36401b1d2a13b553402e8 (patch)
tree87a0351dc00cda0555193421979a4a312185fe25 /chain/src/default.rs
parent9a5359bcc8d47de7222d07035ae99459d49e810e (diff)
Fix a bug of unnecessarily cloning nodes.
* chain/src/item/default/splone.rs: Previously when we split nodes, we always clone the parent if the labels differ. This turns out to be incorrect if the new label is open whereas the old label is closed. In that case, the old parent should not contain the new node as a child, as a closed node should not contain an open node. I am not yet entirely sure this fix is correct, so more test await us.
Diffstat (limited to 'chain/src/default.rs')
-rw-r--r--chain/src/default.rs11
1 files changed, 6 insertions, 5 deletions
diff --git a/chain/src/default.rs b/chain/src/default.rs
index 23baa5f..2f6311c 100644
--- a/chain/src/default.rs
+++ b/chain/src/default.rs
@@ -802,8 +802,6 @@ impl Chain for DefaultChain {
// The 1-th node is a dummy node that should be removed.
assert_ne!(root, 1);
- // let _ = self.forest.print_viz("help.gv");
-
self.forest.remove_node(1)?;
let root_degree = self.forest.degree(root)?;
@@ -1056,12 +1054,11 @@ mod test_chain {
fn test_assumption() -> Result<(), Box<dyn std::error::Error>> {
use grammar::Grammar;
- dbg!();
let grammar_str = std::fs::read_to_string(
"/Users/durand/Desktop/Centre/A propos de programmes/Rust/rep/grammar/abnf grammars/test.abnf",
)
.unwrap();
- dbg!();
+
let grammar: Grammar = grammar_str.parse()?;
let atom = DefaultAtom::from_grammar(grammar)?;
@@ -1071,9 +1068,13 @@ mod test_chain {
let input: &[usize] = &[3, 0, 2, 2, 2, 1, 1, 1, 0, 1];
+ let to_print = std::fs::metadata("output/").is_ok();
+
for (pos, t) in input.iter().copied().enumerate().take(2) {
chain.chain(t, pos, no_item)?;
- // chain.forest().print_viz(&format!("forest {pos}.gv"))?;
+ if to_print {
+ chain.forest().print_viz(&format!("forest {pos}.gv"))?;
+ }
dbg!(pos, t);
}