Skip to content

Commit

Permalink
Improved Rust attributes (#1813)
Browse files Browse the repository at this point in the history
  • Loading branch information
kaivol committed Jun 25, 2021
1 parent 94dda68 commit f0ff1ba
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
10 changes: 2 additions & 8 deletions pygments/lexers/rust.py
Expand Up @@ -213,16 +213,10 @@ class RustLexer(RegexLexer):
'attribute_common': [
(r'"', String, 'string'),
(r'\[', Comment.Preproc, 'attribute['),
(r'\(', Comment.Preproc, 'attribute('),
],
'attribute[': [
include('attribute_common'),
(r'\];?', Comment.Preproc, '#pop'),
(r'[^"\]]+', Comment.Preproc),
],
'attribute(': [
include('attribute_common'),
(r'\);?', Comment.Preproc, '#pop'),
(r'[^")]+', Comment.Preproc),
(r'\]', Comment.Preproc, '#pop'),
(r'[^"\]\[]+', Comment.Preproc),
],
}
12 changes: 12 additions & 0 deletions tests/snippets/rust/test_attribute.txt
@@ -0,0 +1,12 @@
---input---
#[foo(bar = [baz, qux])]

---tokens---
'#[' Comment.Preproc
'foo(bar = ' Comment.Preproc
'[' Comment.Preproc
'baz, qux' Comment.Preproc
']' Comment.Preproc
')' Comment.Preproc
']' Comment.Preproc
'\n' Text.Whitespace

0 comments on commit f0ff1ba

Please sign in to comment.