-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Disallow DFAs with ambiguous actions [RFC] #49
Conversation
It might be possible to catch these by changing the |
Alright, all edge cases I could think of has now been covered. The ambiguity check can be skipped by passing Conflicting preconditions should resolve ambiguities, but I've not been able to actually construct conflicting preconditions, so I haven't been able to test it in This is ready to merge. |
This is awesome, thanks for putting in the work! Sad to lose 100% coverage - maybe @bicycle1885 has ideas for how to test? |
I can't access the codecov report @kescobo. If I get access, I'll fix it myself. |
Turns out it's possible to create a loop of epsilon edges:
This leads to an infinite loop, so that needs to be fixed. |
Infinite loop fixed, but that exposed a bug (or well, suboptimal behaviour) in the |
Defines an unambiguous state machine based on BioJulia/Automa.jl#49.
Defines an unambiguous state machine. BioJulia/Automa.jl#49.
See issue #48 . With this PR, attempting to create a DFA with ambiguous actions will result in an error.
Before:
Here, the machine, when seeing an
X
, won't know if it has to execute:entering_A
or not. Previously, all possible actions were taken, even mututally exclusive ones, which could result in unexpected and self-contradicting behaviour, like exiting the same regex multiple times, or entering a regex and never exiting it (even at EOF).With this commit, the above code raises an error:
ERROR: Ambiguous NFA: Byte 0x58 can lead to actions nothing or [:entering_A]
Note that you can still have ambiguous DFAs if the actions are not ambiguous, for example this code will still work:
While the machine don't know if it is entering A or B, that doesn't matter because they lead to the same actions. And when exiting A, the machine knows for certain that it's not exiting B.
Edit: This change will cause multiple tests to fail, because several tests include ambiguous DFAs. I think the tests should be changed, but want comments for this.