Fix handling of repeats and alternative options in Tabular #75
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I have noticed that tests in
RegexSpec
foratMost
andbetween
were ignored and that they would fail. In this PR I attempt to make them green.There were two bigger areas that I fixed.
Handling of the
|
operator between Steps. In the original version, combining anything withMatched
would be aMatched
state as well. This would, however, reduce alternatives likeaaa | aa | a
to the shortest possible sequence. To help with this, I "uncommented" theMatchedOrJump
type and interpreted it as some kind of "checkpoint". If in the while loop in the implementation oftest
we encounter aMatchedOrJump
, we setreturnV
to the current index but otherwise continue the loop. CombiningMatched with Jump(...)
in this case would resuld aMatchedOrJump
.Handling Empty matchers: The current implementation of
LookupFunction
can only tell if a character matches or not. It cannot tell if it can match without consuming any input. There is anobject Empty
which extendsTabular
, but it cannot be combined with aLookupFunction
currently (Empty | lookup = lookup
). This will fail for uses ofatMost
, or generallyRepeat
where 0 matches are allowed as well. To fix this, I movedEmpty
underLookupFunction
and introduced asupportsEmpty
value toLookupFunction
. Combining lookup functions sequentially wheresupportsEmpty=true
will createMatchedOrJump
steps as well.