diff options
-rw-r--r-- | Cargo.toml | 2 | ||||
-rw-r--r-- | chain/src/archive.txt | 103 | ||||
-rw-r--r-- | chain/src/item/default/mod.rs | 2 | ||||
-rw-r--r-- | src/lib.rs | 3 |
4 files changed, 108 insertions, 2 deletions
@@ -1,6 +1,6 @@ [package] name = "rep" -version = "0.1.0" +version = "0.1.1" edition = "2021" authors = ["JSDurand <durand@jsdurand.xyz>"] description = "Rust, Emacs, and Parsers" diff --git a/chain/src/archive.txt b/chain/src/archive.txt index 79fe6d8..c93b4fe 100644 --- a/chain/src/archive.txt +++ b/chain/src/archive.txt @@ -638,3 +638,106 @@ // } // Ok(()) + +// let parents: Vec<_> = { +// if old_label.clone_index().is_some() { +// let mut parents = self.parents_of(node)?; +// assert_eq!(parents.len(), 1); +// node = parents.next().unwrap().node(); +// } + +// let parents: Vec<_> = self.parents_of(node)?.collect(); + +// let mut result: Vec<(Parent, usize)> = Vec::with_capacity( +// parents +// .iter() +// .map(|parent| { +// self.parents_of(parent.node()) +// .map(|iter| iter.len()) +// .unwrap_or(0) +// }) +// .sum(), +// ); + +// for parent in parents { +// let mut parent_label = self +// .vertex_label(parent.node())? +// .ok_or_else(|| Error::NodeNoLabel(parent.node()))? +// .label(); + +// assert!(get_rule_label(parent_label).is_some()); + +// if self.degree(parent.node())? != 1 { +// dbg!(parent); +// self.print_viz("dbg forest.gv").unwrap(); + +// panic!("assumption fails"); +// } + +// parent_label.set_end_option(end); + +// let parent_label = ForestLabel::from(parent_label); + +// let mut builder = PLGBuilderMut::from_graph_mut(&mut self.graph); + +// let new_parent = builder.add_vertex(parent_label); + +// if let Some(packed) = new_packed { +// builder.add_edge(new_parent, packed, new_label)?; +// } else { +// builder.add_edge(new_parent, new_node, new_label)?; +// } + +// result.extend( +// self.parents_of(parent.node())? +// .map(|parent_parent| (parent_parent, new_parent)), +// ); +// } + +// result +// }; + +// for (parent, new_child) in parents { +// if !completingp { +// if self.has_same_children_until( +// parent.node(), +// parent.node(), +// parent.edge(), +// new_child, +// )? { +// continue; +// } + +// // we don't add a child to parent.edge() here. +// let cloned = self.clone_node(parent.node(), parent.edge(), false)?; + +// let mut builder = PLGBuilderMut::from_graph_mut(&mut self.graph); + +// builder.add_edge(cloned, new_child, new_label)?; +// } else { +// if self.has_same_children_except( +// parent.node(), +// parent.node(), +// parent.edge(), +// new_child, +// )? { +// continue; +// } + +// // we don't add a child to parent.edge() here. +// let cloned = self.clone_node(parent.node(), parent.edge(), false)?; + +// let mut builder = PLGBuilderMut::from_graph_mut(&mut self.graph); + +// builder.add_edge(cloned, new_child, new_label)?; + +// let children_to_add: Vec<_> = builder +// .children_of(parent.node())? +// .skip(parent.edge() + 1) +// .collect(); + +// for child in children_to_add { +// builder.add_edge(cloned, child, new_label)?; +// } +// } +// } diff --git a/chain/src/item/default/mod.rs b/chain/src/item/default/mod.rs index e0e2296..0dc613b 100644 --- a/chain/src/item/default/mod.rs +++ b/chain/src/item/default/mod.rs @@ -1596,7 +1596,7 @@ mod item_test { let atom = DefaultAtom::from_grammar(grammar)?; - // atom.print_nullables(); + atom.print_nullables(); let mut forest: DefaultForest<ForestLabel<GrammarLabel>> = DefaultForest::new_leaf_raw( ForestLabel::new(GrammarLabel::new(TNT::Non(0), 0), ForestLabelType::Plain), @@ -480,6 +480,9 @@ extern "C" fn parser_parse( match forest { Ok(forest) => { + // use graph::Graph; + // forest.print_viz("test forest.gv").unwrap(); + Box::leak(parser_box); let mut bytes = bytes::forest_to_bytes(&forest); |