summaryrefslogtreecommitdiff
path: root/chain
diff options
context:
space:
mode:
authorJSDurand <mmemmew@gmail.com>2023-02-28 15:15:43 +0800
committerJSDurand <mmemmew@gmail.com>2023-02-28 15:15:43 +0800
commitf7be4c8eb8de9f525584b7fa4e53978ad233d5e4 (patch)
tree155b88ac7a0847f028f41c1c25bc654fcb22cde8 /chain
parent1cbebd2ec6b2622c3eb3201a4545388d16364aa3 (diff)
default: add a plan
* chain/src/default.rs: Add a plan to fix things.
Diffstat (limited to 'chain')
-rw-r--r--chain/src/default.rs25
1 files changed, 21 insertions, 4 deletions
diff --git a/chain/src/default.rs b/chain/src/default.rs
index 08e29ce..cd0a898 100644
--- a/chain/src/default.rs
+++ b/chain/src/default.rs
@@ -17,7 +17,10 @@ use graph::{
labelled::DLGBuilder, Builder, DLGraph, Graph, LabelExtGraph, LabelGraph, ParentsGraph,
};
-use std::collections::{HashMap as Map, HashSet, TryReserveError};
+use std::{
+ borrow::Borrow,
+ collections::{HashMap as Map, HashSet, TryReserveError},
+};
/// The errors related to taking derivatives by chain rule.
#[non_exhaustive]
@@ -194,6 +197,16 @@ impl Iterator for DerIter {
}
}
+// TODO: Add a hashmap mapping tuples of forest positions (top,
+// bottom) to vectors of tuples of unsigned integers. Each tuple
+// represents a non-terminal and a rule. The tuple means that we need
+// to close the expansion of the non-terminal by the rule position, if
+// we want to move from bottom to top.
+//
+// After we move up one layer, we are now in a new forest position, so
+// we just query again with the new bottom and top. This means we do
+// not need to clear the map.
+
/// A default implementation for the [`Chain`] trait.
#[derive(Debug, Clone, Default)]
pub struct DefaultChain {
@@ -675,7 +688,7 @@ impl Chain for DefaultChain {
if pos == 4 {
dbg!(atom_moved, label);
self.forest
- .print_viz(&format!("pos4nb - {atom_moved}-{:?}.gv", label))
+ .print_viz(&format!("pos4nb - {atom_moved}-{label:?}.gv"))
.unwrap();
}
@@ -688,7 +701,7 @@ impl Chain for DefaultChain {
if pos == 4 {
self.forest
- .print_viz(&format!("pos4na - {atom_moved}-{:?}.gv", label))
+ .print_viz(&format!("pos4na - {atom_moved}-{label:?}.gv"))
.unwrap();
}
@@ -720,7 +733,7 @@ impl Chain for DefaultChain {
let mut new_edges = Vec::new();
let virtual_accepting = generate_edges(
- self,
+ self.borrow(),
child_iter.clone(),
atom_child_iter.clone(),
first_segment_pavi,
@@ -734,6 +747,7 @@ impl Chain for DefaultChain {
if accepting {
accepting_pavi.insert(virtual_pavi);
+ // FIXME: set true_source here
der_iter.singles.extend(new_edges.clone());
}
@@ -768,6 +782,8 @@ impl Chain for DefaultChain {
if self.atom.is_empty_node(atom_child).unwrap() {
// REVIEW: flat flat map,
// hmm...
+
+ // FIXME: Set true_source as well.
der_iter.singles.extend(child_iter.clone().flat_map(
|child| {
self.graph.labels_of(child).unwrap().flat_map(
@@ -791,6 +807,7 @@ impl Chain for DefaultChain {
}
}
+ self.accepting_sources.clear();
self.accepting_sources.extend(accepting_pavi);
Ok(der_iter)