diff options
Diffstat (limited to 'chain/src/lib.rs')
-rw-r--r-- | chain/src/lib.rs | 38 |
1 files changed, 32 insertions, 6 deletions
diff --git a/chain/src/lib.rs b/chain/src/lib.rs index a7740c2..d7fc519 100644 --- a/chain/src/lib.rs +++ b/chain/src/lib.rs @@ -16,7 +16,7 @@ use graph::{error::Error as GError, LabelExtGraph}; use item::default::Error as ForestError; -use item::PaSe; +use item::PaVi; /// An edge in the Chain-Rule machine. #[derive(Debug, Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash)] @@ -24,18 +24,25 @@ pub struct Edge { /// The position in the atomic languages. label: usize, /// The source of the associated forest edge. - forest_source: PaSe, + forest_source: PaVi, + /// The bottom source on which we shall perform reduction. + /// + /// If this equals `forest_source`, no extra reduction needs to be + /// done. + true_source: PaVi, /// Whether or not this edge is "accepting". accepting: bool, } impl Edge { /// Construct a new edge. - pub fn new(label: usize, forest_source: PaSe, accepting: bool) -> Self { + pub fn new(label: usize, forest_source: PaVi, accepting: bool) -> Self { + let true_source = forest_source; Self { label, forest_source, accepting, + true_source, } } @@ -50,9 +57,21 @@ impl Edge { } /// Return the associated forest edge of the edge. - pub fn forest_source(&self) -> PaSe { + pub fn forest_source(&self) -> PaVi { self.forest_source } + + /// Return the associated bottom edge of the edge from which + /// onwards we shall perform the reduction. + pub fn set_true_source(&mut self, true_source: PaVi) { + self.true_source = true_source; + } + + /// Return the associated bottom edge of the edge from which + /// onwards we shall perform the reduction. + pub fn true_source(&self) -> PaVi { + self.true_source + } } impl core::fmt::Display for Edge { @@ -137,7 +156,7 @@ pub enum TwoLayers { /// the source of the associated forest edge of the second layer, /// and the third is a list of edges, which are the common first /// layers. - Two(usize, PaSe, bool, Vec<(Roi, usize)>), + Two(usize, PaVi, bool, Vec<(Roi, usize)>), } /// The type of a collapsed iterator. @@ -239,12 +258,15 @@ pub trait Chain: LabelExtGraph<Edge> { /// An iterator that iterates all layers that need to be merged. type DerIter: Iterator<Item = TwoLayers>; + // FIXME: Add a parameter to control whether to manipulate the + // forests or not. + /// Take the derivative by a terminal `t` at position `pos`. fn derive(&mut self, t: usize, pos: usize) -> Result<Self::DerIter, Self::Error>; /// Take the union of all derivatives. fn union(&mut self, der_iter: Self::DerIter) -> Result<Vec<(Roi, usize)>, Self::Error> { - // REVIEW: Find a way to avoid allocations. + // REVIEW: Think about the possibilities to avoid allocations. Collapsed::<_, Self>::collapse(der_iter, self) .collect::<Result<Vec<(Roi, usize)>, Self::Error>>() .map(|mut v| { @@ -276,6 +298,10 @@ pub trait Chain: LabelExtGraph<Edge> { Ok(()) } + + /// Signal to the parser that the end of the input is reached, so + /// that the parser knows to generate suitable forests. + fn end_of_input(&mut self) -> Result<(), Self::Error>; } pub mod default; |