Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/pygments/lexers/d.py: 100%
22 statements
« prev ^ index » next coverage.py v7.2.7, created at 2023-07-01 06:54 +0000
« prev ^ index » next coverage.py v7.2.7, created at 2023-07-01 06:54 +0000
1"""
2 pygments.lexers.d
3 ~~~~~~~~~~~~~~~~~
5 Lexers for D languages.
7 :copyright: Copyright 2006-2023 by the Pygments team, see AUTHORS.
8 :license: BSD, see LICENSE for details.
9"""
11from pygments.lexer import RegexLexer, include, words, bygroups
12from pygments.token import Comment, Keyword, Name, String, Number, \
13 Punctuation, Whitespace
15__all__ = ['DLexer', 'CrocLexer', 'MiniDLexer']
18class DLexer(RegexLexer):
19 """
20 For D source.
22 .. versionadded:: 1.2
23 """
24 name = 'D'
25 url = 'https://dlang.org/'
26 filenames = ['*.d', '*.di']
27 aliases = ['d']
28 mimetypes = ['text/x-dsrc']
30 tokens = {
31 'root': [
32 (r'\n', Whitespace),
33 (r'\s+', Whitespace),
34 # (r'\\\n', Text), # line continuations
35 # Comments
36 (r'(//.*?)(\n)', bygroups(Comment.Single, Whitespace)),
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', 'typeid', 'typeof',
51 'union', 'unittest', 'version', 'volatile', 'while', 'with',
52 '__gshared', '__traits', '__vector', '__parameters'),
53 suffix=r'\b'),
54 Keyword),
55 (words((
56 # Removed in 2.072
57 'typedef', ),
58 suffix=r'\b'),
59 Keyword.Removed),
60 (words((
61 'bool', 'byte', 'cdouble', 'cent', 'cfloat', 'char', 'creal',
62 'dchar', 'double', 'float', 'idouble', 'ifloat', 'int', 'ireal',
63 'long', 'real', 'short', 'ubyte', 'ucent', 'uint', 'ulong',
64 'ushort', 'void', 'wchar'), suffix=r'\b'),
65 Keyword.Type),
66 (r'(false|true|null)\b', Keyword.Constant),
67 (words((
68 '__FILE__', '__FILE_FULL_PATH__', '__MODULE__', '__LINE__', '__FUNCTION__',
69 '__PRETTY_FUNCTION__', '__DATE__', '__EOF__', '__TIME__', '__TIMESTAMP__',
70 '__VENDOR__', '__VERSION__'), suffix=r'\b'),
71 Keyword.Pseudo),
72 (r'macro\b', Keyword.Reserved),
73 (r'(string|wstring|dstring|size_t|ptrdiff_t)\b', Name.Builtin),
74 # FloatLiteral
75 # -- HexFloat
76 (r'0[xX]([0-9a-fA-F_]*\.[0-9a-fA-F_]+|[0-9a-fA-F_]+)'
77 r'[pP][+\-]?[0-9_]+[fFL]?[i]?', Number.Float),
78 # -- DecimalFloat
79 (r'[0-9_]+(\.[0-9_]+[eE][+\-]?[0-9_]+|'
80 r'\.[0-9_]*|[eE][+\-]?[0-9_]+)[fFL]?[i]?', Number.Float),
81 (r'\.(0|[1-9][0-9_]*)([eE][+\-]?[0-9_]+)?[fFL]?[i]?', Number.Float),
82 # IntegerLiteral
83 # -- Binary
84 (r'0[Bb][01_]+', Number.Bin),
85 # -- Octal
86 (r'0[0-7_]+', Number.Oct),
87 # -- Hexadecimal
88 (r'0[xX][0-9a-fA-F_]+', Number.Hex),
89 # -- Decimal
90 (r'(0|[1-9][0-9_]*)([LUu]|Lu|LU|uL|UL)?', Number.Integer),
91 # CharacterLiteral
92 (r"""'(\\['"?\\abfnrtv]|\\x[0-9a-fA-F]{2}|\\[0-7]{1,3}"""
93 r"""|\\u[0-9a-fA-F]{4}|\\U[0-9a-fA-F]{8}|\\&\w+;|.)'""",
94 String.Char),
95 # StringLiteral
96 # -- WysiwygString
97 (r'r"[^"]*"[cwd]?', String),
98 # -- AlternateWysiwygString
99 (r'`[^`]*`[cwd]?', String),
100 # -- DoubleQuotedString
101 (r'"(\\\\|\\[^\\]|[^"\\])*"[cwd]?', String),
102 # -- EscapeSequence
103 (r"\\(['\"?\\abfnrtv]|x[0-9a-fA-F]{2}|[0-7]{1,3}"
104 r"|u[0-9a-fA-F]{4}|U[0-9a-fA-F]{8}|&\w+;)",
105 String),
106 # -- HexString
107 (r'x"[0-9a-fA-F_\s]*"[cwd]?', String),
108 # -- DelimitedString
109 (r'q"\[', String, 'delimited_bracket'),
110 (r'q"\(', String, 'delimited_parenthesis'),
111 (r'q"<', String, 'delimited_angle'),
112 (r'q"\{', String, 'delimited_curly'),
113 (r'q"([a-zA-Z_]\w*)\n.*?\n\1"', String),
114 (r'q"(.).*?\1"', String),
115 # -- TokenString
116 (r'q\{', String, 'token_string'),
117 # Attributes
118 (r'@([a-zA-Z_]\w*)?', Name.Decorator),
119 # Tokens
120 (r'(~=|\^=|%=|\*=|==|!>=|!<=|!<>=|!<>|!<|!>|!=|>>>=|>>>|>>=|>>|>='
121 r'|<>=|<>|<<=|<<|<=|\+\+|\+=|--|-=|\|\||\|=|&&|&=|\.\.\.|\.\.|/=)'
122 r'|[/.&|\-+<>!()\[\]{}?,;:$=*%^~]', Punctuation),
123 # Identifier
124 (r'[a-zA-Z_]\w*', Name),
125 # Line
126 (r'(#line)(\s)(.*)(\n)', bygroups(Comment.Special, Whitespace,
127 Comment.Special, Whitespace)),
128 ],
129 'nested_comment': [
130 (r'[^+/]+', Comment.Multiline),
131 (r'/\+', Comment.Multiline, '#push'),
132 (r'\+/', Comment.Multiline, '#pop'),
133 (r'[+/]', Comment.Multiline),
134 ],
135 'token_string': [
136 (r'\{', Punctuation, 'token_string_nest'),
137 (r'\}', String, '#pop'),
138 include('root'),
139 ],
140 'token_string_nest': [
141 (r'\{', Punctuation, '#push'),
142 (r'\}', Punctuation, '#pop'),
143 include('root'),
144 ],
145 'delimited_bracket': [
146 (r'[^\[\]]+', String),
147 (r'\[', String, 'delimited_inside_bracket'),
148 (r'\]"', String, '#pop'),
149 ],
150 'delimited_inside_bracket': [
151 (r'[^\[\]]+', String),
152 (r'\[', String, '#push'),
153 (r'\]', String, '#pop'),
154 ],
155 'delimited_parenthesis': [
156 (r'[^()]+', String),
157 (r'\(', String, 'delimited_inside_parenthesis'),
158 (r'\)"', String, '#pop'),
159 ],
160 'delimited_inside_parenthesis': [
161 (r'[^()]+', String),
162 (r'\(', String, '#push'),
163 (r'\)', String, '#pop'),
164 ],
165 'delimited_angle': [
166 (r'[^<>]+', String),
167 (r'<', String, 'delimited_inside_angle'),
168 (r'>"', String, '#pop'),
169 ],
170 'delimited_inside_angle': [
171 (r'[^<>]+', String),
172 (r'<', String, '#push'),
173 (r'>', String, '#pop'),
174 ],
175 'delimited_curly': [
176 (r'[^{}]+', String),
177 (r'\{', String, 'delimited_inside_curly'),
178 (r'\}"', String, '#pop'),
179 ],
180 'delimited_inside_curly': [
181 (r'[^{}]+', String),
182 (r'\{', String, '#push'),
183 (r'\}', String, '#pop'),
184 ],
185 }
188class CrocLexer(RegexLexer):
189 """
190 For Croc source.
191 """
192 name = 'Croc'
193 url = 'http://jfbillingsley.com/croc'
194 filenames = ['*.croc']
195 aliases = ['croc']
196 mimetypes = ['text/x-crocsrc']
198 tokens = {
199 'root': [
200 (r'\n', Whitespace),
201 (r'\s+', Whitespace),
202 # Comments
203 (r'(//.*?)(\n)', bygroups(Comment.Single, Whitespace)),
204 (r'/\*', Comment.Multiline, 'nestedcomment'),
205 # Keywords
206 (words((
207 'as', 'assert', 'break', 'case', 'catch', 'class', 'continue',
208 'default', 'do', 'else', 'finally', 'for', 'foreach', 'function',
209 'global', 'namespace', 'if', 'import', 'in', 'is', 'local',
210 'module', 'return', 'scope', 'super', 'switch', 'this', 'throw',
211 'try', 'vararg', 'while', 'with', 'yield'), suffix=r'\b'),
212 Keyword),
213 (r'(false|true|null)\b', Keyword.Constant),
214 # FloatLiteral
215 (r'([0-9][0-9_]*)(?=[.eE])(\.[0-9][0-9_]*)?([eE][+\-]?[0-9_]+)?',
216 Number.Float),
217 # IntegerLiteral
218 # -- Binary
219 (r'0[bB][01][01_]*', Number.Bin),
220 # -- Hexadecimal
221 (r'0[xX][0-9a-fA-F][0-9a-fA-F_]*', Number.Hex),
222 # -- Decimal
223 (r'([0-9][0-9_]*)(?![.eE])', Number.Integer),
224 # CharacterLiteral
225 (r"""'(\\['"\\nrt]|\\x[0-9a-fA-F]{2}|\\[0-9]{1,3}"""
226 r"""|\\u[0-9a-fA-F]{4}|\\U[0-9a-fA-F]{8}|.)'""",
227 String.Char),
228 # StringLiteral
229 # -- WysiwygString
230 (r'@"(""|[^"])*"', String),
231 (r'@`(``|[^`])*`', String),
232 (r"@'(''|[^'])*'", String),
233 # -- DoubleQuotedString
234 (r'"(\\\\|\\[^\\]|[^"\\])*"', String),
235 # Tokens
236 (r'(~=|\^=|%=|\*=|==|!=|>>>=|>>>|>>=|>>|>=|<=>|\?=|-\>'
237 r'|<<=|<<|<=|\+\+|\+=|--|-=|\|\||\|=|&&|&=|\.\.|/=)'
238 r'|[-/.&$@|\+<>!()\[\]{}?,;:=*%^~#\\]', Punctuation),
239 # Identifier
240 (r'[a-zA-Z_]\w*', Name),
241 ],
242 'nestedcomment': [
243 (r'[^*/]+', Comment.Multiline),
244 (r'/\*', Comment.Multiline, '#push'),
245 (r'\*/', Comment.Multiline, '#pop'),
246 (r'[*/]', Comment.Multiline),
247 ],
248 }
251class MiniDLexer(CrocLexer):
252 """
253 For MiniD source. MiniD is now known as Croc.
254 """
255 name = 'MiniD'
256 filenames = [] # don't lex .md as MiniD, reserve for Markdown
257 aliases = ['minid']
258 mimetypes = ['text/x-minidsrc']