summaryrefslogtreecommitdiff
path: root/chain/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'chain/src/lib.rs')
-rw-r--r--chain/src/lib.rs29
1 files changed, 27 insertions, 2 deletions
diff --git a/chain/src/lib.rs b/chain/src/lib.rs
index 9de1df7..bf3a8b4 100644
--- a/chain/src/lib.rs
+++ b/chain/src/lib.rs
@@ -240,6 +240,10 @@ pub trait Chain: LabelExtGraph<Edge> {
/// language.
fn unit(atom: Self::Atom) -> Result<Self, Self::Error>;
+ /// Produce the underlying atom, so that we can produce an initial
+ /// empty chain from the same atom again.
+ fn atom(&self) -> &Self::Atom;
+
/// Return true if and only if the language contains the empty
/// string.
fn epsilon(&self) -> Result<bool, Self::Error>;
@@ -283,7 +287,8 @@ pub trait Chain: LabelExtGraph<Edge> {
/// The argument `t` is the terminal we computet the derivative
/// with.
///
- /// The argument `pos` is the position within the input.
+ /// The argument `pos` is the zero-based position within the
+ /// input.
///
/// The argument `no_item` determines whether we want the item
/// derivation forest as well.
@@ -307,9 +312,29 @@ pub trait Chain: LabelExtGraph<Edge> {
Ok(())
}
+ // FIXME: I shall probably not use the trait of forests for this
+ // purpose, but I have not figured out yet wha the correct trait
+ // should be.
+ /// The type of output item that will be produced by this machine.
+ type Item: item::Forest<grammar::GrammarLabel>;
+
/// 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>;
+ ///
+ /// This is not needed when recognizing instead of parsing.
+ ///
+ /// We also pass in the current position `pos` so that we have a
+ /// little flexibility in the position of the end of input. In
+ /// addition, this makes it easier to produce the suitable
+ /// forests.
+ ///
+ /// As a reminder, `pos` should be the position of the last
+ /// terminal, so if there are three terminals in total, the `pos`
+ /// should be `2` , instead of `3`.
+ ///
+ /// Similarly, we pass in the terminal at the position `pos` to
+ /// aid the production of the forest.
+ fn end_of_input(&mut self, pos: usize, ter: usize) -> Result<Self::Item, Self::Error>;
}
pub mod default;