diff options
author | JSDurand <mmemmew@gmail.com> | 2023-07-08 12:30:21 +0800 |
---|---|---|
committer | JSDurand <mmemmew@gmail.com> | 2023-07-08 12:31:13 +0800 |
commit | 9a317e56f8a6126583f7d0c431bf878d9b1fe7b1 (patch) | |
tree | 7bb6004196b38446a5ab0cb3a0ab642d35f113e9 /chain/src/lib.rs | |
parent | 691f969eb104fa3d4c2a1667693fd0382eb9d6b5 (diff) |
Finished the Emacs binding.
Now the binding part is finished.
What remains is a bug encountered when planting a fragment to the
forest which intersects a packed node, which would lead to invalid
forests. This will also cause problem when planting a packed
fragment, but until now my testing grammars do not produce packed
fragments, so this problem is not encountered yet.
I am still figuring out efficient ways to solve this problem.
Diffstat (limited to 'chain/src/lib.rs')
-rw-r--r-- | chain/src/lib.rs | 29 |
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; |