From fba9a90cfc6aca2a26cce72f55fb261789139781 Mon Sep 17 00:00:00 2001 From: JSDurand Date: Fri, 16 Oct 2026 14:01:01 +0800 Subject: new start 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. --- chain/src/default.rs | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) (limited to 'chain/src/default.rs') 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, } +// 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 for DefaultChain { - type Iter<'a> = as LabelGraph>::Iter<'a> + type Iter<'a> + = as LabelGraph>::Iter<'a> where Self: 'a; - type TupleIter<'a> = as LabelGraph>::TupleIter<'a> + type TupleIter<'a> + = as LabelGraph>::TupleIter<'a> where Self: 'a, Edge: 'a; - type LabelIter<'a> = as LabelGraph>::LabelIter<'a> + type LabelIter<'a> + = as LabelGraph>::LabelIter<'a> where Self: 'a, Edge: 'a; - type EdgeLabelIter<'a> = as LabelGraph>::EdgeLabelIter<'a> + type EdgeLabelIter<'a> + = as LabelGraph>::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 + ExactSizeIterator + Clone, + mut child_iter: impl ExactSizeIterator + Clone, atom_child_iter: impl Iterator + Clone, mut output: impl AsMut>, ) -> Result { @@ -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::>() + // ); + // panic!("test"); + // } + let fragment = generate_fragment([atom_moved.into(), Ter(ter).into()], pos)?; -- cgit v1.2.3-18-g5258