diff --git a/CHANGES b/CHANGES index df1ea07106..b4ce1fe2cb 100644 --- a/CHANGES +++ b/CHANGES @@ -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 diff --git a/pygments/lexers/rust.py b/pygments/lexers/rust.py index 6cb8291d76..c57f2b9e6b 100644 --- a/pygments/lexers/rust.py +++ b/pygments/lexers/rust.py @@ -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 diff --git a/tests/snippets/rust/test_break.txt b/tests/snippets/rust/test_break.txt new file mode 100644 index 0000000000..7dafde2d8f --- /dev/null +++ b/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