3 pygments.lexers.dotnet |
3 pygments.lexers.dotnet |
4 ~~~~~~~~~~~~~~~~~~~~~~ |
4 ~~~~~~~~~~~~~~~~~~~~~~ |
5 |
5 |
6 Lexers for .net languages. |
6 Lexers for .net languages. |
7 |
7 |
8 :copyright: Copyright 2006-2012 by the Pygments team, see AUTHORS. |
8 :copyright: Copyright 2006-2013 by the Pygments team, see AUTHORS. |
9 :license: BSD, see LICENSE for details. |
9 :license: BSD, see LICENSE for details. |
10 """ |
10 """ |
11 import re |
11 import re |
12 |
12 |
13 from pygments.lexer import RegexLexer, DelegatingLexer, bygroups, include, \ |
13 from pygments.lexer import RegexLexer, DelegatingLexer, bygroups, include, \ |
20 from pygments.lexers.web import XmlLexer |
20 from pygments.lexers.web import XmlLexer |
21 |
21 |
22 __all__ = ['CSharpLexer', 'NemerleLexer', 'BooLexer', 'VbNetLexer', |
22 __all__ = ['CSharpLexer', 'NemerleLexer', 'BooLexer', 'VbNetLexer', |
23 'CSharpAspxLexer', 'VbNetAspxLexer', 'FSharpLexer'] |
23 'CSharpAspxLexer', 'VbNetAspxLexer', 'FSharpLexer'] |
24 |
24 |
25 |
|
26 def _escape(st): |
|
27 return st.replace('\\', r'\\').replace('-', r'\-').\ |
|
28 replace('[', r'\[').replace(']', r'\]') |
|
29 |
25 |
30 class CSharpLexer(RegexLexer): |
26 class CSharpLexer(RegexLexer): |
31 """ |
27 """ |
32 For `C# <http://msdn2.microsoft.com/en-us/vcsharp/default.aspx>`_ |
28 For `C# <http://msdn2.microsoft.com/en-us/vcsharp/default.aspx>`_ |
33 source code. |
29 source code. |
65 'none': '@?[_a-zA-Z][a-zA-Z0-9_]*', |
61 'none': '@?[_a-zA-Z][a-zA-Z0-9_]*', |
66 'basic': ('@?[_' + uni.Lu + uni.Ll + uni.Lt + uni.Lm + uni.Nl + ']' + |
62 'basic': ('@?[_' + uni.Lu + uni.Ll + uni.Lt + uni.Lm + uni.Nl + ']' + |
67 '[' + uni.Lu + uni.Ll + uni.Lt + uni.Lm + uni.Nl + |
63 '[' + uni.Lu + uni.Ll + uni.Lt + uni.Lm + uni.Nl + |
68 uni.Nd + uni.Pc + uni.Cf + uni.Mn + uni.Mc + ']*'), |
64 uni.Nd + uni.Pc + uni.Cf + uni.Mn + uni.Mc + ']*'), |
69 'full': ('@?(?:_|[^' + |
65 'full': ('@?(?:_|[^' + |
70 _escape(uni.allexcept('Lu', 'Ll', 'Lt', 'Lm', 'Lo', 'Nl')) + '])' |
66 uni.allexcept('Lu', 'Ll', 'Lt', 'Lm', 'Lo', 'Nl') + '])' |
71 + '[^' + _escape(uni.allexcept('Lu', 'Ll', 'Lt', 'Lm', 'Lo', |
67 + '[^' + uni.allexcept('Lu', 'Ll', 'Lt', 'Lm', 'Lo', 'Nl', |
72 'Nl', 'Nd', 'Pc', 'Cf', 'Mn', |
68 'Nd', 'Pc', 'Cf', 'Mn', 'Mc') + ']*'), |
73 'Mc')) + ']*'), |
|
74 } |
69 } |
75 |
70 |
76 tokens = {} |
71 tokens = {} |
77 token_variants = True |
72 token_variants = True |
78 |
73 |
86 bygroups(using(this), Name.Function, Text, Punctuation)), |
81 bygroups(using(this), Name.Function, Text, Punctuation)), |
87 (r'^\s*\[.*?\]', Name.Attribute), |
82 (r'^\s*\[.*?\]', Name.Attribute), |
88 (r'[^\S\n]+', Text), |
83 (r'[^\S\n]+', Text), |
89 (r'\\\n', Text), # line continuation |
84 (r'\\\n', Text), # line continuation |
90 (r'//.*?\n', Comment.Single), |
85 (r'//.*?\n', Comment.Single), |
91 (r'/[*](.|\n)*?[*]/', Comment.Multiline), |
86 (r'/[*].*?[*]/', Comment.Multiline), |
92 (r'\n', Text), |
87 (r'\n', Text), |
93 (r'[~!%^&*()+=|\[\]:;,.<>/?-]', Punctuation), |
88 (r'[~!%^&*()+=|\[\]:;,.<>/?-]', Punctuation), |
94 (r'[{}]', Punctuation), |
89 (r'[{}]', Punctuation), |
95 (r'@"(""|[^"])*"', String), |
90 (r'@"(""|[^"])*"', String), |
96 (r'"(\\\\|\\"|[^"\n])*["\n]', String), |
91 (r'"(\\\\|\\"|[^"\n])*["\n]', String), |
100 (r'#[ \t]*(if|endif|else|elif|define|undef|' |
95 (r'#[ \t]*(if|endif|else|elif|define|undef|' |
101 r'line|error|warning|region|endregion|pragma)\b.*?\n', |
96 r'line|error|warning|region|endregion|pragma)\b.*?\n', |
102 Comment.Preproc), |
97 Comment.Preproc), |
103 (r'\b(extern)(\s+)(alias)\b', bygroups(Keyword, Text, |
98 (r'\b(extern)(\s+)(alias)\b', bygroups(Keyword, Text, |
104 Keyword)), |
99 Keyword)), |
105 (r'(abstract|as|base|break|case|catch|' |
100 (r'(abstract|as|async|await|base|break|case|catch|' |
106 r'checked|const|continue|default|delegate|' |
101 r'checked|const|continue|default|delegate|' |
107 r'do|else|enum|event|explicit|extern|false|finally|' |
102 r'do|else|enum|event|explicit|extern|false|finally|' |
108 r'fixed|for|foreach|goto|if|implicit|in|interface|' |
103 r'fixed|for|foreach|goto|if|implicit|in|interface|' |
109 r'internal|is|lock|new|null|operator|' |
104 r'internal|is|lock|new|null|operator|' |
110 r'out|override|params|private|protected|public|readonly|' |
105 r'out|override|params|private|protected|public|readonly|' |
177 levels = dict( |
172 levels = dict( |
178 none = '@?[_a-zA-Z][a-zA-Z0-9_]*', |
173 none = '@?[_a-zA-Z][a-zA-Z0-9_]*', |
179 basic = ('@?[_' + uni.Lu + uni.Ll + uni.Lt + uni.Lm + uni.Nl + ']' + |
174 basic = ('@?[_' + uni.Lu + uni.Ll + uni.Lt + uni.Lm + uni.Nl + ']' + |
180 '[' + uni.Lu + uni.Ll + uni.Lt + uni.Lm + uni.Nl + |
175 '[' + uni.Lu + uni.Ll + uni.Lt + uni.Lm + uni.Nl + |
181 uni.Nd + uni.Pc + uni.Cf + uni.Mn + uni.Mc + ']*'), |
176 uni.Nd + uni.Pc + uni.Cf + uni.Mn + uni.Mc + ']*'), |
182 full = ('@?(?:_|[^' + _escape(uni.allexcept('Lu', 'Ll', 'Lt', 'Lm', |
177 full = ('@?(?:_|[^' + uni.allexcept('Lu', 'Ll', 'Lt', 'Lm', 'Lo', |
183 'Lo', 'Nl')) + '])' |
178 'Nl') + '])' |
184 + '[^' + _escape(uni.allexcept('Lu', 'Ll', 'Lt', 'Lm', 'Lo', |
179 + '[^' + uni.allexcept('Lu', 'Ll', 'Lt', 'Lm', 'Lo', 'Nl', |
185 'Nl', 'Nd', 'Pc', 'Cf', 'Mn', |
180 'Nd', 'Pc', 'Cf', 'Mn', 'Mc') + ']*'), |
186 'Mc')) + ']*'), |
|
187 ) |
181 ) |
188 |
182 |
189 tokens = {} |
183 tokens = {} |
190 token_variants = True |
184 token_variants = True |
191 |
185 |