Skip to content

Commit

Permalink
Rust: fix lexing of "break" and "continue"
Browse files Browse the repository at this point in the history
fixes #1843
  • Loading branch information
birkenfeld committed Jun 20, 2021
1 parent faf69c0 commit 1664557
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGES
Expand Up @@ -12,6 +12,7 @@ Version 2.10.0
(not released yet)

- Fix assert statements in TNT lexer.
- Rust: fix lexing of "break" and "continue" (#1843)


Version 2.9.0
Expand Down
2 changes: 1 addition & 1 deletion pygments/lexers/rust.py
Expand Up @@ -109,7 +109,7 @@ class RustLexer(RegexLexer):
# Types in positions.
(r'(?::|->)', Text, 'typename'),
# Labels
(r'(break|continue)(\s*)(\'[A-Za-z_]\w*)?',
(r'(break|continue)(\b\s*)(\'[A-Za-z_]\w*)?',
bygroups(Keyword, Text.Whitespace, Name.Label)),

# Character literals
Expand Down
39 changes: 39 additions & 0 deletions tests/snippets/rust/test_break.txt
@@ -0,0 +1,39 @@
---input---
loop {
break;
break 'foo;
break'foo;
break_it;
}

---tokens---
'loop' Keyword
' ' Text.Whitespace
'{' Punctuation
'\n' Text.Whitespace

' ' Text.Whitespace
'break' Keyword
';' Punctuation
'\n' Text.Whitespace

' ' Text.Whitespace
'break' Keyword
' ' Text.Whitespace
"'foo" Name.Label
';' Punctuation
'\n' Text.Whitespace

' ' Text.Whitespace
'break' Keyword
"'foo" Name.Label
';' Punctuation
'\n' Text.Whitespace

' ' Text.Whitespace
'break_it' Name
';' Punctuation
'\n' Text.Whitespace

'}' Punctuation
'\n' Text.Whitespace

0 comments on commit 1664557

Please sign in to comment.