aboutsummaryrefslogtreecommitdiff
path: root/chain/src/default.rs
diff options
context:
space:
mode:
authorJSDurand <mmemmew@gmail.com>2026-10-16 14:01:01 +0800
committerJSDurand <mmemmew@gmail.com>2026-10-16 14:02:10 +0800
commitfba9a90cfc6aca2a26cce72f55fb261789139781 (patch)
treeb4b121791ad639e745df689c0d5a8ed7a9e5dcc4 /chain/src/default.rs
parent3ae0cf9898485a2ec35df7d23cd274e7dea5796d (diff)
new startHEADmaster
Now I tested and discussed with claude, and had a working version of this project. The rest is to port the claude version to my own writings. So this serves as the starting point before that attempt. In the new attempt the design is better, and a number of bugs were found and supposedly fixed, so let us see how this goes at the end.
Diffstat (limited to 'chain/src/default.rs')
-rw-r--r--chain/src/default.rs27
1 files changed, 22 insertions, 5 deletions
diff --git a/chain/src/default.rs b/chain/src/default.rs
index 042f84e..db42ef8 100644
--- a/chain/src/default.rs
+++ b/chain/src/default.rs
@@ -224,6 +224,9 @@ pub struct DefaultChain {
accepting_sources: Vec<PaVi>,
}
+// TODO: Implement saving the chain on disk, so that we do not have to
+// load the grammar every time.
+
impl DefaultChain {
/// Return the current node.
#[inline]
@@ -311,6 +314,7 @@ impl DefaultChain {
let mut file = std::fs::File::options()
.write(true)
.create(true)
+ .truncate(true)
.open(&filename)?;
use std::io::Write;
@@ -320,21 +324,25 @@ impl DefaultChain {
}
impl LabelGraph<Edge> for DefaultChain {
- type Iter<'a> = <DLGraph<Edge> as LabelGraph<Edge>>::Iter<'a>
+ type Iter<'a>
+ = <DLGraph<Edge> as LabelGraph<Edge>>::Iter<'a>
where
Self: 'a;
- type TupleIter<'a> = <DLGraph<Edge> as LabelGraph<Edge>>::TupleIter<'a>
+ type TupleIter<'a>
+ = <DLGraph<Edge> as LabelGraph<Edge>>::TupleIter<'a>
where
Self: 'a,
Edge: 'a;
- type LabelIter<'a> = <DLGraph<Edge> as LabelGraph<Edge>>::LabelIter<'a>
+ type LabelIter<'a>
+ = <DLGraph<Edge> as LabelGraph<Edge>>::LabelIter<'a>
where
Self: 'a,
Edge: 'a;
- type EdgeLabelIter<'a> = <DLGraph<Edge> as LabelGraph<Edge>>::EdgeLabelIter<'a>
+ type EdgeLabelIter<'a>
+ = <DLGraph<Edge> as LabelGraph<Edge>>::EdgeLabelIter<'a>
where
Self: 'a,
Edge: 'a;
@@ -554,7 +562,7 @@ impl Chain for DefaultChain {
/// to save some allocations.
fn generate_edges(
input: GeneratorInput<'_>,
- mut child_iter: impl Iterator<Item = usize> + ExactSizeIterator + Clone,
+ mut child_iter: impl ExactSizeIterator<Item = usize> + Clone,
atom_child_iter: impl Iterator<Item = usize> + Clone,
mut output: impl AsMut<Vec<(Roi, usize)>>,
) -> Result<bool, Error> {
@@ -693,6 +701,15 @@ impl Chain for DefaultChain {
let new_pavi = if !no_item {
// prepare forest fragment
+ // if ter == 0 {
+ // println!("{ter}, {t}, {atom_moved}, {atom_label}");
+ // println!(
+ // "hey: {:?}",
+ // self.atom.labels_of(0).unwrap().collect::<Vec<_>>()
+ // );
+ // panic!("test");
+ // }
+
let fragment =
generate_fragment([atom_moved.into(), Ter(ter).into()], pos)?;