eric6/ThirdParty/Pygments/pygments/lexers/d.py

changeset 6942
2602857055c5
parent 5713
6762afd9f963
child 7547
21b0534faebc
equal deleted inserted replaced
6941:f99d60d6b59b 6942:2602857055c5
1 # -*- coding: utf-8 -*-
2 """
3 pygments.lexers.d
4 ~~~~~~~~~~~~~~~~~
5
6 Lexers for D languages.
7
8 :copyright: Copyright 2006-2017 by the Pygments team, see AUTHORS.
9 :license: BSD, see LICENSE for details.
10 """
11
12 from pygments.lexer import RegexLexer, include, words
13 from pygments.token import Text, Comment, Keyword, Name, String, \
14 Number, Punctuation
15
16 __all__ = ['DLexer', 'CrocLexer', 'MiniDLexer']
17
18
19 class DLexer(RegexLexer):
20 """
21 For D source.
22
23 .. versionadded:: 1.2
24 """
25 name = 'D'
26 filenames = ['*.d', '*.di']
27 aliases = ['d']
28 mimetypes = ['text/x-dsrc']
29
30 tokens = {
31 'root': [
32 (r'\n', Text),
33 (r'\s+', Text),
34 # (r'\\\n', Text), # line continuations
35 # Comments
36 (r'//(.*?)\n', Comment.Single),
37 (r'/(\\\n)?[*](.|\n)*?[*](\\\n)?/', Comment.Multiline),
38 (r'/\+', Comment.Multiline, 'nested_comment'),
39 # Keywords
40 (words((
41 'abstract', 'alias', 'align', 'asm', 'assert', 'auto', 'body',
42 'break', 'case', 'cast', 'catch', 'class', 'const', 'continue',
43 'debug', 'default', 'delegate', 'delete', 'deprecated', 'do', 'else',
44 'enum', 'export', 'extern', 'finally', 'final', 'foreach_reverse',
45 'foreach', 'for', 'function', 'goto', 'if', 'immutable', 'import',
46 'interface', 'invariant', 'inout', 'in', 'is', 'lazy', 'mixin',
47 'module', 'new', 'nothrow', 'out', 'override', 'package', 'pragma',
48 'private', 'protected', 'public', 'pure', 'ref', 'return', 'scope',
49 'shared', 'static', 'struct', 'super', 'switch', 'synchronized',
50 'template', 'this', 'throw', 'try', 'typedef', 'typeid', 'typeof',
51 'union', 'unittest', 'version', 'volatile', 'while', 'with',
52 '__gshared', '__traits', '__vector', '__parameters'),
53 suffix=r'\b'),
54 Keyword),
55 (words((
56 'bool', 'byte', 'cdouble', 'cent', 'cfloat', 'char', 'creal',
57 'dchar', 'double', 'float', 'idouble', 'ifloat', 'int', 'ireal',
58 'long', 'real', 'short', 'ubyte', 'ucent', 'uint', 'ulong',
59 'ushort', 'void', 'wchar'), suffix=r'\b'),
60 Keyword.Type),
61 (r'(false|true|null)\b', Keyword.Constant),
62 (words((
63 '__FILE__', '__MODULE__', '__LINE__', '__FUNCTION__', '__PRETTY_FUNCTION__'
64 '', '__DATE__', '__EOF__', '__TIME__', '__TIMESTAMP__', '__VENDOR__',
65 '__VERSION__'), suffix=r'\b'),
66 Keyword.Pseudo),
67 (r'macro\b', Keyword.Reserved),
68 (r'(string|wstring|dstring|size_t|ptrdiff_t)\b', Name.Builtin),
69 # FloatLiteral
70 # -- HexFloat
71 (r'0[xX]([0-9a-fA-F_]*\.[0-9a-fA-F_]+|[0-9a-fA-F_]+)'
72 r'[pP][+\-]?[0-9_]+[fFL]?[i]?', Number.Float),
73 # -- DecimalFloat
74 (r'[0-9_]+(\.[0-9_]+[eE][+\-]?[0-9_]+|'
75 r'\.[0-9_]*|[eE][+\-]?[0-9_]+)[fFL]?[i]?', Number.Float),
76 (r'\.(0|[1-9][0-9_]*)([eE][+\-]?[0-9_]+)?[fFL]?[i]?', Number.Float),
77 # IntegerLiteral
78 # -- Binary
79 (r'0[Bb][01_]+', Number.Bin),
80 # -- Octal
81 (r'0[0-7_]+', Number.Oct),
82 # -- Hexadecimal
83 (r'0[xX][0-9a-fA-F_]+', Number.Hex),
84 # -- Decimal
85 (r'(0|[1-9][0-9_]*)([LUu]|Lu|LU|uL|UL)?', Number.Integer),
86 # CharacterLiteral
87 (r"""'(\\['"?\\abfnrtv]|\\x[0-9a-fA-F]{2}|\\[0-7]{1,3}"""
88 r"""|\\u[0-9a-fA-F]{4}|\\U[0-9a-fA-F]{8}|\\&\w+;|.)'""",
89 String.Char),
90 # StringLiteral
91 # -- WysiwygString
92 (r'r"[^"]*"[cwd]?', String),
93 # -- AlternateWysiwygString
94 (r'`[^`]*`[cwd]?', String),
95 # -- DoubleQuotedString
96 (r'"(\\\\|\\"|[^"])*"[cwd]?', String),
97 # -- EscapeSequence
98 (r"\\(['\"?\\abfnrtv]|x[0-9a-fA-F]{2}|[0-7]{1,3}"
99 r"|u[0-9a-fA-F]{4}|U[0-9a-fA-F]{8}|&\w+;)",
100 String),
101 # -- HexString
102 (r'x"[0-9a-fA-F_\s]*"[cwd]?', String),
103 # -- DelimitedString
104 (r'q"\[', String, 'delimited_bracket'),
105 (r'q"\(', String, 'delimited_parenthesis'),
106 (r'q"<', String, 'delimited_angle'),
107 (r'q"\{', String, 'delimited_curly'),
108 (r'q"([a-zA-Z_]\w*)\n.*?\n\1"', String),
109 (r'q"(.).*?\1"', String),
110 # -- TokenString
111 (r'q\{', String, 'token_string'),
112 # Attributes
113 (r'@([a-zA-Z_]\w*)?', Name.Decorator),
114 # Tokens
115 (r'(~=|\^=|%=|\*=|==|!>=|!<=|!<>=|!<>|!<|!>|!=|>>>=|>>>|>>=|>>|>='
116 r'|<>=|<>|<<=|<<|<=|\+\+|\+=|--|-=|\|\||\|=|&&|&=|\.\.\.|\.\.|/=)'
117 r'|[/.&|\-+<>!()\[\]{}?,;:$=*%^~]', Punctuation),
118 # Identifier
119 (r'[a-zA-Z_]\w*', Name),
120 # Line
121 (r'#line\s.*\n', Comment.Special),
122 ],
123 'nested_comment': [
124 (r'[^+/]+', Comment.Multiline),
125 (r'/\+', Comment.Multiline, '#push'),
126 (r'\+/', Comment.Multiline, '#pop'),
127 (r'[+/]', Comment.Multiline),
128 ],
129 'token_string': [
130 (r'\{', Punctuation, 'token_string_nest'),
131 (r'\}', String, '#pop'),
132 include('root'),
133 ],
134 'token_string_nest': [
135 (r'\{', Punctuation, '#push'),
136 (r'\}', Punctuation, '#pop'),
137 include('root'),
138 ],
139 'delimited_bracket': [
140 (r'[^\[\]]+', String),
141 (r'\[', String, 'delimited_inside_bracket'),
142 (r'\]"', String, '#pop'),
143 ],
144 'delimited_inside_bracket': [
145 (r'[^\[\]]+', String),
146 (r'\[', String, '#push'),
147 (r'\]', String, '#pop'),
148 ],
149 'delimited_parenthesis': [
150 (r'[^()]+', String),
151 (r'\(', String, 'delimited_inside_parenthesis'),
152 (r'\)"', String, '#pop'),
153 ],
154 'delimited_inside_parenthesis': [
155 (r'[^()]+', String),
156 (r'\(', String, '#push'),
157 (r'\)', String, '#pop'),
158 ],
159 'delimited_angle': [
160 (r'[^<>]+', String),
161 (r'<', String, 'delimited_inside_angle'),
162 (r'>"', String, '#pop'),
163 ],
164 'delimited_inside_angle': [
165 (r'[^<>]+', String),
166 (r'<', String, '#push'),
167 (r'>', String, '#pop'),
168 ],
169 'delimited_curly': [
170 (r'[^{}]+', String),
171 (r'\{', String, 'delimited_inside_curly'),
172 (r'\}"', String, '#pop'),
173 ],
174 'delimited_inside_curly': [
175 (r'[^{}]+', String),
176 (r'\{', String, '#push'),
177 (r'\}', String, '#pop'),
178 ],
179 }
180
181
182 class CrocLexer(RegexLexer):
183 """
184 For `Croc <http://jfbillingsley.com/croc>`_ source.
185 """
186 name = 'Croc'
187 filenames = ['*.croc']
188 aliases = ['croc']
189 mimetypes = ['text/x-crocsrc']
190
191 tokens = {
192 'root': [
193 (r'\n', Text),
194 (r'\s+', Text),
195 # Comments
196 (r'//(.*?)\n', Comment.Single),
197 (r'/\*', Comment.Multiline, 'nestedcomment'),
198 # Keywords
199 (words((
200 'as', 'assert', 'break', 'case', 'catch', 'class', 'continue',
201 'default', 'do', 'else', 'finally', 'for', 'foreach', 'function',
202 'global', 'namespace', 'if', 'import', 'in', 'is', 'local',
203 'module', 'return', 'scope', 'super', 'switch', 'this', 'throw',
204 'try', 'vararg', 'while', 'with', 'yield'), suffix=r'\b'),
205 Keyword),
206 (r'(false|true|null)\b', Keyword.Constant),
207 # FloatLiteral
208 (r'([0-9][0-9_]*)(?=[.eE])(\.[0-9][0-9_]*)?([eE][+\-]?[0-9_]+)?',
209 Number.Float),
210 # IntegerLiteral
211 # -- Binary
212 (r'0[bB][01][01_]*', Number.Bin),
213 # -- Hexadecimal
214 (r'0[xX][0-9a-fA-F][0-9a-fA-F_]*', Number.Hex),
215 # -- Decimal
216 (r'([0-9][0-9_]*)(?![.eE])', Number.Integer),
217 # CharacterLiteral
218 (r"""'(\\['"\\nrt]|\\x[0-9a-fA-F]{2}|\\[0-9]{1,3}"""
219 r"""|\\u[0-9a-fA-F]{4}|\\U[0-9a-fA-F]{8}|.)'""",
220 String.Char),
221 # StringLiteral
222 # -- WysiwygString
223 (r'@"(""|[^"])*"', String),
224 (r'@`(``|[^`])*`', String),
225 (r"@'(''|[^'])*'", String),
226 # -- DoubleQuotedString
227 (r'"(\\\\|\\"|[^"])*"', String),
228 # Tokens
229 (r'(~=|\^=|%=|\*=|==|!=|>>>=|>>>|>>=|>>|>=|<=>|\?=|-\>'
230 r'|<<=|<<|<=|\+\+|\+=|--|-=|\|\||\|=|&&|&=|\.\.|/=)'
231 r'|[-/.&$@|\+<>!()\[\]{}?,;:=*%^~#\\]', Punctuation),
232 # Identifier
233 (r'[a-zA-Z_]\w*', Name),
234 ],
235 'nestedcomment': [
236 (r'[^*/]+', Comment.Multiline),
237 (r'/\*', Comment.Multiline, '#push'),
238 (r'\*/', Comment.Multiline, '#pop'),
239 (r'[*/]', Comment.Multiline),
240 ],
241 }
242
243
244 class MiniDLexer(CrocLexer):
245 """
246 For MiniD source. MiniD is now known as Croc.
247 """
248 name = 'MiniD'
249 filenames = [] # don't lex .md as MiniD, reserve for Markdown
250 aliases = ['minid']
251 mimetypes = ['text/x-minidsrc']

eric ide

mercurial