Skip to content
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

Rust lexer: bug fix with rust macros #1608

Merged
merged 3 commits into from Nov 19, 2020
Merged

Conversation

klux2
Copy link

@klux2 klux2 commented Nov 18, 2020

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 regex r"println!\b" (it would instead be matched by r"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.

K. Lux 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.
@birkenfeld
Copy link
Member

Thanks for the PR! The failure to highlight macros is indeed embarrassing.

@birkenfeld birkenfeld merged commit 1ee4350 into pygments:master Nov 19, 2020
@birkenfeld birkenfeld added the changelog-update Items which need to get mentioned in the changelog label Nov 19, 2020
@Anteru Anteru added this to the 2.7.3 milestone Nov 25, 2020
@Anteru Anteru removed the changelog-update Items which need to get mentioned in the changelog label Dec 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants