Skip to content

Rust lexer: bug fix with rust macros#1608

Merged
birkenfeld merged 3 commits intopygments:masterfrom
klux2:master
Nov 19, 2020
Merged

Rust lexer: bug fix with rust macros#1608
birkenfeld merged 3 commits intopygments:masterfrom
klux2:master

Conversation

@klux2
Copy link
Copy Markdown

@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
Copy Markdown
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.

3 participants