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

Improved Rust attributes #1813

Merged
merged 6 commits into from Jun 25, 2021
Merged

Improved Rust attributes #1813

merged 6 commits into from Jun 25, 2021

Conversation

kaivol
Copy link
Contributor

@kaivol kaivol commented May 22, 2021

Rust attributes with nested brackets are currently not correctly highlighted.

For example, in

#[foo(bar = [baz, qux])]

the attribute is only highlighted until the first closing square bracket.

I think this should fixed with these changes.

@Anteru
Copy link
Collaborator

Anteru commented May 22, 2021

Can you please add a test for this? There's a rust example file, it should be sufficient to add one line with an attribute like that there.

@kaivol
Copy link
Contributor Author

kaivol commented May 22, 2021

You mean like that?

Unfortunately I'm not familiar with pygments so I'm not exactly sure what I'm doing here...

@Anteru
Copy link
Collaborator

Anteru commented May 22, 2021

Yeah, adding it to the example file is sufficient, thanks!

@dario23
Copy link

dario23 commented Jun 22, 2021

i just stumbled over this problem as well. as far as i can see, the diff needed to make the rust tests pass is

diff --git a/tests/examplefiles/rust/eval.rs.output b/tests/examplefiles/rust/eval.rs.output
index 186a7c0c..dd0f7997 100644
--- a/tests/examplefiles/rust/eval.rs.output
+++ b/tests/examplefiles/rust/eval.rs.output
@@ -218,7 +218,10 @@
 '/// Represents a value (either 16-bit or 32-bit) at runtime.\n' Literal.String.Doc
 
 '#['          Comment.Preproc
-'derive(Clone, PartialEq, Eq, Debug)' Comment.Preproc
+'derive'      Comment.Preproc
+'('           Comment.Preproc
+'Clone, PartialEq, Eq, Debug' Comment.Preproc
+')'           Comment.Preproc
 ']'           Comment.Preproc
 '\n'          Text.Whitespace

aka the #[derive(..)] line is now looked at in more detail as well, just like the initial example.

@birkenfeld
Copy link
Member

Actually, why are we tracking ( and ) pairs? The only thing that's relevant is nested [ and ]...

@kaivol
Copy link
Contributor Author

kaivol commented Jun 23, 2021

For highlighting purposes it should indeed be sufficient to look at square brackets.
Should I change the code accordingly?

@birkenfeld
Copy link
Member

That would be nice, and it will also reduce the number of individual tokens.

pygments/lexers/rust.py Outdated Show resolved Hide resolved
@birkenfeld
Copy link
Member

Thanks!

@birkenfeld birkenfeld merged commit f0ff1ba into pygments:master Jun 25, 2021
@Anteru Anteru added this to the 2.10 milestone Jul 18, 2021
@Anteru Anteru added the changelog-update Items which need to get mentioned in the changelog label Jul 18, 2021
@Anteru Anteru self-assigned this Jul 18, 2021
@Anteru Anteru added A-lexing area: changes to individual lexers and removed changelog-update Items which need to get mentioned in the changelog labels Aug 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lexing area: changes to individual lexers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants