-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Core: Fixed greedy targeting bug #1932
Merged
RunDevelopment
merged 13 commits into
PrismJS:master
from
RunDevelopment:greedy-target-fix
Aug 29, 2019
Merged
Core: Fixed greedy targeting bug #1932
RunDevelopment
merged 13 commits into
PrismJS:master
from
RunDevelopment:greedy-target-fix
Aug 29, 2019
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This reverts commit d4736f0.
57f5751
to
8be7280
Compare
Possible to get tests that demonstrates the fixed behavior? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This PR fixes a bug of greedy matching.
The
target
parameter defines the token which causes rematching. Rematching is done by recursively callingmatchGrammar
wheretarget
will be the current token name. The rematching is done if either a match was found or we reached the target token, whatever comes first.The bug is that a token is identified by its name. But the name alone doesn't uniquely identify a token in a grammar because many tokens can have the same name:
The fix is quite obvious.
target
will no be a combination of the token name and its index.Note: This is a technically a breaking change because
matchGrammar
is publicly exposed. But the function is also not documented, so its behavior is undefined anyway.Edit:
An example of the bug is the following JS code:
Before:
![image](https://user-images.githubusercontent.com/20878432/59156998-29ad3e80-8aa4-11e9-9a09-6c28f9fa07c6.png)
After:
![image](https://user-images.githubusercontent.com/20878432/59157016-4184c280-8aa4-11e9-85f3-8067ee2c064b.png)