-
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
Greedy matching bug #1492
Comments
This was referenced Jul 27, 2018
Closed
Here is a minimal example showing the bug in action: Language definitionI used aliases for styling. Prism.languages['greedy-test'] = {
'a': {
pattern: /'[^'\r\n]*'/,
alias: 'comment'
},
'b': {
pattern: /"[^"\r\n]*"/,
greedy: true,
alias: 'string'
},
'c': {
pattern: /<[^>\r\n]*>/,
greedy: true,
alias: 'keyword'
}
} Code:
(Each line is one example.) Notes:
|
This was referenced Apr 1, 2019
This was referenced Aug 23, 2019
Merged
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Consider the following code:
Highlighted using Test Drive:
What's happening is quite simple:
template-string
matches(?:\\[\s\S]|\${[^}]+}|[^\\
and/, 'a': 0 ....... 'string': /(
(plus the grave accents).string
matches'template-string-pattern'
and'c'
. The rest is blocked bytemplate-string
.regex
breaks the matches oftemplate-string
and highlights the regexes.string
gets a chance fromregex
to match and does so matching'a'
. But that's it, becauseoneshot=true
.Btw: You can see this bug all over the place when you look at the Prism code with lots of language definitions.
The text was updated successfully, but these errors were encountered: