Rust lexer: bug fix with rust macros#1608
Merged
birkenfeld merged 3 commits intopygments:masterfrom Nov 19, 2020
Merged
Conversation
added 3 commits
November 19, 2020 00:04
'drop', 'Some', 'None', 'Ok' and 'Err' are types, not macros.
Rust macros end with a '!'. The word border (regex '\b') for such expressions is located before the '!' (e. g. "print\b!(...)"). The regex here used the suffix option, which added an r'\b' after each regex (e. g. r'print!\b'). Therefore, the supplied regular expressions didn't match the rust macros. To fix this problem, the suffix is removed. As every macro ends with an '!' (which implicitely includes a word border before), it's not necessary anyway.
Rust macros seem to fit more into the "magic function" category than into the "builtin" one.
Member
|
Thanks for the PR! The failure to highlight macros is indeed embarrassing. |
This file contains hidden or 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
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.
Rust macros would not be recognized/formatted, as they end with a '!', which does not count as word boundary. This was required by the suffix r'\b' (after the '!').
A typical macro call like
"println!("test");"would not be matched by the associated regexr"println!\b"(it would instead be matched byr"println\b!").To fix this problem, the suffix is removed. As every macro ends with an '!' (which implicitely includes a word boundary before), it's not necessary anyway for the macros.
There were also several keywords which are not macros (as far as I know) listed in this category. They were moved to the correct section. As both categories used the same token anyway, it doesn't really matter.
Lastly, the token type for macros was changed. Rust macros seem to fit more into the magic function (
Name.Function.Magic) category than into the builtin (Name.Builtin) one.