Skip to content

Commit

Permalink
C#: recognize Operators as such, fix split-up numeric literals
Browse files Browse the repository at this point in the history
Fixes #2256
  • Loading branch information
birkenfeld committed Oct 22, 2022
1 parent 50ed74d commit a9b5fac
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 98 deletions.
1 change: 1 addition & 0 deletions CHANGES
Expand Up @@ -23,6 +23,7 @@ Version 2.14.0
* C family (C, C++ and many others): fix an issue where a chunk would
be wrongly recognized as a function definition due to braces in
comments (#2210)
* C#: fix number and operator recognition (#2257)
* gas (GNU assembler): recognize braces as punctuation (#2230)
* HTTP: add `CONNECT` keyword
* Inform 6: fix lexing of properties and doubles (#2214)
Expand Down
11 changes: 9 additions & 2 deletions pygments/lexers/dotnet.py
Expand Up @@ -85,12 +85,19 @@ class CSharpLexer(RegexLexer):
(r'//.*?\n', Comment.Single),
(r'/[*].*?[*]/', Comment.Multiline),
(r'\n', Whitespace),
(r'[~!%^&*()+=|\[\]:;,.<>/?-]', Punctuation),
(words((
'>>>=', '>>=', '<<=', '<=', '>=', '+=', '-=', '*=', '/=',
'%=', '&=', '|=', '^=', '??=', '=>', '??', '?.', '!=', '==',
'&&', '||', '>>>', '>>', '<<', '++', '--', '+', '-', '*',
'/', '%', '&', '|', '^', '<', '>', '?', '!', '~', '=',
)), Operator),
(r'=~|!=|==|<<|>>|[-+/*%=<>&^|]', Operator),
(r'[()\[\];:,.]', Punctuation),
(r'[{}]', Punctuation),
(r'@"(""|[^"])*"', String),
(r'\$?"(\\\\|\\[^\\]|[^"\\\n])*["\n]', String),
(r"'\\.'|'[^\\]'", String.Char),
(r"[0-9](\.[0-9]*)?([eE][+-][0-9]+)?"
(r"[0-9]+(\.[0-9]*)?([eE][+-][0-9]+)?"
r"[flFLdD]?|0[xX][0-9a-fA-F]+[Ll]?", Number),
(r'(#)([ \t]*)(if|endif|else|elif|define|undef|'
r'line|error|warning|region|endregion|pragma)\b(.*?)(\n)',
Expand Down
4 changes: 2 additions & 2 deletions tests/examplefiles/aspx-cs/aspx-cs_example.output

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a9b5fac

Please sign in to comment.