diff options
author | JSDurand <mmemmew@gmail.com> | 2023-06-02 15:00:48 +0800 |
---|---|---|
committer | JSDurand <mmemmew@gmail.com> | 2023-06-02 15:00:48 +0800 |
commit | 8486474f377faf2d800d79166a7abe6b975e3e50 (patch) | |
tree | f06baa22bafebf9393869664067e9cf308c92634 /grammar/src/lib.rs | |
parent | 1455da10f943e2aa1bdf26fb2697dafccc61e073 (diff) |
Fix a bug of duplication from planting after sploing
I should have staged and committed these changes separately, but I am
too lazy to deal with that.
The main changes in this commit are that I added the derive macro that
automates the delegation of the Graph trait. This saves a lot of
boiler-plate codes.
The second main change, perhaps the most important one, is that I
found and tried to fix a bug that caused duplication of nodes. The
bug arises from splitting or cloning a node multiple times, and
immediately planting the same fragment under the new "sploned" node.
That is, when we try to splone the node again, we found that we need
to splone, because the node that was created by the same sploning
process now has a different label because of the planting of the
fragment. Then after the sploning, we plant the fragment again. This
makes the newly sploned node have the same label (except for the clone
index) and the same children as the node that was sploned and planted
in the previous rounds.
The fix is to check for the existence of a node that has the same set
of children as the about-to-be-sploned node, except for the last one,
which contains the about-to-be-planted fragment as a prefix. If that
is the case, treat it as an already existing node, so that we do not
have to splone the node again.
This is consistent with the principle to not create what we do not
need.
Diffstat (limited to 'grammar/src/lib.rs')
-rw-r--r-- | grammar/src/lib.rs | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/grammar/src/lib.rs b/grammar/src/lib.rs index 54d9ebc..135f668 100644 --- a/grammar/src/lib.rs +++ b/grammar/src/lib.rs @@ -82,6 +82,7 @@ pub enum TNT { Ter(usize), /// Nonterminal variant Non(usize), + // TODO: Add a range type. } impl Display for TNT { @@ -834,6 +835,8 @@ impl Display for Grammar { } } +pub mod abnf; + // A helper module that provides some grammars for testing. #[cfg(feature = "test-helper")] pub mod test_grammar_helper; |