ThirdParty/Pygments/pygments/lexers/compiled.py

changeset 2426
da76c71624de
parent 1705
b0fbc9300f2b
child 2525
8b507a9a2d40
equal deleted inserted replaced
2425:ace8a08028f3 2426:da76c71624de
3 pygments.lexers.compiled 3 pygments.lexers.compiled
4 ~~~~~~~~~~~~~~~~~~~~~~~~ 4 ~~~~~~~~~~~~~~~~~~~~~~~~
5 5
6 Lexers for compiled languages. 6 Lexers for compiled 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 11
12 import re 12 import re
13 from string import Template 13 from string import Template
14 14
15 from pygments.lexer import Lexer, RegexLexer, include, bygroups, using, \ 15 from pygments.lexer import Lexer, RegexLexer, include, bygroups, using, \
16 this, combined 16 this, combined, inherit, do_insertions
17 from pygments.util import get_bool_opt, get_list_opt 17 from pygments.util import get_bool_opt, get_list_opt
18 from pygments.token import Text, Comment, Operator, Keyword, Name, String, \ 18 from pygments.token import Text, Comment, Operator, Keyword, Name, String, \
19 Number, Punctuation, Error, Literal 19 Number, Punctuation, Error, Literal, Generic
20 from pygments.scanner import Scanner 20 from pygments.scanner import Scanner
21 21
22 # backwards compatibility 22 # backwards compatibility
23 from pygments.lexers.functional import OcamlLexer 23 from pygments.lexers.functional import OcamlLexer
24 from pygments.lexers.jvm import JavaLexer, ScalaLexer 24 from pygments.lexers.jvm import JavaLexer, ScalaLexer
25 25
26 __all__ = ['CLexer', 'CppLexer', 'DLexer', 'DelphiLexer', 'ECLexer', 26 __all__ = ['CLexer', 'CppLexer', 'DLexer', 'DelphiLexer', 'ECLexer', 'DylanLexer',
27 'DylanLexer', 'ObjectiveCLexer', 'FortranLexer', 'GLShaderLexer', 27 'ObjectiveCLexer', 'ObjectiveCppLexer', 'FortranLexer', 'GLShaderLexer',
28 'PrologLexer', 'CythonLexer', 'ValaLexer', 'OocLexer', 'GoLexer', 28 'PrologLexer', 'CythonLexer', 'ValaLexer', 'OocLexer', 'GoLexer',
29 'FelixLexer', 'AdaLexer', 'Modula2Lexer', 'BlitzMaxLexer', 29 'FelixLexer', 'AdaLexer', 'Modula2Lexer', 'BlitzMaxLexer',
30 'NimrodLexer', 'FantomLexer'] 30 'NimrodLexer', 'FantomLexer', 'RustLexer', 'CudaLexer', 'MonkeyLexer',
31 31 'DylanLidLexer', 'DylanConsoleLexer', 'CobolLexer',
32 32 'CobolFreeformatLexer', 'LogosLexer']
33 class CLexer(RegexLexer): 33
34 """ 34
35 For C source code with preprocessor directives. 35 class CFamilyLexer(RegexLexer):
36 """ 36 """
37 name = 'C' 37 For C family source code. This is used as a base class to avoid repetitious
38 aliases = ['c'] 38 definitions.
39 filenames = ['*.c', '*.h', '*.idc'] 39 """
40 mimetypes = ['text/x-chdr', 'text/x-csrc']
41 40
42 #: optional Comment or Whitespace 41 #: optional Comment or Whitespace
43 _ws = r'(?:\s|//.*?\n|/[*].*?[*]/)+' 42 _ws = r'(?:\s|//.*?\n|/[*].*?[*]/)+'
43 #: only one /* */ style comment
44 _ws1 = r':\s*/[*].*?[*]/\s*'
44 45
45 tokens = { 46 tokens = {
46 'whitespace': [ 47 'whitespace': [
47 # preprocessor directives: without whitespace 48 # preprocessor directives: without whitespace
48 ('^#if\s+0', Comment.Preproc, 'if0'), 49 ('^#if\s+0', Comment.Preproc, 'if0'),
49 ('^#', Comment.Preproc, 'macro'), 50 ('^#', Comment.Preproc, 'macro'),
50 # or with whitespace 51 # or with whitespace
51 ('^(' + _ws + r')(#if\s+0)', 52 ('^(' + _ws1 + r')(#if\s+0)',
52 bygroups(using(this), Comment.Preproc), 'if0'), 53 bygroups(using(this), Comment.Preproc), 'if0'),
53 ('^(' + _ws + ')(#)', 54 ('^(' + _ws1 + ')(#)',
54 bygroups(using(this), Comment.Preproc), 'macro'), 55 bygroups(using(this), Comment.Preproc), 'macro'),
55 (r'^(\s*)([a-zA-Z_][a-zA-Z0-9_]*:(?!:))', 56 (r'^(\s*)([a-zA-Z_][a-zA-Z0-9_]*:(?!:))',
56 bygroups(Text, Name.Label)), 57 bygroups(Text, Name.Label)),
57 (r'\n', Text), 58 (r'\n', Text),
58 (r'\s+', Text), 59 (r'\s+', Text),
72 (r'[~!%^&*+=|?:<>/-]', Operator), 73 (r'[~!%^&*+=|?:<>/-]', Operator),
73 (r'[()\[\],.]', Punctuation), 74 (r'[()\[\],.]', Punctuation),
74 (r'\b(case)(.+?)(:)', bygroups(Keyword, using(this), Text)), 75 (r'\b(case)(.+?)(:)', bygroups(Keyword, using(this), Text)),
75 (r'(auto|break|case|const|continue|default|do|else|enum|extern|' 76 (r'(auto|break|case|const|continue|default|do|else|enum|extern|'
76 r'for|goto|if|register|restricted|return|sizeof|static|struct|' 77 r'for|goto|if|register|restricted|return|sizeof|static|struct|'
77 r'switch|typedef|union|volatile|virtual|while)\b', Keyword), 78 r'switch|typedef|union|volatile|while)\b', Keyword),
78 (r'(int|long|float|short|double|char|unsigned|signed|void)\b', 79 (r'(bool|int|long|float|short|double|char|unsigned|signed|void|'
80 r'[a-z_][a-z0-9_]*_t)\b',
79 Keyword.Type), 81 Keyword.Type),
80 (r'(_{0,2}inline|naked|restrict|thread|typename)\b', Keyword.Reserved), 82 (r'(_{0,2}inline|naked|restrict|thread|typename)\b', Keyword.Reserved),
83 # Vector intrinsics
84 (r'(__(m128i|m128d|m128|m64))\b', Keyword.Reserved),
85 # Microsoft-isms
81 (r'__(asm|int8|based|except|int16|stdcall|cdecl|fastcall|int32|' 86 (r'__(asm|int8|based|except|int16|stdcall|cdecl|fastcall|int32|'
82 r'declspec|finally|int64|try|leave)\b', Keyword.Reserved), 87 r'declspec|finally|int64|try|leave|wchar_t|w64|unaligned|'
88 r'raise|noop|identifier|forceinline|assume)\b', Keyword.Reserved),
83 (r'(true|false|NULL)\b', Name.Builtin), 89 (r'(true|false|NULL)\b', Name.Builtin),
84 ('[a-zA-Z_][a-zA-Z0-9_]*', Name), 90 ('[a-zA-Z_][a-zA-Z0-9_]*', Name),
85 ], 91 ],
86 'root': [ 92 'root': [
87 include('whitespace'), 93 include('whitespace'),
88 # functions 94 # functions
89 (r'((?:[a-zA-Z0-9_*\s])+?(?:\s|[*]))' # return arguments 95 (r'((?:[a-zA-Z0-9_*\s])+?(?:\s|[*]))' # return arguments
90 r'([a-zA-Z_][a-zA-Z0-9_]*)' # method name 96 r'([a-zA-Z_][a-zA-Z0-9_]*)' # method name
91 r'(\s*\([^;]*?\))' # signature 97 r'(\s*\([^;]*?\))' # signature
92 r'(' + _ws + r')({)', 98 r'(' + _ws + r')?({)',
93 bygroups(using(this), Name.Function, using(this), using(this), 99 bygroups(using(this), Name.Function, using(this), using(this),
94 Punctuation), 100 Punctuation),
95 'function'), 101 'function'),
96 # function declarations 102 # function declarations
97 (r'((?:[a-zA-Z0-9_*\s])+?(?:\s|[*]))' # return arguments 103 (r'((?:[a-zA-Z0-9_*\s])+?(?:\s|[*]))' # return arguments
98 r'([a-zA-Z_][a-zA-Z0-9_]*)' # method name 104 r'([a-zA-Z_][a-zA-Z0-9_]*)' # method name
99 r'(\s*\([^;]*?\))' # signature 105 r'(\s*\([^;]*?\))' # signature
100 r'(' + _ws + r')(;)', 106 r'(' + _ws + r')?(;)',
101 bygroups(using(this), Name.Function, using(this), using(this), 107 bygroups(using(this), Name.Function, using(this), using(this),
102 Punctuation)), 108 Punctuation)),
103 ('', Text, 'statement'), 109 ('', Text, 'statement'),
104 ], 110 ],
105 'statement' : [ 111 'statement' : [
115 ('{', Punctuation, '#push'), 121 ('{', Punctuation, '#push'),
116 ('}', Punctuation, '#pop'), 122 ('}', Punctuation, '#pop'),
117 ], 123 ],
118 'string': [ 124 'string': [
119 (r'"', String, '#pop'), 125 (r'"', String, '#pop'),
120 (r'\\([\\abfnrtv"\']|x[a-fA-F0-9]{2,4}|[0-7]{1,3})', String.Escape), 126 (r'\\([\\abfnrtv"\']|x[a-fA-F0-9]{2,4}|'
127 r'u[a-fA-F0-9]{4}|U[a-fA-F0-9]{8}|[0-7]{1,3})', String.Escape),
121 (r'[^\\"\n]+', String), # all other characters 128 (r'[^\\"\n]+', String), # all other characters
122 (r'\\\n', String), # line continuation 129 (r'\\\n', String), # line continuation
123 (r'\\', String), # stray backslash 130 (r'\\', String), # stray backslash
124 ], 131 ],
125 'macro': [ 132 'macro': [
137 (r'.*?\n', Comment), 144 (r'.*?\n', Comment),
138 ] 145 ]
139 } 146 }
140 147
141 stdlib_types = ['size_t', 'ssize_t', 'off_t', 'wchar_t', 'ptrdiff_t', 148 stdlib_types = ['size_t', 'ssize_t', 'off_t', 'wchar_t', 'ptrdiff_t',
142 'sig_atomic_t', 'fpos_t', 'clock_t', 'time_t', 'va_list', 149 'sig_atomic_t', 'fpos_t', 'clock_t', 'time_t', 'va_list',
143 'jmp_buf', 'FILE', 'DIR', 'div_t', 'ldiv_t', 'mbstate_t', 150 'jmp_buf', 'FILE', 'DIR', 'div_t', 'ldiv_t', 'mbstate_t',
144 'wctrans_t', 'wint_t', 'wctype_t'] 151 'wctrans_t', 'wint_t', 'wctype_t']
145 c99_types = ['_Bool', '_Complex', 'int8_t', 'int16_t', 'int32_t', 'int64_t', 152 c99_types = ['_Bool', '_Complex', 'int8_t', 'int16_t', 'int32_t', 'int64_t',
146 'uint8_t', 'uint16_t', 'uint32_t', 'uint64_t', 'int_least8_t', 153 'uint8_t', 'uint16_t', 'uint32_t', 'uint64_t', 'int_least8_t',
147 'int_least16_t', 'int_least32_t', 'int_least64_t', 154 'int_least16_t', 'int_least32_t', 'int_least64_t',
148 'uint_least8_t', 'uint_least16_t', 'uint_least32_t', 155 'uint_least8_t', 'uint_least16_t', 'uint_least32_t',
149 'uint_least64_t', 'int_fast8_t', 'int_fast16_t', 'int_fast32_t', 156 'uint_least64_t', 'int_fast8_t', 'int_fast16_t', 'int_fast32_t',
150 'int_fast64_t', 'uint_fast8_t', 'uint_fast16_t', 'uint_fast32_t', 157 'int_fast64_t', 'uint_fast8_t', 'uint_fast16_t', 'uint_fast32_t',
151 'uint_fast64_t', 'intptr_t', 'uintptr_t', 'intmax_t', 'uintmax_t'] 158 'uint_fast64_t', 'intptr_t', 'uintptr_t', 'intmax_t',
159 'uintmax_t']
152 160
153 def __init__(self, **options): 161 def __init__(self, **options):
154 self.stdlibhighlighting = get_bool_opt(options, 162 self.stdlibhighlighting = get_bool_opt(options,
155 'stdlibhighlighting', True) 163 'stdlibhighlighting', True)
156 self.c99highlighting = get_bool_opt(options, 164 self.c99highlighting = get_bool_opt(options,
165 token = Keyword.Type 173 token = Keyword.Type
166 elif self.c99highlighting and value in self.c99_types: 174 elif self.c99highlighting and value in self.c99_types:
167 token = Keyword.Type 175 token = Keyword.Type
168 yield index, token, value 176 yield index, token, value
169 177
170 class CppLexer(RegexLexer): 178
179 class CLexer(CFamilyLexer):
180 """
181 For C source code with preprocessor directives.
182 """
183 name = 'C'
184 aliases = ['c']
185 filenames = ['*.c', '*.h', '*.idc']
186 mimetypes = ['text/x-chdr', 'text/x-csrc']
187 priority = 0.1
188
189 def analyse_text(text):
190 return 0.1
191
192
193 class CppLexer(CFamilyLexer):
171 """ 194 """
172 For C++ source code with preprocessor directives. 195 For C++ source code with preprocessor directives.
173 """ 196 """
174 name = 'C++' 197 name = 'C++'
175 aliases = ['cpp', 'c++'] 198 aliases = ['cpp', 'c++']
176 filenames = ['*.cpp', '*.hpp', '*.c++', '*.h++', 199 filenames = ['*.cpp', '*.hpp', '*.c++', '*.h++',
177 '*.cc', '*.hh', '*.cxx', '*.hxx'] 200 '*.cc', '*.hh', '*.cxx', '*.hxx',
201 '*.C', '*.H', '*.cp', '*.CPP']
178 mimetypes = ['text/x-c++hdr', 'text/x-c++src'] 202 mimetypes = ['text/x-c++hdr', 'text/x-c++src']
179 203 priority = 0.1
180 #: optional Comment or Whitespace
181 _ws = r'(?:\s|//.*?\n|/[*].*?[*]/)+'
182 204
183 tokens = { 205 tokens = {
206 'statements': [
207 (r'(asm|catch|const_cast|delete|dynamic_cast|explicit|'
208 r'export|friend|mutable|namespace|new|operator|'
209 r'private|protected|public|reinterpret_cast|'
210 r'restrict|static_cast|template|this|throw|throws|'
211 r'typeid|typename|using|virtual)\b', Keyword),
212 (r'(class)(\s+)', bygroups(Keyword, Text), 'classname'),
213 inherit,
214 ],
184 'root': [ 215 'root': [
185 # preprocessor directives: without whitespace 216 inherit,
186 ('^#if\s+0', Comment.Preproc, 'if0'), 217 # C++ Microsoft-isms
187 ('^#', Comment.Preproc, 'macro'), 218 (r'__(virtual_inheritance|uuidof|super|single_inheritance|'
188 # or with whitespace 219 r'multiple_inheritance|interface|event)\b', Keyword.Reserved),
189 ('^(' + _ws + r')(#if\s+0)',
190 bygroups(using(this), Comment.Preproc), 'if0'),
191 ('^(' + _ws + ')(#)',
192 bygroups(using(this), Comment.Preproc), 'macro'),
193 (r'\n', Text),
194 (r'\s+', Text),
195 (r'\\\n', Text), # line continuation
196 (r'/(\\\n)?/(\n|(.|\n)*?[^\\]\n)', Comment.Single),
197 (r'/(\\\n)?[*](.|\n)*?[*](\\\n)?/', Comment.Multiline),
198 (r'[{}]', Punctuation),
199 (r'L?"', String, 'string'),
200 (r"L?'(\\.|\\[0-7]{1,3}|\\x[a-fA-F0-9]{1,2}|[^\\\'\n])'", String.Char),
201 (r'(\d+\.\d*|\.\d+|\d+)[eE][+-]?\d+[LlUu]*', Number.Float),
202 (r'(\d+\.\d*|\.\d+|\d+[fF])[fF]?', Number.Float),
203 (r'0x[0-9a-fA-F]+[LlUu]*', Number.Hex),
204 (r'0[0-7]+[LlUu]*', Number.Oct),
205 (r'\d+[LlUu]*', Number.Integer),
206 (r'\*/', Error),
207 (r'[~!%^&*+=|?:<>/-]', Operator),
208 (r'[()\[\],.;]', Punctuation),
209 (r'(asm|auto|break|case|catch|const|const_cast|continue|'
210 r'default|delete|do|dynamic_cast|else|enum|explicit|export|'
211 r'extern|for|friend|goto|if|mutable|namespace|new|operator|'
212 r'private|protected|public|register|reinterpret_cast|return|'
213 r'restrict|sizeof|static|static_cast|struct|switch|template|'
214 r'this|throw|throws|try|typedef|typeid|typename|union|using|'
215 r'volatile|virtual|while)\b', Keyword),
216 (r'(class)(\s+)', bygroups(Keyword, Text), 'classname'),
217 (r'(bool|int|long|float|short|double|char|unsigned|signed|'
218 r'void|wchar_t)\b', Keyword.Type),
219 (r'(_{0,2}inline|naked|thread)\b', Keyword.Reserved),
220 (r'__(asm|int8|based|except|int16|stdcall|cdecl|fastcall|int32|'
221 r'declspec|finally|int64|try|leave|wchar_t|w64|virtual_inheritance|'
222 r'uuidof|unaligned|super|single_inheritance|raise|noop|'
223 r'multiple_inheritance|m128i|m128d|m128|m64|interface|'
224 r'identifier|forceinline|event|assume)\b', Keyword.Reserved),
225 # Offload C++ extensions, http://offload.codeplay.com/ 220 # Offload C++ extensions, http://offload.codeplay.com/
226 (r'(__offload|__blockingoffload|__outer)\b', Keyword.Pseudo), 221 (r'(__offload|__blockingoffload|__outer)\b', Keyword.Pseudo),
227 (r'(true|false)\b', Keyword.Constant),
228 (r'NULL\b', Name.Builtin),
229 ('[a-zA-Z_][a-zA-Z0-9_]*:(?!:)', Name.Label),
230 ('[a-zA-Z_][a-zA-Z0-9_]*', Name),
231 ], 222 ],
232 'classname': [ 223 'classname': [
233 (r'[a-zA-Z_][a-zA-Z0-9_]*', Name.Class, '#pop'), 224 (r'[a-zA-Z_][a-zA-Z0-9_]*', Name.Class, '#pop'),
234 # template specification 225 # template specification
235 (r'\s*(?=>)', Text, '#pop'), 226 (r'\s*(?=>)', Text, '#pop'),
236 ], 227 ],
237 'string': [
238 (r'"', String, '#pop'),
239 (r'\\([\\abfnrtv"\']|x[a-fA-F0-9]{2,4}|[0-7]{1,3})', String.Escape),
240 (r'[^\\"\n]+', String), # all other characters
241 (r'\\\n', String), # line continuation
242 (r'\\', String), # stray backslash
243 ],
244 'macro': [
245 (r'[^/\n]+', Comment.Preproc),
246 (r'/[*](.|\n)*?[*]/', Comment.Multiline),
247 (r'//.*?\n', Comment.Single, '#pop'),
248 (r'/', Comment.Preproc),
249 (r'(?<=\\)\n', Comment.Preproc),
250 (r'\n', Comment.Preproc, '#pop'),
251 ],
252 'if0': [
253 (r'^\s*#if.*?(?<!\\)\n', Comment.Preproc, '#push'),
254 (r'^\s*#endif.*?(?<!\\)\n', Comment.Preproc, '#pop'),
255 (r'.*?\n', Comment),
256 ]
257 } 228 }
258 229
259 230 def analyse_text(text):
260 class ECLexer(RegexLexer): 231 return 0.1
232
233
234 class ECLexer(CLexer):
261 """ 235 """
262 For eC source code with preprocessor directives. 236 For eC source code with preprocessor directives.
263 237
264 *New in Pygments 1.5.* 238 *New in Pygments 1.5.*
265 """ 239 """
266 name = 'eC' 240 name = 'eC'
267 aliases = ['ec'] 241 aliases = ['ec']
268 filenames = ['*.ec', '*.eh'] 242 filenames = ['*.ec', '*.eh']
269 mimetypes = ['text/x-echdr', 'text/x-ecsrc'] 243 mimetypes = ['text/x-echdr', 'text/x-ecsrc']
270 244
271 #: optional Comment or Whitespace
272 _ws = r'(?:\s|//.*?\n|/[*].*?[*]/)+'
273
274 tokens = { 245 tokens = {
275 'whitespace': [
276 # preprocessor directives: without whitespace
277 ('^#if\s+0', Comment.Preproc, 'if0'),
278 ('^#', Comment.Preproc, 'macro'),
279 # or with whitespace
280 ('^' + _ws + r'#if\s+0', Comment.Preproc, 'if0'),
281 ('^' + _ws + '#', Comment.Preproc, 'macro'),
282 (r'^(\s*)([a-zA-Z_][a-zA-Z0-9_]*:(?!:))', bygroups(Text, Name.Label)),
283 (r'\n', Text),
284 (r'\s+', Text),
285 (r'\\\n', Text), # line continuation
286 (r'//(\n|(.|\n)*?[^\\]\n)', Comment.Single),
287 (r'/(\\\n)?[*](.|\n)*?[*](\\\n)?/', Comment.Multiline),
288 ],
289 'statements': [ 246 'statements': [
290 (r'L?"', String, 'string'), 247 (r'(virtual|class|private|public|property|import|delete|new|new0|'
291 (r"L?'(\\.|\\[0-7]{1,3}|\\x[a-fA-F0-9]{1,2}|[^\\\'\n])'", String.Char), 248 r'renew|renew0|define|get|set|remote|dllexport|dllimport|stdcall|'
292 (r'(\d+\.\d*|\.\d+|\d+)[eE][+-]?\d+[LlUu]*', Number.Float), 249 r'subclass|__on_register_module|namespace|using|typed_object|'
293 (r'(\d+\.\d*|\.\d+|\d+[fF])[fF]?', Number.Float), 250 r'any_object|incref|register|watch|stopwatching|firewatchers|'
294 (r'0x[0-9a-fA-F]+[LlUu]*', Number.Hex), 251 r'watchable|class_designer|class_fixed|class_no_expansion|isset|'
295 (r'0[0-7]+[LlUu]*', Number.Oct), 252 r'class_default_property|property_category|class_data|'
296 (r'\d+[LlUu]*', Number.Integer), 253 r'class_property|virtual|thisclass|'
297 (r'\*/', Error),
298 (r'[~!%^&*+=|?:<>/-]', Operator),
299 (r'[()\[\],.]', Punctuation),
300 (r'\b(case)(.+?)(:)', bygroups(Keyword, using(this), Text)),
301 (r'(auto|break|case|const|continue|default|do|else|enum|extern|'
302 r'for|goto|if|register|restricted|return|sizeof|static|struct|'
303 r'switch|typedef|union|volatile|virtual|while|class|private|public|'
304 r'property|import|delete|new|new0|renew|renew0|define|get|set|remote|dllexport|dllimport|stdcall|'
305 r'subclass|__on_register_module|namespace|using|typed_object|any_object|incref|register|watch|'
306 r'stopwatching|firewatchers|watchable|class_designer|class_fixed|class_no_expansion|isset|'
307 r'class_default_property|property_category|class_data|class_property|virtual|thisclass|'
308 r'dbtable|dbindex|database_open|dbfield)\b', Keyword), 254 r'dbtable|dbindex|database_open|dbfield)\b', Keyword),
309 (r'(int|long|float|short|double|char|unsigned|signed|void)\b',
310 Keyword.Type),
311 (r'(uint|uint16|uint32|uint64|bool|byte|unichar|int64)\b', 255 (r'(uint|uint16|uint32|uint64|bool|byte|unichar|int64)\b',
312 Keyword.Type), 256 Keyword.Type),
313 (r'(class)(\s+)', bygroups(Keyword, Text), 'classname'), 257 (r'(class)(\s+)', bygroups(Keyword, Text), 'classname'),
314 (r'(_{0,2}inline|naked|restrict|thread|typename)\b', Keyword.Reserved), 258 (r'(null|value|this)\b', Name.Builtin),
315 (r'__(asm|int8|based|except|int16|stdcall|cdecl|fastcall|int32|' 259 inherit,
316 r'declspec|finally|int64|try|leave)\b', Keyword.Reserved),
317 (r'(true|false|null|value|this|NULL)\b', Name.Builtin),
318 ('[a-zA-Z_][a-zA-Z0-9_]*', Name),
319 ],
320 'root': [
321 include('whitespace'),
322 # functions
323 (r'((?:[a-zA-Z0-9_*\s])+?(?:\s|[*]))' # return arguments
324 r'([a-zA-Z_][a-zA-Z0-9_]*)' # method name
325 r'(\s*\([^;]*?\))' # signature
326 r'(' + _ws + r')({)',
327 bygroups(using(this), Name.Function, using(this), using(this),
328 Punctuation),
329 'function'),
330 # function declarations
331 (r'((?:[a-zA-Z0-9_*\s])+?(?:\s|[*]))' # return arguments
332 r'([a-zA-Z_][a-zA-Z0-9_]*)' # method name
333 r'(\s*\([^;]*?\))' # signature
334 r'(' + _ws + r')(;)',
335 bygroups(using(this), Name.Function, using(this), using(this),
336 Punctuation)),
337 ('', Text, 'statement'),
338 ], 260 ],
339 'classname': [ 261 'classname': [
340 (r'[a-zA-Z_][a-zA-Z0-9_]*', Name.Class, '#pop'), 262 (r'[a-zA-Z_][a-zA-Z0-9_]*', Name.Class, '#pop'),
341 # template specification 263 # template specification
342 (r'\s*(?=>)', Text, '#pop'), 264 (r'\s*(?=>)', Text, '#pop'),
343 ], 265 ],
344 'statement' : [
345 include('whitespace'),
346 include('statements'),
347 ('[{}]', Punctuation),
348 (';', Punctuation, '#pop'),
349 ],
350 'function': [
351 include('whitespace'),
352 include('statements'),
353 (';', Punctuation),
354 ('{', Punctuation, '#push'),
355 ('}', Punctuation, '#pop'),
356 ],
357 'string': [
358 (r'"', String, '#pop'),
359 (r'\\([\\abfnrtv"\']|x[a-fA-F0-9]{2,4}|[0-7]{1,3})', String.Escape),
360 (r'[^\\"\n]+', String), # all other characters
361 (r'\\\n', String), # line continuation
362 (r'\\', String), # stray backslash
363 ],
364 'macro': [
365 (r'[^/\n]+', Comment.Preproc),
366 (r'/[*](.|\n)*?[*]/', Comment.Multiline),
367 (r'//.*?\n', Comment.Single, '#pop'),
368 (r'/', Comment.Preproc),
369 (r'(?<=\\)\n', Comment.Preproc),
370 (r'\n', Comment.Preproc, '#pop'),
371 ],
372 'if0': [
373 (r'^\s*#if.*?(?<!\\)\n', Comment.Preproc, '#push'),
374 (r'^\s*#el(?:se|if).*\n', Comment.Preproc, '#pop'),
375 (r'^\s*#endif.*?(?<!\\)\n', Comment.Preproc, '#pop'),
376 (r'.*?\n', Comment),
377 ]
378 } 266 }
379
380 stdlib_types = ['size_t', 'ssize_t', 'off_t', 'wchar_t', 'ptrdiff_t',
381 'sig_atomic_t', 'fpos_t', 'clock_t', 'time_t', 'va_list',
382 'jmp_buf', 'FILE', 'DIR', 'div_t', 'ldiv_t', 'mbstate_t',
383 'wctrans_t', 'wint_t', 'wctype_t']
384 c99_types = ['_Bool', '_Complex', 'int8_t', 'int16_t', 'int32_t', 'int64_t',
385 'uint8_t', 'uint16_t', 'uint32_t', 'uint64_t', 'int_least8_t',
386 'int_least16_t', 'int_least32_t', 'int_least64_t',
387 'uint_least8_t', 'uint_least16_t', 'uint_least32_t',
388 'uint_least64_t', 'int_fast8_t', 'int_fast16_t', 'int_fast32_t',
389 'int_fast64_t', 'uint_fast8_t', 'uint_fast16_t', 'uint_fast32_t',
390 'uint_fast64_t', 'intptr_t', 'uintptr_t', 'intmax_t', 'uintmax_t']
391
392 def __init__(self, **options):
393 self.stdlibhighlighting = get_bool_opt(options,
394 'stdlibhighlighting', True)
395 self.c99highlighting = get_bool_opt(options,
396 'c99highlighting', True)
397 RegexLexer.__init__(self, **options)
398
399 def get_tokens_unprocessed(self, text):
400 for index, token, value in \
401 RegexLexer.get_tokens_unprocessed(self, text):
402 if token is Name:
403 if self.stdlibhighlighting and value in self.stdlib_types:
404 token = Keyword.Type
405 elif self.c99highlighting and value in self.c99_types:
406 token = Keyword.Type
407 yield index, token, value
408 267
409 268
410 class DLexer(RegexLexer): 269 class DLexer(RegexLexer):
411 """ 270 """
412 For D source. 271 For D source.
1048 *New in Pygments 0.7.* 907 *New in Pygments 0.7.*
1049 """ 908 """
1050 909
1051 name = 'Dylan' 910 name = 'Dylan'
1052 aliases = ['dylan'] 911 aliases = ['dylan']
1053 filenames = ['*.dylan', '*.dyl'] 912 filenames = ['*.dylan', '*.dyl', '*.intr']
1054 mimetypes = ['text/x-dylan'] 913 mimetypes = ['text/x-dylan']
1055 914
1056 flags = re.DOTALL 915 flags = re.IGNORECASE
916
917 builtins = set([
918 'subclass', 'abstract', 'block', 'concrete', 'constant', 'class',
919 'compiler-open', 'compiler-sideways', 'domain', 'dynamic',
920 'each-subclass', 'exception', 'exclude', 'function', 'generic',
921 'handler', 'inherited', 'inline', 'inline-only', 'instance',
922 'interface', 'import', 'keyword', 'library', 'macro', 'method',
923 'module', 'open', 'primary', 'required', 'sealed', 'sideways',
924 'singleton', 'slot', 'thread', 'variable', 'virtual'])
925
926 keywords = set([
927 'above', 'afterwards', 'begin', 'below', 'by', 'case', 'cleanup',
928 'create', 'define', 'else', 'elseif', 'end', 'export', 'finally',
929 'for', 'from', 'if', 'in', 'let', 'local', 'otherwise', 'rename',
930 'select', 'signal', 'then', 'to', 'unless', 'until', 'use', 'when',
931 'while'])
932
933 operators = set([
934 '~', '+', '-', '*', '|', '^', '=', '==', '~=', '~==', '<', '<=',
935 '>', '>=', '&', '|'])
936
937 functions = set([
938 'abort', 'abs', 'add', 'add!', 'add-method', 'add-new', 'add-new!',
939 'all-superclasses', 'always', 'any?', 'applicable-method?', 'apply',
940 'aref', 'aref-setter', 'as', 'as-lowercase', 'as-lowercase!',
941 'as-uppercase', 'as-uppercase!', 'ash', 'backward-iteration-protocol',
942 'break', 'ceiling', 'ceiling/', 'cerror', 'check-type', 'choose',
943 'choose-by', 'complement', 'compose', 'concatenate', 'concatenate-as',
944 'condition-format-arguments', 'condition-format-string', 'conjoin',
945 'copy-sequence', 'curry', 'default-handler', 'dimension', 'dimensions',
946 'direct-subclasses', 'direct-superclasses', 'disjoin', 'do',
947 'do-handlers', 'element', 'element-setter', 'empty?', 'error', 'even?',
948 'every?', 'false-or', 'fill!', 'find-key', 'find-method', 'first',
949 'first-setter', 'floor', 'floor/', 'forward-iteration-protocol',
950 'function-arguments', 'function-return-values',
951 'function-specializers', 'gcd', 'generic-function-mandatory-keywords',
952 'generic-function-methods', 'head', 'head-setter', 'identity',
953 'initialize', 'instance?', 'integral?', 'intersection',
954 'key-sequence', 'key-test', 'last', 'last-setter', 'lcm', 'limited',
955 'list', 'logand', 'logbit?', 'logior', 'lognot', 'logxor', 'make',
956 'map', 'map-as', 'map-into', 'max', 'member?', 'merge-hash-codes',
957 'min', 'modulo', 'negative', 'negative?', 'next-method',
958 'object-class', 'object-hash', 'odd?', 'one-of', 'pair', 'pop',
959 'pop-last', 'positive?', 'push', 'push-last', 'range', 'rank',
960 'rcurry', 'reduce', 'reduce1', 'remainder', 'remove', 'remove!',
961 'remove-duplicates', 'remove-duplicates!', 'remove-key!',
962 'remove-method', 'replace-elements!', 'replace-subsequence!',
963 'restart-query', 'return-allowed?', 'return-description',
964 'return-query', 'reverse', 'reverse!', 'round', 'round/',
965 'row-major-index', 'second', 'second-setter', 'shallow-copy',
966 'signal', 'singleton', 'size', 'size-setter', 'slot-initialized?',
967 'sort', 'sort!', 'sorted-applicable-methods', 'subsequence-position',
968 'subtype?', 'table-protocol', 'tail', 'tail-setter', 'third',
969 'third-setter', 'truncate', 'truncate/', 'type-error-expected-type',
970 'type-error-value', 'type-for-copy', 'type-union', 'union', 'values',
971 'vector', 'zero?'])
972
973 valid_name = '\\\\?[a-zA-Z0-9' + re.escape('!&*<>|^$%@_-+~?/=') + ']+'
974
975 def get_tokens_unprocessed(self, text):
976 for index, token, value in RegexLexer.get_tokens_unprocessed(self, text):
977 if token is Name:
978 lowercase_value = value.lower()
979 if lowercase_value in self.builtins:
980 yield index, Name.Builtin, value
981 continue
982 if lowercase_value in self.keywords:
983 yield index, Keyword, value
984 continue
985 if lowercase_value in self.functions:
986 yield index, Name.Builtin, value
987 continue
988 if lowercase_value in self.operators:
989 yield index, Operator, value
990 continue
991 yield index, token, value
1057 992
1058 tokens = { 993 tokens = {
1059 'root': [ 994 'root': [
1060 (r'\b(subclass|abstract|block|c(on(crete|stant)|lass)|domain' 995 # Whitespace
1061 r'|ex(c(eption|lude)|port)|f(unction(al)?)|generic|handler' 996 (r'\s+', Text),
1062 r'|i(n(herited|line|stance|terface)|mport)|library|m(acro|ethod)' 997
1063 r'|open|primary|sealed|si(deways|ngleton)|slot' 998 # single line comment
1064 r'|v(ariable|irtual))\b', Name.Builtin),
1065 (r'<\w+>', Keyword.Type),
1066 (r'//.*?\n', Comment.Single), 999 (r'//.*?\n', Comment.Single),
1067 (r'/\*[\w\W]*?\*/', Comment.Multiline), 1000
1001 # lid header
1002 (r'([A-Za-z0-9-]+)(:)([ \t]*)(.*(?:\n[ \t].+)*)',
1003 bygroups(Name.Attribute, Operator, Text, String)),
1004
1005 ('', Text, 'code') # no header match, switch to code
1006 ],
1007 'code': [
1008 # Whitespace
1009 (r'\s+', Text),
1010
1011 # single line comment
1012 (r'//.*?\n', Comment.Single),
1013
1014 # multi-line comment
1015 (r'/\*', Comment.Multiline, 'comment'),
1016
1017 # strings and characters
1068 (r'"', String, 'string'), 1018 (r'"', String, 'string'),
1069 (r"'(\\.|\\[0-7]{1,3}|\\x[a-fA-F0-9]{1,2}|[^\\\'\n])'", String.Char), 1019 (r"'(\\.|\\[0-7]{1,3}|\\x[a-fA-F0-9]{1,2}|[^\\\'\n])'", String.Char),
1070 (r'=>|\b(a(bove|fterwards)|b(e(gin|low)|y)|c(ase|leanup|reate)' 1020
1071 r'|define|else(if)?|end|f(inally|or|rom)|i[fn]|l(et|ocal)|otherwise' 1021 # binary integer
1072 r'|rename|s(elect|ignal)|t(hen|o)|u(n(less|til)|se)|wh(en|ile))\b', 1022 (r'#[bB][01]+', Number),
1073 Keyword), 1023
1074 (r'([ \t])([!\$%&\*\/:<=>\?~_^a-zA-Z0-9.+\-]*:)', 1024 # octal integer
1075 bygroups(Text, Name.Variable)), 1025 (r'#[oO][0-7]+', Number.Oct),
1076 (r'([ \t]*)(\S+[^:])([ \t]*)(\()([ \t]*)', 1026
1077 bygroups(Text, Name.Function, Text, Punctuation, Text)), 1027 # floating point
1078 (r'-?[0-9.]+', Number), 1028 (r'[-+]?(\d*\.\d+(e[-+]?\d+)?|\d+(\.\d*)?e[-+]?\d+)', Number.Float),
1079 (r'[(),;]', Punctuation), 1029
1080 (r'\$[a-zA-Z0-9-]+', Name.Constant), 1030 # decimal integer
1081 (r'[!$%&*/:<>=?~^.+\[\]{}-]+', Operator), 1031 (r'[-+]?\d+', Number.Integer),
1082 (r'\s+', Text), 1032
1083 (r'#"[a-zA-Z0-9-]+"', Keyword), 1033 # hex integer
1034 (r'#[xX][0-9a-fA-F]+', Number.Hex),
1035
1036 # Macro parameters
1037 (r'(\?' + valid_name + ')(:)'
1038 r'(token|name|variable|expression|body|case-body|\*)',
1039 bygroups(Name.Tag, Operator, Name.Builtin)),
1040 (r'(\?)(:)(token|name|variable|expression|body|case-body|\*)',
1041 bygroups(Name.Tag, Operator, Name.Builtin)),
1042 (r'\?' + valid_name, Name.Tag),
1043
1044 # Punctuation
1045 (r'(=>|::|#\(|#\[|##|\?|\?\?|\?=|[(){}\[\],\.;])', Punctuation),
1046
1047 # Most operators are picked up as names and then re-flagged.
1048 # This one isn't valid in a name though, so we pick it up now.
1049 (r':=', Operator),
1050
1051 # Pick up #t / #f before we match other stuff with #.
1052 (r'#[tf]', Literal),
1053
1054 # #"foo" style keywords
1055 (r'#"', String.Symbol, 'keyword'),
1056
1057 # #rest, #key, #all-keys, etc.
1084 (r'#[a-zA-Z0-9-]+', Keyword), 1058 (r'#[a-zA-Z0-9-]+', Keyword),
1085 (r'#(\(|\[)', Punctuation), 1059
1086 (r'[a-zA-Z0-9-_]+', Name.Variable), 1060 # required-init-keyword: style keywords.
1061 (valid_name + ':', Keyword),
1062
1063 # class names
1064 (r'<' + valid_name + '>', Name.Class),
1065
1066 # define variable forms.
1067 (r'\*' + valid_name + '\*', Name.Variable.Global),
1068
1069 # define constant forms.
1070 (r'\$' + valid_name, Name.Constant),
1071
1072 # everything else. We re-flag some of these in the method above.
1073 (valid_name, Name),
1074 ],
1075 'comment': [
1076 (r'[^*/]', Comment.Multiline),
1077 (r'/\*', Comment.Multiline, '#push'),
1078 (r'\*/', Comment.Multiline, '#pop'),
1079 (r'[*/]', Comment.Multiline)
1080 ],
1081 'keyword': [
1082 (r'"', String.Symbol, '#pop'),
1083 (r'[^\\"]+', String.Symbol), # all other characters
1087 ], 1084 ],
1088 'string': [ 1085 'string': [
1089 (r'"', String, '#pop'), 1086 (r'"', String, '#pop'),
1090 (r'\\([\\abfnrtv"\']|x[a-fA-F0-9]{2,4}|[0-7]{1,3})', String.Escape), 1087 (r'\\([\\abfnrtv"\']|x[a-fA-F0-9]{2,4}|[0-7]{1,3})', String.Escape),
1091 (r'[^\\"\n]+', String), # all other characters 1088 (r'[^\\"\n]+', String), # all other characters
1092 (r'\\\n', String), # line continuation 1089 (r'\\\n', String), # line continuation
1093 (r'\\', String), # stray backslash 1090 (r'\\', String), # stray backslash
1094 ], 1091 ]
1095 } 1092 }
1096 1093
1097 1094
1098 class ObjectiveCLexer(RegexLexer): 1095 class DylanLidLexer(RegexLexer):
1096 """
1097 For Dylan LID (Library Interchange Definition) files.
1098
1099 *New in Pygments 1.6.*
1100 """
1101
1102 name = 'DylanLID'
1103 aliases = ['dylan-lid', 'lid']
1104 filenames = ['*.lid', '*.hdp']
1105 mimetypes = ['text/x-dylan-lid']
1106
1107 flags = re.IGNORECASE
1108
1109 tokens = {
1110 'root': [
1111 # Whitespace
1112 (r'\s+', Text),
1113
1114 # single line comment
1115 (r'//.*?\n', Comment.Single),
1116
1117 # lid header
1118 (r'(.*?)(:)([ \t]*)(.*(?:\n[ \t].+)*)',
1119 bygroups(Name.Attribute, Operator, Text, String)),
1120 ]
1121 }
1122
1123
1124 class DylanConsoleLexer(Lexer):
1125 """
1126 For Dylan interactive console output like:
1127
1128 .. sourcecode:: dylan-console
1129
1130 ? let a = 1;
1131 => 1
1132 ? a
1133 => 1
1134
1135 This is based on a copy of the RubyConsoleLexer.
1136
1137 *New in Pygments 1.6.*
1138 """
1139 name = 'Dylan session'
1140 aliases = ['dylan-console', 'dylan-repl']
1141 filenames = ['*.dylan-console']
1142 mimetypes = ['text/x-dylan-console']
1143
1144 _line_re = re.compile('.*?\n')
1145 _prompt_re = re.compile('\?| ')
1146
1147 def get_tokens_unprocessed(self, text):
1148 dylexer = DylanLexer(**self.options)
1149
1150 curcode = ''
1151 insertions = []
1152 for match in self._line_re.finditer(text):
1153 line = match.group()
1154 m = self._prompt_re.match(line)
1155 if m is not None:
1156 end = m.end()
1157 insertions.append((len(curcode),
1158 [(0, Generic.Prompt, line[:end])]))
1159 curcode += line[end:]
1160 else:
1161 if curcode:
1162 for item in do_insertions(insertions,
1163 dylexer.get_tokens_unprocessed(curcode)):
1164 yield item
1165 curcode = ''
1166 insertions = []
1167 yield match.start(), Generic.Output, line
1168 if curcode:
1169 for item in do_insertions(insertions,
1170 dylexer.get_tokens_unprocessed(curcode)):
1171 yield item
1172
1173
1174 def objective(baselexer):
1175 """
1176 Generate a subclass of baselexer that accepts the Objective-C syntax
1177 extensions.
1178 """
1179
1180 # Have to be careful not to accidentally match JavaDoc/Doxygen syntax here,
1181 # since that's quite common in ordinary C/C++ files. It's OK to match
1182 # JavaDoc/Doxygen keywords that only apply to Objective-C, mind.
1183 #
1184 # The upshot of this is that we CANNOT match @class or @interface
1185 _oc_keywords = re.compile(r'@(?:end|implementation|protocol)')
1186
1187 # Matches [ <ws>? identifier <ws> ( identifier <ws>? ] | identifier? : )
1188 # (note the identifier is *optional* when there is a ':'!)
1189 _oc_message = re.compile(r'\[\s*[a-zA-Z_][a-zA-Z0-9_]*\s+'
1190 r'(?:[a-zA-Z_][a-zA-Z0-9_]*\s*\]|'
1191 r'(?:[a-zA-Z_][a-zA-Z0-9_]*)?:)')
1192
1193 class GeneratedObjectiveCVariant(baselexer):
1194 """
1195 Implements Objective-C syntax on top of an existing C family lexer.
1196 """
1197
1198 tokens = {
1199 'statements': [
1200 (r'@"', String, 'string'),
1201 (r"@'(\\.|\\[0-7]{1,3}|\\x[a-fA-F0-9]{1,2}|[^\\\'\n])'",
1202 String.Char),
1203 (r'@(\d+\.\d*|\.\d+|\d+)[eE][+-]?\d+[lL]?', Number.Float),
1204 (r'@(\d+\.\d*|\.\d+|\d+[fF])[fF]?', Number.Float),
1205 (r'@0x[0-9a-fA-F]+[Ll]?', Number.Hex),
1206 (r'@0[0-7]+[Ll]?', Number.Oct),
1207 (r'@\d+[Ll]?', Number.Integer),
1208 (r'(in|@selector|@private|@protected|@public|@encode|'
1209 r'@synchronized|@try|@throw|@catch|@finally|@end|@property|'
1210 r'@synthesize|@dynamic|@optional)\b', Keyword),
1211 (r'(id|Class|IMP|SEL|BOOL|IBOutlet|IBAction|unichar)\b',
1212 Keyword.Type),
1213 (r'@(true|false|YES|NO)\n', Name.Builtin),
1214 (r'(YES|NO|nil)\b', Name.Builtin),
1215 (r'(@interface|@implementation)(\s+)', bygroups(Keyword, Text),
1216 ('#pop', 'oc_classname')),
1217 (r'(@class|@protocol)(\s+)', bygroups(Keyword, Text),
1218 ('#pop', 'oc_forward_classname')),
1219 inherit,
1220 ],
1221 'oc_classname' : [
1222 # interface definition that inherits
1223 ('([a-zA-Z$_][a-zA-Z0-9$_]*)(\s*:\s*)([a-zA-Z$_][a-zA-Z0-9$_]*)?',
1224 bygroups(Name.Class, Text, Name.Class), '#pop'),
1225 # interface definition for a category
1226 ('([a-zA-Z$_][a-zA-Z0-9$_]*)(\s*)(\([a-zA-Z$_][a-zA-Z0-9$_]*\))',
1227 bygroups(Name.Class, Text, Name.Label), '#pop'),
1228 # simple interface / implementation
1229 ('([a-zA-Z$_][a-zA-Z0-9$_]*)', Name.Class, '#pop')
1230 ],
1231 'oc_forward_classname' : [
1232 ('([a-zA-Z$_][a-zA-Z0-9$_]*)(\s*,\s*)',
1233 bygroups(Name.Class, Text), 'oc_forward_classname'),
1234 ('([a-zA-Z$_][a-zA-Z0-9$_]*)(\s*;?)',
1235 bygroups(Name.Class, Text), '#pop')
1236 ],
1237 'root': [
1238 # methods
1239 (r'^([-+])(\s*)' # method marker
1240 r'(\(.*?\))?(\s*)' # return type
1241 r'([a-zA-Z$_][a-zA-Z0-9$_]*:?)', # begin of method name
1242 bygroups(Keyword, Text, using(this),
1243 Text, Name.Function),
1244 'method'),
1245 inherit,
1246 ],
1247 'method': [
1248 include('whitespace'),
1249 # TODO unsure if ellipses are allowed elsewhere, see
1250 # discussion in Issue 789
1251 (r',', Punctuation),
1252 (r'\.\.\.', Punctuation),
1253 (r'(\(.*?\))([a-zA-Z$_][a-zA-Z0-9$_]*)', bygroups(using(this),
1254 Name.Variable)),
1255 (r'[a-zA-Z$_][a-zA-Z0-9$_]*:', Name.Function),
1256 (';', Punctuation, '#pop'),
1257 ('{', Punctuation, 'function'),
1258 ('', Text, '#pop'),
1259 ],
1260 }
1261
1262 def analyse_text(text):
1263 if _oc_keywords.search(text):
1264 return 1.0
1265 elif '@"' in text: # strings
1266 return 0.8
1267 elif _oc_message.search(text):
1268 return 0.8
1269 return 0
1270
1271 return GeneratedObjectiveCVariant
1272
1273
1274 class ObjectiveCLexer(objective(CLexer)):
1099 """ 1275 """
1100 For Objective-C source code with preprocessor directives. 1276 For Objective-C source code with preprocessor directives.
1101 """ 1277 """
1102 1278
1103 name = 'Objective-C' 1279 name = 'Objective-C'
1104 aliases = ['objective-c', 'objectivec', 'obj-c', 'objc'] 1280 aliases = ['objective-c', 'objectivec', 'obj-c', 'objc']
1105 #XXX: objc has .h files too :-/ 1281 filenames = ['*.m', '*.h']
1106 filenames = ['*.m']
1107 mimetypes = ['text/x-objective-c'] 1282 mimetypes = ['text/x-objective-c']
1108 1283 priority = 0.05 # Lower than C
1109 #: optional Comment or Whitespace 1284
1110 _ws = r'(?:\s|//.*?\n|/[*].*?[*]/)+' 1285
1111 1286 class ObjectiveCppLexer(objective(CppLexer)):
1112 tokens = { 1287 """
1113 'whitespace': [ 1288 For Objective-C++ source code with preprocessor directives.
1114 # preprocessor directives: without whitespace 1289 """
1115 ('^#if\s+0', Comment.Preproc, 'if0'), 1290
1116 ('^#', Comment.Preproc, 'macro'), 1291 name = 'Objective-C++'
1117 # or with whitespace 1292 aliases = ['objective-c++', 'objectivec++', 'obj-c++', 'objc++']
1118 ('^' + _ws + r'#if\s+0', Comment.Preproc, 'if0'), 1293 filenames = ['*.mm', '*.hh']
1119 ('^' + _ws + '#', Comment.Preproc, 'macro'), 1294 mimetypes = ['text/x-objective-c++']
1120 (r'\n', Text), 1295 priority = 0.05 # Lower than C++
1121 (r'\s+', Text),
1122 (r'\\\n', Text), # line continuation
1123 (r'//(\n|(.|\n)*?[^\\]\n)', Comment.Single),
1124 (r'/(\\\n)?[*](.|\n)*?[*](\\\n)?/', Comment.Multiline),
1125 ],
1126 'statements': [
1127 (r'(L|@)?"', String, 'string'),
1128 (r"(L|@)?'(\\.|\\[0-7]{1,3}|\\x[a-fA-F0-9]{1,2}|[^\\\'\n])'",
1129 String.Char),
1130 (r'(\d+\.\d*|\.\d+|\d+)[eE][+-]?\d+[lL]?', Number.Float),
1131 (r'(\d+\.\d*|\.\d+|\d+[fF])[fF]?', Number.Float),
1132 (r'0x[0-9a-fA-F]+[Ll]?', Number.Hex),
1133 (r'0[0-7]+[Ll]?', Number.Oct),
1134 (r'\d+[Ll]?', Number.Integer),
1135 (r'[~!%^&*+=|?:<>/-]', Operator),
1136 (r'[()\[\],.]', Punctuation),
1137 (r'(auto|break|case|const|continue|default|do|else|enum|extern|'
1138 r'for|goto|if|register|restricted|return|sizeof|static|struct|'
1139 r'switch|typedef|union|volatile|virtual|while|in|@selector|'
1140 r'@private|@protected|@public|@encode|'
1141 r'@synchronized|@try|@throw|@catch|@finally|@end|@property|'
1142 r'@synthesize|@dynamic)\b', Keyword),
1143 (r'(int|long|float|short|double|char|unsigned|signed|void|'
1144 r'id|BOOL|IBOutlet|IBAction|SEL)\b', Keyword.Type),
1145 (r'(_{0,2}inline|naked|restrict|thread|typename)\b',
1146 Keyword.Reserved),
1147 (r'__(asm|int8|based|except|int16|stdcall|cdecl|fastcall|int32|'
1148 r'declspec|finally|int64|try|leave)\b', Keyword.Reserved),
1149 (r'(TRUE|FALSE|nil|NULL)\b', Name.Builtin),
1150 ('[a-zA-Z$_][a-zA-Z0-9$_]*:(?!:)', Name.Label),
1151 ('[a-zA-Z$_][a-zA-Z0-9$_]*', Name),
1152 ],
1153 'root': [
1154 include('whitespace'),
1155 # functions
1156 (r'((?:[a-zA-Z0-9_*\s])+?(?:\s|[*]))' # return arguments
1157 r'([a-zA-Z$_][a-zA-Z0-9$_]*)' # method name
1158 r'(\s*\([^;]*?\))' # signature
1159 r'(' + _ws + r')({)',
1160 bygroups(using(this), Name.Function,
1161 using(this), Text, Punctuation),
1162 'function'),
1163 # methods
1164 (r'^([-+])(\s*)' # method marker
1165 r'(\(.*?\))?(\s*)' # return type
1166 r'([a-zA-Z$_][a-zA-Z0-9$_]*:?)', # begin of method name
1167 bygroups(Keyword, Text, using(this),
1168 Text, Name.Function),
1169 'method'),
1170 # function declarations
1171 (r'((?:[a-zA-Z0-9_*\s])+?(?:\s|[*]))' # return arguments
1172 r'([a-zA-Z$_][a-zA-Z0-9$_]*)' # method name
1173 r'(\s*\([^;]*?\))' # signature
1174 r'(' + _ws + r')(;)',
1175 bygroups(using(this), Name.Function,
1176 using(this), Text, Punctuation)),
1177 (r'(@interface|@implementation)(\s+)', bygroups(Keyword, Text),
1178 'classname'),
1179 (r'(@class|@protocol)(\s+)', bygroups(Keyword, Text),
1180 'forward_classname'),
1181 (r'(\s*)(@end)(\s*)', bygroups(Text, Keyword, Text)),
1182 ('', Text, 'statement'),
1183 ],
1184 'classname' : [
1185 # interface definition that inherits
1186 ('([a-zA-Z$_][a-zA-Z0-9$_]*)(\s*:\s*)([a-zA-Z$_][a-zA-Z0-9$_]*)?',
1187 bygroups(Name.Class, Text, Name.Class), '#pop'),
1188 # interface definition for a category
1189 ('([a-zA-Z$_][a-zA-Z0-9$_]*)(\s*)(\([a-zA-Z$_][a-zA-Z0-9$_]*\))',
1190 bygroups(Name.Class, Text, Name.Label), '#pop'),
1191 # simple interface / implementation
1192 ('([a-zA-Z$_][a-zA-Z0-9$_]*)', Name.Class, '#pop')
1193 ],
1194 'forward_classname' : [
1195 ('([a-zA-Z$_][a-zA-Z0-9$_]*)(\s*,\s*)',
1196 bygroups(Name.Class, Text), 'forward_classname'),
1197 ('([a-zA-Z$_][a-zA-Z0-9$_]*)(\s*;?)',
1198 bygroups(Name.Class, Text), '#pop')
1199 ],
1200 'statement' : [
1201 include('whitespace'),
1202 include('statements'),
1203 ('[{}]', Punctuation),
1204 (';', Punctuation, '#pop'),
1205 ],
1206 'function': [
1207 include('whitespace'),
1208 include('statements'),
1209 (';', Punctuation),
1210 ('{', Punctuation, '#push'),
1211 ('}', Punctuation, '#pop'),
1212 ],
1213 'method': [
1214 include('whitespace'),
1215 (r'(\(.*?\))([a-zA-Z$_][a-zA-Z0-9$_]*)', bygroups(using(this),
1216 Name.Variable)),
1217 (r'[a-zA-Z$_][a-zA-Z0-9$_]*:', Name.Function),
1218 (';', Punctuation, '#pop'),
1219 ('{', Punctuation, 'function'),
1220 ('', Text, '#pop'),
1221 ],
1222 'string': [
1223 (r'"', String, '#pop'),
1224 (r'\\([\\abfnrtv"\']|x[a-fA-F0-9]{2,4}|[0-7]{1,3})', String.Escape),
1225 (r'[^\\"\n]+', String), # all other characters
1226 (r'\\\n', String), # line continuation
1227 (r'\\', String), # stray backslash
1228 ],
1229 'macro': [
1230 (r'[^/\n]+', Comment.Preproc),
1231 (r'/[*](.|\n)*?[*]/', Comment.Multiline),
1232 (r'//.*?\n', Comment.Single, '#pop'),
1233 (r'/', Comment.Preproc),
1234 (r'(?<=\\)\n', Comment.Preproc),
1235 (r'\n', Comment.Preproc, '#pop'),
1236 ],
1237 'if0': [
1238 (r'^\s*#if.*?(?<!\\)\n', Comment.Preproc, '#push'),
1239 (r'^\s*#endif.*?(?<!\\)\n', Comment.Preproc, '#pop'),
1240 (r'.*?\n', Comment),
1241 ]
1242 }
1243
1244 def analyse_text(text):
1245 if '@import' in text or '@interface' in text or \
1246 '@implementation' in text:
1247 return True
1248 elif '@"' in text: # strings
1249 return True
1250 elif re.match(r'\[[a-zA-Z0-9.]:', text): # message
1251 return True
1252 return False
1253 1296
1254 1297
1255 class FortranLexer(RegexLexer): 1298 class FortranLexer(RegexLexer):
1256 """ 1299 """
1257 Lexer for FORTRAN 90 code. 1300 Lexer for FORTRAN 90 code.
1280 include('nums'), 1323 include('nums'),
1281 (r'[\s]+', Text), 1324 (r'[\s]+', Text),
1282 ], 1325 ],
1283 'core': [ 1326 'core': [
1284 # Statements 1327 # Statements
1285 (r'\b(ACCEPT|ALLOCATABLE|ALLOCATE|ARRAY|ASSIGN|ASYNCHRONOUS|' 1328 (r'\b(ABSTRACT|ACCEPT|ALLOCATABLE|ALLOCATE|ARRAY|ASSIGN|ASYNCHRONOUS|'
1286 r'BACKSPACE|BIND|BLOCK DATA|BYTE|CALL|CASE|CLOSE|COMMON|CONTAINS|' 1329 r'BACKSPACE|BIND|BLOCK( DATA)?|BYTE|CALL|CASE|CLASS|CLOSE|COMMON|CONTAINS|'
1287 r'CONTINUE|CYCLE|DATA|DEALLOCATE|DECODE|DEFERRED|DIMENSION|DO|' 1330 r'CONTINUE|CYCLE|DATA|DEALLOCATE|DECODE|DEFERRED|DIMENSION|DO|'
1288 r'ELSE|ENCODE|END FILE|ENDIF|END|ENTRY|ENUMERATOR|EQUIVALENCE|' 1331 r'ELEMENTAL|ELSE|ENCODE|END( FILE)?|ENDIF|ENTRY|ENUMERATOR|EQUIVALENCE|'
1289 r'EXIT|EXTERNAL|EXTRINSIC|FINAL|FORALL|FORMAT|FUNCTION|GENERIC|' 1332 r'EXIT|EXTERNAL|EXTRINSIC|FINAL|FORALL|FORMAT|FUNCTION|GENERIC|'
1290 r'GOTO|IF|IMPLICIT|IMPORT|INCLUDE|INQUIRE|INTENT|INTERFACE|' 1333 r'GOTO|IF|IMPLICIT|IMPORT|INCLUDE|INQUIRE|INTENT|INTERFACE|'
1291 r'INTRINSIC|MODULE|NAMELIST|NULLIFY|NONE|NON_INTRINSIC|' 1334 r'INTRINSIC|MODULE|NAMELIST|NULLIFY|NONE|NON_INTRINSIC|'
1292 r'NON_OVERRIDABLE|NOPASS|OPEN|OPTIONAL|OPTIONS|PARAMETER|PASS|' 1335 r'NON_OVERRIDABLE|NOPASS|OPEN|OPTIONAL|OPTIONS|PARAMETER|PASS|'
1293 r'PAUSE|POINTER|PRINT|PRIVATE|PROGRAM|PROTECTED|PUBLIC|PURE|READ|' 1336 r'PAUSE|POINTER|PRINT|PRIVATE|PROGRAM|PROTECTED|PUBLIC|PURE|READ|'
1294 r'RECURSIVE|RETURN|REWIND|SAVE|SELECT|SEQUENCE|STOP|SUBROUTINE|' 1337 r'RECURSIVE|RESULT|RETURN|REWIND|SAVE|SELECT|SEQUENCE|STOP|SUBROUTINE|'
1295 r'TARGET|THEN|TYPE|USE|VALUE|VOLATILE|WHERE|WRITE|WHILE)\s*\b', 1338 r'TARGET|THEN|TYPE|USE|VALUE|VOLATILE|WHERE|WRITE|WHILE)\s*\b',
1296 Keyword), 1339 Keyword),
1297 1340
1298 # Data Types 1341 # Data Types
1299 (r'\b(CHARACTER|COMPLEX|DOUBLE PRECISION|DOUBLE COMPLEX|INTEGER|' 1342 (r'\b(CHARACTER|COMPLEX|DOUBLE PRECISION|DOUBLE COMPLEX|INTEGER|'
1434 (r'"(?:\\x[0-9a-fA-F]+\\|\\u[0-9a-fA-F]{4}|\\U[0-9a-fA-F]{8}|' 1477 (r'"(?:\\x[0-9a-fA-F]+\\|\\u[0-9a-fA-F]{4}|\\U[0-9a-fA-F]{8}|'
1435 r'\\[0-7]+\\|\\[\w\W]|[^"])*"', String.Double), 1478 r'\\[0-7]+\\|\\[\w\W]|[^"])*"', String.Double),
1436 (r"'(?:''|[^'])*'", String.Atom), # quoted atom 1479 (r"'(?:''|[^'])*'", String.Atom), # quoted atom
1437 # Needs to not be followed by an atom. 1480 # Needs to not be followed by an atom.
1438 #(r'=(?=\s|[a-zA-Z\[])', Operator), 1481 #(r'=(?=\s|[a-zA-Z\[])', Operator),
1439 (r'(is|<|>|=<|>=|==|=:=|=|/|//|\*|\+|-)(?=\s|[a-zA-Z0-9\[])', 1482 (r'is\b', Operator),
1483 (r'(<|>|=<|>=|==|=:=|=|/|//|\*|\+|-)(?=\s|[a-zA-Z0-9\[])',
1440 Operator), 1484 Operator),
1441 (r'(mod|div|not)\b', Operator), 1485 (r'(mod|div|not)\b', Operator),
1442 (r'_', Keyword), # The don't-care variable 1486 (r'_', Keyword), # The don't-care variable
1443 (r'([a-z]+)(:)', bygroups(Name.Namespace, Punctuation)), 1487 (r'([a-z]+)(:)', bygroups(Name.Namespace, Punctuation)),
1444 ('([a-z\u00c0-\u1fff\u3040-\ud7ff\ue000-\uffef]' 1488 ('([a-z\u00c0-\u1fff\u3040-\ud7ff\ue000-\uffef]'
1805 (r'\n', Text), 1849 (r'\n', Text),
1806 (r'\s+', Text), 1850 (r'\s+', Text),
1807 (r'\\\n', Text), # line continuations 1851 (r'\\\n', Text), # line continuations
1808 (r'//(.*?)\n', Comment.Single), 1852 (r'//(.*?)\n', Comment.Single),
1809 (r'/(\\\n)?[*](.|\n)*?[*](\\\n)?/', Comment.Multiline), 1853 (r'/(\\\n)?[*](.|\n)*?[*](\\\n)?/', Comment.Multiline),
1810 (r'(break|default|func|interface|select' 1854 (r'(import|package)\b', Keyword.Namespace),
1811 r'|case|defer|go|map|struct' 1855 (r'(var|func|struct|map|chan|type|interface|const)\b', Keyword.Declaration),
1812 r'|chan|else|goto|package|switch' 1856 (r'(break|default|select|case|defer|go'
1813 r'|const|fallthrough|if|range|type' 1857 r'|else|goto|switch|fallthrough|if|range'
1814 r'|continue|for|import|return|var)\b', Keyword 1858 r'|continue|for|return)\b', Keyword),
1815 ), 1859 (r'(true|false|iota|nil)\b', Keyword.Constant),
1816 # It seems the builtin types aren't actually keywords. 1860 # It seems the builtin types aren't actually keywords, but
1817 (r'(uint8|uint16|uint32|uint64' 1861 # can be used as functions. So we need two declarations.
1818 r'|int8|int16|int32|int64' 1862 (r'(uint|uint8|uint16|uint32|uint64'
1819 r'|float32|float64|byte' 1863 r'|int|int8|int16|int32|int64'
1820 r'|uint|int|float|uintptr' 1864 r'|float|float32|float64'
1821 r'|string|close|closed|len|cap|new|make)\b', Name.Builtin 1865 r'|complex64|complex128|byte|rune'
1822 ), 1866 r'|string|bool|error|uintptr'
1867 r'|print|println|panic|recover|close|complex|real|imag'
1868 r'|len|cap|append|copy|delete|new|make)\b(\()',
1869 bygroups(Name.Builtin, Punctuation)),
1870 (r'(uint|uint8|uint16|uint32|uint64'
1871 r'|int|int8|int16|int32|int64'
1872 r'|float|float32|float64'
1873 r'|complex64|complex128|byte|rune'
1874 r'|string|bool|error|uintptr)\b', Keyword.Type),
1875 # imaginary_lit
1876 (r'\d+i', Number),
1877 (r'\d+\.\d*([Ee][-+]\d+)?i', Number),
1878 (r'\.\d+([Ee][-+]\d+)?i', Number),
1879 (r'\d+[Ee][-+]\d+i', Number),
1823 # float_lit 1880 # float_lit
1824 (r'\d+(\.\d+[eE][+\-]?\d+|' 1881 (r'\d+(\.\d+[eE][+\-]?\d+|'
1825 r'\.\d*|[eE][+\-]?\d+)', Number.Float), 1882 r'\.\d*|[eE][+\-]?\d+)', Number.Float),
1826 (r'\.\d+([eE][+\-]?\d+)?', Number.Float), 1883 (r'\.\d+([eE][+\-]?\d+)?', Number.Float),
1827 # int_lit 1884 # int_lit
1841 (r'`[^`]*`', String), 1898 (r'`[^`]*`', String),
1842 # -- interpreted_string_lit 1899 # -- interpreted_string_lit
1843 (r'"(\\\\|\\"|[^"])*"', String), 1900 (r'"(\\\\|\\"|[^"])*"', String),
1844 # Tokens 1901 # Tokens
1845 (r'(<<=|>>=|<<|>>|<=|>=|&\^=|&\^|\+=|-=|\*=|/=|%=|&=|\|=|&&|\|\|' 1902 (r'(<<=|>>=|<<|>>|<=|>=|&\^=|&\^|\+=|-=|\*=|/=|%=|&=|\|=|&&|\|\|'
1846 r'|<-|\+\+|--|==|!=|:=|\.\.\.)|[+\-*/%&|^<>=!()\[\]{}.,;:]', 1903 r'|<-|\+\+|--|==|!=|:=|\.\.\.|[+\-*/%&])', Operator),
1847 Punctuation 1904 (r'[|^<>=!()\[\]{}.,;:]', Punctuation),
1848 ),
1849 # identifier 1905 # identifier
1850 (r'[a-zA-Z_]\w*', Name), 1906 (r'[a-zA-Z_]\w*', Name.Other),
1851 ] 1907 ]
1852 } 1908 }
1853 1909
1854 1910
1855 class FelixLexer(RegexLexer): 1911 class FelixLexer(RegexLexer):
2118 filenames = ['*.adb', '*.ads', '*.ada'] 2174 filenames = ['*.adb', '*.ads', '*.ada']
2119 mimetypes = ['text/x-ada'] 2175 mimetypes = ['text/x-ada']
2120 2176
2121 flags = re.MULTILINE | re.I # Ignore case 2177 flags = re.MULTILINE | re.I # Ignore case
2122 2178
2123 _ws = r'(?:\s|//.*?\n|/[*].*?[*]/)+'
2124
2125 tokens = { 2179 tokens = {
2126 'root': [ 2180 'root': [
2127 (r'[^\S\n]+', Text), 2181 (r'[^\S\n]+', Text),
2128 (r'--.*?\n', Comment.Single), 2182 (r'--.*?\n', Comment.Single),
2129 (r'[^\S\n]+', Text), 2183 (r'[^\S\n]+', Text),
2134 (r'(subtype)(\s+)', bygroups(Keyword.Declaration, Text)), 2188 (r'(subtype)(\s+)', bygroups(Keyword.Declaration, Text)),
2135 (r'(end)(\s+)', bygroups(Keyword.Reserved, Text), 'end'), 2189 (r'(end)(\s+)', bygroups(Keyword.Reserved, Text), 'end'),
2136 (r'(pragma)(\s+)([a-zA-Z0-9_]+)', bygroups(Keyword.Reserved, Text, 2190 (r'(pragma)(\s+)([a-zA-Z0-9_]+)', bygroups(Keyword.Reserved, Text,
2137 Comment.Preproc)), 2191 Comment.Preproc)),
2138 (r'(true|false|null)\b', Keyword.Constant), 2192 (r'(true|false|null)\b', Keyword.Constant),
2139 (r'(Byte|Character|Float|Integer|Long_Float|Long_Integer|' 2193 (r'(Address|Byte|Boolean|Character|Controlled|Count|Cursor|'
2140 r'Long_Long_Float|Long_Long_Integer|Natural|Positive|Short_Float|' 2194 r'Duration|File_Mode|File_Type|Float|Generator|Integer|Long_Float|'
2141 r'Short_Integer|Short_Short_Float|Short_Short_Integer|String|' 2195 r'Long_Integer|Long_Long_Float|Long_Long_Integer|Natural|Positive|'
2142 r'Wide_String|Duration)\b', Keyword.Type), 2196 r'Reference_Type|Short_Float|Short_Integer|Short_Short_Float|'
2197 r'Short_Short_Integer|String|Wide_Character|Wide_String)\b',
2198 Keyword.Type),
2143 (r'(and(\s+then)?|in|mod|not|or(\s+else)|rem)\b', Operator.Word), 2199 (r'(and(\s+then)?|in|mod|not|or(\s+else)|rem)\b', Operator.Word),
2144 (r'generic|private', Keyword.Declaration), 2200 (r'generic|private', Keyword.Declaration),
2145 (r'package', Keyword.Declaration, 'package'), 2201 (r'package', Keyword.Declaration, 'package'),
2146 (r'array\b', Keyword.Reserved, 'array_def'), 2202 (r'array\b', Keyword.Reserved, 'array_def'),
2147 (r'(with|use)(\s+)', bygroups(Keyword.Namespace, Text), 'import'), 2203 (r'(with|use)(\s+)', bygroups(Keyword.Namespace, Text), 'import'),
2192 'type_def': [ 2248 'type_def': [
2193 (r';', Punctuation, '#pop'), 2249 (r';', Punctuation, '#pop'),
2194 (r'\(', Punctuation, 'formal_part'), 2250 (r'\(', Punctuation, 'formal_part'),
2195 (r'with|and|use', Keyword.Reserved), 2251 (r'with|and|use', Keyword.Reserved),
2196 (r'array\b', Keyword.Reserved, ('#pop', 'array_def')), 2252 (r'array\b', Keyword.Reserved, ('#pop', 'array_def')),
2197 (r'record\b', Keyword.Reserved, ('formal_part')), 2253 (r'record\b', Keyword.Reserved, ('record_def')),
2254 (r'(null record)(;)', bygroups(Keyword.Reserved, Punctuation), '#pop'),
2198 include('root'), 2255 include('root'),
2199 ], 2256 ],
2200 'array_def' : [ 2257 'array_def' : [
2201 (r';', Punctuation, '#pop'), 2258 (r';', Punctuation, '#pop'),
2202 (r'([a-z0-9_]+)(\s+)(range)', bygroups(Keyword.Type, Text, 2259 (r'([a-z0-9_]+)(\s+)(range)', bygroups(Keyword.Type, Text,
2203 Keyword.Reserved)), 2260 Keyword.Reserved)),
2261 include('root'),
2262 ],
2263 'record_def' : [
2264 (r'end record', Keyword.Reserved, '#pop'),
2204 include('root'), 2265 include('root'),
2205 ], 2266 ],
2206 'import': [ 2267 'import': [
2207 (r'[a-z0-9_.]+', Name.Namespace, '#pop'), 2268 (r'[a-z0-9_.]+', Name.Namespace, '#pop'),
2208 (r'', Text, '#pop'), 2269 (r'', Text, '#pop'),
2440 2501
2441 bmax_vopwords = r'\b(Shl|Shr|Sar|Mod)\b' 2502 bmax_vopwords = r'\b(Shl|Shr|Sar|Mod)\b'
2442 bmax_sktypes = r'@{1,2}|[!#$%]' 2503 bmax_sktypes = r'@{1,2}|[!#$%]'
2443 bmax_lktypes = r'\b(Int|Byte|Short|Float|Double|Long)\b' 2504 bmax_lktypes = r'\b(Int|Byte|Short|Float|Double|Long)\b'
2444 bmax_name = r'[a-z_][a-z0-9_]*' 2505 bmax_name = r'[a-z_][a-z0-9_]*'
2445 bmax_var = r'(%s)(?:(?:([ \t]*)(%s)|([ \t]*:[ \t]*\b(?:Shl|Shr|Sar|Mod)\b)|([ \t]*)([:])([ \t]*)(?:%s|(%s)))(?:([ \t]*)(Ptr))?)' % (bmax_name, bmax_sktypes, bmax_lktypes, bmax_name) 2506 bmax_var = (r'(%s)(?:(?:([ \t]*)(%s)|([ \t]*:[ \t]*\b(?:Shl|Shr|Sar|Mod)\b)'
2507 r'|([ \t]*)([:])([ \t]*)(?:%s|(%s)))(?:([ \t]*)(Ptr))?)') % \
2508 (bmax_name, bmax_sktypes, bmax_lktypes, bmax_name)
2446 bmax_func = bmax_var + r'?((?:[ \t]|\.\.\n)*)([(])' 2509 bmax_func = bmax_var + r'?((?:[ \t]|\.\.\n)*)([(])'
2447 2510
2448 flags = re.MULTILINE | re.IGNORECASE 2511 flags = re.MULTILINE | re.IGNORECASE
2449 tokens = { 2512 tokens = {
2450 'root': [ 2513 'root': [
2887 (r'(\s*)(\w+)(\s*)(=)', bygroups(Text, Name, Text, Operator)), 2950 (r'(\s*)(\w+)(\s*)(=)', bygroups(Text, Name, Text, Operator)),
2888 (r'}', Punctuation, '#pop'), 2951 (r'}', Punctuation, '#pop'),
2889 (r'.', Text) 2952 (r'.', Text)
2890 ], 2953 ],
2891 } 2954 }
2955
2956
2957 class RustLexer(RegexLexer):
2958 """
2959 Lexer for Mozilla's Rust programming language.
2960
2961 *New in Pygments 1.6.*
2962 """
2963 name = 'Rust'
2964 filenames = ['*.rs', '*.rc']
2965 aliases = ['rust']
2966 mimetypes = ['text/x-rustsrc']
2967
2968 tokens = {
2969 'root': [
2970 # Whitespace and Comments
2971 (r'\n', Text),
2972 (r'\s+', Text),
2973 (r'//(.*?)\n', Comment.Single),
2974 (r'/[*](.|\n)*?[*]/', Comment.Multiline),
2975
2976 # Keywords
2977 (r'(as|assert|break|const'
2978 r'|copy|do|else|enum|extern|fail'
2979 r'|false|fn|for|if|impl|let|log'
2980 r'|loop|match|mod|move|mut|once|priv|pub|pure'
2981 r'|ref|return|static|struct|trait|true|type|unsafe|use|while'
2982 r'|u8|u16|u32|u64|i8|i16|i32|i64|uint'
2983 r'|int|float|f32|f64|str)\b', Keyword),
2984
2985 # Character Literal
2986 (r"""'(\\['"\\nrt]|\\x[0-9a-fA-F]{2}|\\[0-7]{1,3}"""
2987 r"""|\\u[0-9a-fA-F]{4}|\\U[0-9a-fA-F]{8}|.)'""",
2988 String.Char),
2989 # Binary Literal
2990 (r'0[Bb][01_]+', Number, 'number_lit'),
2991 # Octal Literal
2992 (r'0[0-7_]+', Number.Oct, 'number_lit'),
2993 # Hexadecimal Literal
2994 (r'0[xX][0-9a-fA-F_]+', Number.Hex, 'number_lit'),
2995 # Decimal Literal
2996 (r'[0-9][0-9_]*(\.[0-9_]+[eE][+\-]?'
2997 r'[0-9_]+|\.[0-9_]*|[eE][+\-]?[0-9_]+)?', Number, 'number_lit'),
2998 # String Literal
2999 (r'"', String, 'string'),
3000
3001 # Operators and Punctuation
3002 (r'[{}()\[\],.;]', Punctuation),
3003 (r'[+\-*/%&|<>^!~@=:?]', Operator),
3004
3005 # Identifier
3006 (r'[a-zA-Z_$][a-zA-Z0-9_]*', Name),
3007
3008 # Attributes
3009 (r'#\[', Comment.Preproc, 'attribute['),
3010 (r'#\(', Comment.Preproc, 'attribute('),
3011 # Macros
3012 (r'[A-Za-z_][A-Za-z0-9_]*!\[', Comment.Preproc, 'attribute['),
3013 (r'[A-Za-z_][A-Za-z0-9_]*!\(', Comment.Preproc, 'attribute('),
3014 ],
3015 'number_lit': [
3016 (r'(([ui](8|16|32|64)?)|(f(32|64)?))?', Keyword, '#pop'),
3017 ],
3018 'string': [
3019 (r'"', String, '#pop'),
3020 (r"""\\['"\\nrt]|\\x[0-9a-fA-F]{2}|\\[0-7]{1,3}"""
3021 r"""|\\u[0-9a-fA-F]{4}|\\U[0-9a-fA-F]{8}""", String.Escape),
3022 (r'[^\\"]+', String),
3023 (r'\\', String),
3024 ],
3025 'attribute_common': [
3026 (r'"', String, 'string'),
3027 (r'\[', Comment.Preproc, 'attribute['),
3028 (r'\(', Comment.Preproc, 'attribute('),
3029 ],
3030 'attribute[': [
3031 include('attribute_common'),
3032 (r'\];?', Comment.Preproc, '#pop'),
3033 (r'[^"\]]+', Comment.Preproc),
3034 ],
3035 'attribute(': [
3036 include('attribute_common'),
3037 (r'\);?', Comment.Preproc, '#pop'),
3038 (r'[^"\)]+', Comment.Preproc),
3039 ],
3040 }
3041
3042
3043 class CudaLexer(CLexer):
3044 """
3045 For NVIDIA `CUDAâ„¢ <http://developer.nvidia.com/category/zone/cuda-zone>`_
3046 source.
3047
3048 *New in Pygments 1.6.*
3049 """
3050 name = 'CUDA'
3051 filenames = ['*.cu', '*.cuh']
3052 aliases = ['cuda', 'cu']
3053 mimetypes = ['text/x-cuda']
3054
3055 function_qualifiers = ['__device__', '__global__', '__host__',
3056 '__noinline__', '__forceinline__']
3057 variable_qualifiers = ['__device__', '__constant__', '__shared__',
3058 '__restrict__']
3059 vector_types = ['char1', 'uchar1', 'char2', 'uchar2', 'char3', 'uchar3',
3060 'char4', 'uchar4', 'short1', 'ushort1', 'short2', 'ushort2',
3061 'short3', 'ushort3', 'short4', 'ushort4', 'int1', 'uint1',
3062 'int2', 'uint2', 'int3', 'uint3', 'int4', 'uint4', 'long1',
3063 'ulong1', 'long2', 'ulong2', 'long3', 'ulong3', 'long4',
3064 'ulong4', 'longlong1', 'ulonglong1', 'longlong2',
3065 'ulonglong2', 'float1', 'float2', 'float3', 'float4',
3066 'double1', 'double2', 'dim3']
3067 variables = ['gridDim', 'blockIdx', 'blockDim', 'threadIdx', 'warpSize']
3068 functions = ['__threadfence_block', '__threadfence', '__threadfence_system',
3069 '__syncthreads', '__syncthreads_count', '__syncthreads_and',
3070 '__syncthreads_or']
3071 execution_confs = ['<<<', '>>>']
3072
3073 def get_tokens_unprocessed(self, text):
3074 for index, token, value in \
3075 CLexer.get_tokens_unprocessed(self, text):
3076 if token is Name:
3077 if value in self.variable_qualifiers:
3078 token = Keyword.Type
3079 elif value in self.vector_types:
3080 token = Keyword.Type
3081 elif value in self.variables:
3082 token = Name.Builtin
3083 elif value in self.execution_confs:
3084 token = Keyword.Pseudo
3085 elif value in self.function_qualifiers:
3086 token = Keyword.Reserved
3087 elif value in self.functions:
3088 token = Name.Function
3089 yield index, token, value
3090
3091
3092 class MonkeyLexer(RegexLexer):
3093 """
3094 For
3095 `Monkey <https://en.wikipedia.org/wiki/Monkey_(programming_language)>`_
3096 source code.
3097
3098 *New in Pygments 1.6.*
3099 """
3100
3101 name = 'Monkey'
3102 aliases = ['monkey']
3103 filenames = ['*.monkey']
3104 mimetypes = ['text/x-monkey']
3105
3106 name_variable = r'[a-z_][a-zA-Z0-9_]*'
3107 name_function = r'[A-Z][a-zA-Z0-9_]*'
3108 name_constant = r'[A-Z_][A-Z0-9_]*'
3109 name_class = r'[A-Z][a-zA-Z0-9_]*'
3110 name_module = r'[a-z0-9_]*'
3111
3112 keyword_type = r'(?:Int|Float|String|Bool|Object|Array|Void)'
3113 # ? == Bool // % == Int // # == Float // $ == String
3114 keyword_type_special = r'[?%#$]'
3115
3116 flags = re.MULTILINE
3117
3118 tokens = {
3119 'root': [
3120 #Text
3121 (r'\s+', Text),
3122 # Comments
3123 (r"'.*", Comment),
3124 (r'(?i)^#rem\b', Comment.Multiline, 'comment'),
3125 # preprocessor directives
3126 (r'(?i)^(?:#If|#ElseIf|#Else|#EndIf|#End|#Print|#Error)\b', Comment.Preproc),
3127 # preprocessor variable (any line starting with '#' that is not a directive)
3128 (r'^#', Comment.Preproc, 'variables'),
3129 # String
3130 ('"', String.Double, 'string'),
3131 # Numbers
3132 (r'[0-9]+\.[0-9]*(?!\.)', Number.Float),
3133 (r'\.[0-9]+(?!\.)', Number.Float),
3134 (r'[0-9]+', Number.Integer),
3135 (r'\$[0-9a-fA-Z]+', Number.Hex),
3136 (r'\%[10]+', Number), # Binary
3137 # Native data types
3138 (r'\b%s\b' % keyword_type, Keyword.Type),
3139 # Exception handling
3140 (r'(?i)\b(?:Try|Catch|Throw)\b', Keyword.Reserved),
3141 (r'Throwable', Name.Exception),
3142 # Builtins
3143 (r'(?i)\b(?:Null|True|False)\b', Name.Builtin),
3144 (r'(?i)\b(?:Self|Super)\b', Name.Builtin.Pseudo),
3145 (r'\b(?:HOST|LANG|TARGET|CONFIG)\b', Name.Constant),
3146 # Keywords
3147 (r'(?i)^(Import)(\s+)(.*)(\n)',
3148 bygroups(Keyword.Namespace, Text, Name.Namespace, Text)),
3149 (r'(?i)^Strict\b.*\n', Keyword.Reserved),
3150 (r'(?i)(Const|Local|Global|Field)(\s+)',
3151 bygroups(Keyword.Declaration, Text), 'variables'),
3152 (r'(?i)(New|Class|Interface|Extends|Implements)(\s+)',
3153 bygroups(Keyword.Reserved, Text), 'classname'),
3154 (r'(?i)(Function|Method)(\s+)',
3155 bygroups(Keyword.Reserved, Text), 'funcname'),
3156 (r'(?i)(?:End|Return|Public|Private|Extern|Property|'
3157 r'Final|Abstract)\b', Keyword.Reserved),
3158 # Flow Control stuff
3159 (r'(?i)(?:If|Then|Else|ElseIf|EndIf|'
3160 r'Select|Case|Default|'
3161 r'While|Wend|'
3162 r'Repeat|Until|Forever|'
3163 r'For|To|Until|Step|EachIn|Next|'
3164 r'Exit|Continue)\s+', Keyword.Reserved),
3165 # not used yet
3166 (r'(?i)\b(?:Module|Inline)\b', Keyword.Reserved),
3167 # Array
3168 (r'[\[\]]', Punctuation),
3169 # Other
3170 (r'<=|>=|<>|\*=|/=|\+=|-=|&=|~=|\|=|[-&*/^+=<>|~]', Operator),
3171 (r'(?i)(?:Not|Mod|Shl|Shr|And|Or)', Operator.Word),
3172 (r'[\(\){}!#,.:]', Punctuation),
3173 # catch the rest
3174 (r'%s\b' % name_constant, Name.Constant),
3175 (r'%s\b' % name_function, Name.Function),
3176 (r'%s\b' % name_variable, Name.Variable),
3177 ],
3178 'funcname': [
3179 (r'(?i)%s\b' % name_function, Name.Function),
3180 (r':', Punctuation, 'classname'),
3181 (r'\s+', Text),
3182 (r'\(', Punctuation, 'variables'),
3183 (r'\)', Punctuation, '#pop')
3184 ],
3185 'classname': [
3186 (r'%s\.' % name_module, Name.Namespace),
3187 (r'%s\b' % keyword_type, Keyword.Type),
3188 (r'%s\b' % name_class, Name.Class),
3189 # array (of given size)
3190 (r'(\[)(\s*)(\d*)(\s*)(\])',
3191 bygroups(Punctuation, Text, Number.Integer, Text, Punctuation)),
3192 # generics
3193 (r'\s+(?!<)', Text, '#pop'),
3194 (r'<', Punctuation, '#push'),
3195 (r'>', Punctuation, '#pop'),
3196 (r'\n', Text, '#pop'),
3197 (r'', Text, '#pop')
3198 ],
3199 'variables': [
3200 (r'%s\b' % name_constant, Name.Constant),
3201 (r'%s\b' % name_variable, Name.Variable),
3202 (r'%s' % keyword_type_special, Keyword.Type),
3203 (r'\s+', Text),
3204 (r':', Punctuation, 'classname'),
3205 (r',', Punctuation, '#push'),
3206 (r'', Text, '#pop')
3207 ],
3208 'string': [
3209 (r'[^"~]+', String.Double),
3210 (r'~q|~n|~r|~t|~z|~~', String.Escape),
3211 (r'"', String.Double, '#pop'),
3212 ],
3213 'comment' : [
3214 (r'(?i)^#rem.*?', Comment.Multiline, "#push"),
3215 (r'(?i)^#end.*?', Comment.Multiline, "#pop"),
3216 (r'\n', Comment.Multiline),
3217 (r'.+', Comment.Multiline),
3218 ],
3219 }
3220
3221
3222 class CobolLexer(RegexLexer):
3223 """
3224 Lexer for OpenCOBOL code.
3225
3226 *New in Pygments 1.6.*
3227 """
3228 name = 'COBOL'
3229 aliases = ['cobol']
3230 filenames = ['*.cob', '*.COB', '*.cpy', '*.CPY']
3231 mimetypes = ['text/x-cobol']
3232 flags = re.IGNORECASE | re.MULTILINE
3233
3234 # Data Types: by PICTURE and USAGE
3235 # Operators: **, *, +, -, /, <, >, <=, >=, =, <>
3236 # Logical (?): NOT, AND, OR
3237
3238 # Reserved words:
3239 # http://opencobol.add1tocobol.com/#reserved-words
3240 # Intrinsics:
3241 # http://opencobol.add1tocobol.com/#does-opencobol-implement-any-intrinsic-functions
3242
3243 tokens = {
3244 'root': [
3245 include('comment'),
3246 include('strings'),
3247 include('core'),
3248 include('nums'),
3249 (r'[a-z0-9]([_a-z0-9\-]*[a-z0-9]+)?', Name.Variable),
3250 # (r'[\s]+', Text),
3251 (r'[ \t]+', Text),
3252 ],
3253 'comment': [
3254 (r'(^.{6}[*/].*\n|^.{6}|\*>.*\n)', Comment),
3255 ],
3256 'core': [
3257 # Figurative constants
3258 (r'(^|(?<=[^0-9a-z_\-]))(ALL\s+)?'
3259 r'((ZEROES)|(HIGH-VALUE|LOW-VALUE|QUOTE|SPACE|ZERO)(S)?)'
3260 r'\s*($|(?=[^0-9a-z_\-]))',
3261 Name.Constant),
3262
3263 # Reserved words STATEMENTS and other bolds
3264 (r'(^|(?<=[^0-9a-z_\-]))'
3265 r'(ACCEPT|ADD|ALLOCATE|CALL|CANCEL|CLOSE|COMPUTE|'
3266 r'CONFIGURATION|CONTINUE|'
3267 r'DATA|DELETE|DISPLAY|DIVIDE|DIVISION|ELSE|END|END-ACCEPT|'
3268 r'END-ADD|END-CALL|END-COMPUTE|END-DELETE|END-DISPLAY|'
3269 r'END-DIVIDE|END-EVALUATE|END-IF|END-MULTIPLY|END-OF-PAGE|'
3270 r'END-PERFORM|END-READ|END-RETURN|END-REWRITE|END-SEARCH|'
3271 r'END-START|END-STRING|END-SUBTRACT|END-UNSTRING|END-WRITE|'
3272 r'ENVIRONMENT|EVALUATE|EXIT|FD|FILE|FILE-CONTROL|FOREVER|'
3273 r'FREE|GENERATE|GO|GOBACK|'
3274 r'IDENTIFICATION|IF|INITIALIZE|'
3275 r'INITIATE|INPUT-OUTPUT|INSPECT|INVOKE|I-O-CONTROL|LINKAGE|'
3276 r'LOCAL-STORAGE|MERGE|MOVE|MULTIPLY|OPEN|'
3277 r'PERFORM|PROCEDURE|PROGRAM-ID|RAISE|READ|RELEASE|RESUME|'
3278 r'RETURN|REWRITE|SCREEN|'
3279 r'SD|SEARCH|SECTION|SET|SORT|START|STOP|STRING|SUBTRACT|'
3280 r'SUPPRESS|TERMINATE|THEN|UNLOCK|UNSTRING|USE|VALIDATE|'
3281 r'WORKING-STORAGE|WRITE)'
3282 r'\s*($|(?=[^0-9a-z_\-]))', Keyword.Reserved),
3283
3284 # Reserved words
3285 (r'(^|(?<=[^0-9a-z_\-]))'
3286 r'(ACCESS|ADDRESS|ADVANCING|AFTER|ALL|'
3287 r'ALPHABET|ALPHABETIC|ALPHABETIC-LOWER|ALPHABETIC-UPPER|'
3288 r'ALPHANUMERIC|ALPHANUMERIC-EDITED|ALSO|ALTER|ALTERNATE'
3289 r'ANY|ARE|AREA|AREAS|ARGUMENT-NUMBER|ARGUMENT-VALUE|AS|'
3290 r'ASCENDING|ASSIGN|AT|AUTO|AUTO-SKIP|AUTOMATIC|AUTOTERMINATE|'
3291 r'BACKGROUND-COLOR|BASED|BEEP|BEFORE|BELL|'
3292 r'BLANK|'
3293 r'BLINK|BLOCK|BOTTOM|BY|BYTE-LENGTH|CHAINING|'
3294 r'CHARACTER|CHARACTERS|CLASS|CODE|CODE-SET|COL|COLLATING|'
3295 r'COLS|COLUMN|COLUMNS|COMMA|COMMAND-LINE|COMMIT|COMMON|'
3296 r'CONSTANT|CONTAINS|CONTENT|CONTROL|'
3297 r'CONTROLS|CONVERTING|COPY|CORR|CORRESPONDING|COUNT|CRT|'
3298 r'CURRENCY|CURSOR|CYCLE|DATE|DAY|DAY-OF-WEEK|DE|DEBUGGING|'
3299 r'DECIMAL-POINT|DECLARATIVES|DEFAULT|DELIMITED|'
3300 r'DELIMITER|DEPENDING|DESCENDING|DETAIL|DISK|'
3301 r'DOWN|DUPLICATES|DYNAMIC|EBCDIC|'
3302 r'ENTRY|ENVIRONMENT-NAME|ENVIRONMENT-VALUE|EOL|EOP|'
3303 r'EOS|ERASE|ERROR|ESCAPE|EXCEPTION|'
3304 r'EXCLUSIVE|EXTEND|EXTERNAL|'
3305 r'FILE-ID|FILLER|FINAL|FIRST|FIXED|FLOAT-LONG|FLOAT-SHORT|'
3306 r'FOOTING|FOR|FOREGROUND-COLOR|FORMAT|FROM|FULL|FUNCTION|'
3307 r'FUNCTION-ID|GIVING|GLOBAL|GROUP|'
3308 r'HEADING|HIGHLIGHT|I-O|ID|'
3309 r'IGNORE|IGNORING|IN|INDEX|INDEXED|INDICATE|'
3310 r'INITIAL|INITIALIZED|INPUT|'
3311 r'INTO|INTRINSIC|INVALID|IS|JUST|JUSTIFIED|KEY|LABEL|'
3312 r'LAST|LEADING|LEFT|LENGTH|LIMIT|LIMITS|LINAGE|'
3313 r'LINAGE-COUNTER|LINE|LINES|LOCALE|LOCK|'
3314 r'LOWLIGHT|MANUAL|MEMORY|MINUS|MODE|'
3315 r'MULTIPLE|NATIONAL|NATIONAL-EDITED|NATIVE|'
3316 r'NEGATIVE|NEXT|NO|NULL|NULLS|NUMBER|NUMBERS|NUMERIC|'
3317 r'NUMERIC-EDITED|OBJECT-COMPUTER|OCCURS|OF|OFF|OMITTED|ON|ONLY|'
3318 r'OPTIONAL|ORDER|ORGANIZATION|OTHER|OUTPUT|OVERFLOW|'
3319 r'OVERLINE|PACKED-DECIMAL|PADDING|PAGE|PARAGRAPH|'
3320 r'PLUS|POINTER|POSITION|POSITIVE|PRESENT|PREVIOUS|'
3321 r'PRINTER|PRINTING|PROCEDURE-POINTER|PROCEDURES|'
3322 r'PROCEED|PROGRAM|PROGRAM-POINTER|PROMPT|QUOTE|'
3323 r'QUOTES|RANDOM|RD|RECORD|RECORDING|RECORDS|RECURSIVE|'
3324 r'REDEFINES|REEL|REFERENCE|RELATIVE|REMAINDER|REMOVAL|'
3325 r'RENAMES|REPLACING|REPORT|REPORTING|REPORTS|REPOSITORY|'
3326 r'REQUIRED|RESERVE|RETURNING|REVERSE-VIDEO|REWIND|'
3327 r'RIGHT|ROLLBACK|ROUNDED|RUN|SAME|SCROLL|'
3328 r'SECURE|SEGMENT-LIMIT|SELECT|SENTENCE|SEPARATE|'
3329 r'SEQUENCE|SEQUENTIAL|SHARING|SIGN|SIGNED|SIGNED-INT|'
3330 r'SIGNED-LONG|SIGNED-SHORT|SIZE|SORT-MERGE|SOURCE|'
3331 r'SOURCE-COMPUTER|SPECIAL-NAMES|STANDARD|'
3332 r'STANDARD-1|STANDARD-2|STATUS|SUM|'
3333 r'SYMBOLIC|SYNC|SYNCHRONIZED|TALLYING|TAPE|'
3334 r'TEST|THROUGH|THRU|TIME|TIMES|TO|TOP|TRAILING|'
3335 r'TRANSFORM|TYPE|UNDERLINE|UNIT|UNSIGNED|'
3336 r'UNSIGNED-INT|UNSIGNED-LONG|UNSIGNED-SHORT|UNTIL|UP|'
3337 r'UPDATE|UPON|USAGE|USING|VALUE|VALUES|VARYING|WAIT|WHEN|'
3338 r'WITH|WORDS|YYYYDDD|YYYYMMDD)'
3339 r'\s*($|(?=[^0-9a-z_\-]))', Keyword.Pseudo),
3340
3341 # inactive reserved words
3342 (r'(^|(?<=[^0-9a-z_\-]))'
3343 r'(ACTIVE-CLASS|ALIGNED|ANYCASE|ARITHMETIC|ATTRIBUTE|B-AND|'
3344 r'B-NOT|B-OR|B-XOR|BIT|BOOLEAN|CD|CENTER|CF|CH|CHAIN|CLASS-ID|'
3345 r'CLASSIFICATION|COMMUNICATION|CONDITION|DATA-POINTER|'
3346 r'DESTINATION|DISABLE|EC|EGI|EMI|ENABLE|END-RECEIVE|'
3347 r'ENTRY-CONVENTION|EO|ESI|EXCEPTION-OBJECT|EXPANDS|FACTORY|'
3348 r'FLOAT-BINARY-16|FLOAT-BINARY-34|FLOAT-BINARY-7|'
3349 r'FLOAT-DECIMAL-16|FLOAT-DECIMAL-34|FLOAT-EXTENDED|FORMAT|'
3350 r'FUNCTION-POINTER|GET|GROUP-USAGE|IMPLEMENTS|INFINITY|'
3351 r'INHERITS|INTERFACE|INTERFACE-ID|INVOKE|LC_ALL|LC_COLLATE|'
3352 r'LC_CTYPE|LC_MESSAGES|LC_MONETARY|LC_NUMERIC|LC_TIME|'
3353 r'LINE-COUNTER|MESSAGE|METHOD|METHOD-ID|NESTED|NONE|NORMAL|'
3354 r'OBJECT|OBJECT-REFERENCE|OPTIONS|OVERRIDE|PAGE-COUNTER|PF|PH|'
3355 r'PROPERTY|PROTOTYPE|PURGE|QUEUE|RAISE|RAISING|RECEIVE|'
3356 r'RELATION|REPLACE|REPRESENTS-NOT-A-NUMBER|RESET|RESUME|RETRY|'
3357 r'RF|RH|SECONDS|SEGMENT|SELF|SEND|SOURCES|STATEMENT|STEP|'
3358 r'STRONG|SUB-QUEUE-1|SUB-QUEUE-2|SUB-QUEUE-3|SUPER|SYMBOL|'
3359 r'SYSTEM-DEFAULT|TABLE|TERMINAL|TEXT|TYPEDEF|UCS-4|UNIVERSAL|'
3360 r'USER-DEFAULT|UTF-16|UTF-8|VAL-STATUS|VALID|VALIDATE|'
3361 r'VALIDATE-STATUS)\s*($|(?=[^0-9a-z_\-]))', Error),
3362
3363 # Data Types
3364 (r'(^|(?<=[^0-9a-z_\-]))'
3365 r'(PIC\s+.+?(?=(\s|\.\s))|PICTURE\s+.+?(?=(\s|\.\s))|'
3366 r'(COMPUTATIONAL)(-[1-5X])?|(COMP)(-[1-5X])?|'
3367 r'BINARY-C-LONG|'
3368 r'BINARY-CHAR|BINARY-DOUBLE|BINARY-LONG|BINARY-SHORT|'
3369 r'BINARY)\s*($|(?=[^0-9a-z_\-]))', Keyword.Type),
3370
3371 # Operators
3372 (r'(\*\*|\*|\+|-|/|<=|>=|<|>|==|/=|=)', Operator),
3373
3374 # (r'(::)', Keyword.Declaration),
3375
3376 (r'([(),;:&%.])', Punctuation),
3377
3378 # Intrinsics
3379 (r'(^|(?<=[^0-9a-z_\-]))(ABS|ACOS|ANNUITY|ASIN|ATAN|BYTE-LENGTH|'
3380 r'CHAR|COMBINED-DATETIME|CONCATENATE|COS|CURRENT-DATE|'
3381 r'DATE-OF-INTEGER|DATE-TO-YYYYMMDD|DAY-OF-INTEGER|DAY-TO-YYYYDDD|'
3382 r'EXCEPTION-(?:FILE|LOCATION|STATEMENT|STATUS)|EXP10|EXP|E|'
3383 r'FACTORIAL|FRACTION-PART|INTEGER-OF-(?:DATE|DAY|PART)|INTEGER|'
3384 r'LENGTH|LOCALE-(?:DATE|TIME(?:-FROM-SECONDS)?)|LOG10|LOG|'
3385 r'LOWER-CASE|MAX|MEAN|MEDIAN|MIDRANGE|MIN|MOD|NUMVAL(?:-C)?|'
3386 r'ORD(?:-MAX|-MIN)?|PI|PRESENT-VALUE|RANDOM|RANGE|REM|REVERSE|'
3387 r'SECONDS-FROM-FORMATTED-TIME|SECONDS-PAST-MIDNIGHT|SIGN|SIN|SQRT|'
3388 r'STANDARD-DEVIATION|STORED-CHAR-LENGTH|SUBSTITUTE(?:-CASE)?|'
3389 r'SUM|TAN|TEST-DATE-YYYYMMDD|TEST-DAY-YYYYDDD|TRIM|'
3390 r'UPPER-CASE|VARIANCE|WHEN-COMPILED|YEAR-TO-YYYY)\s*'
3391 r'($|(?=[^0-9a-z_\-]))', Name.Function),
3392
3393 # Booleans
3394 (r'(^|(?<=[^0-9a-z_\-]))(true|false)\s*($|(?=[^0-9a-z_\-]))', Name.Builtin),
3395 # Comparing Operators
3396 (r'(^|(?<=[^0-9a-z_\-]))(equal|equals|ne|lt|le|gt|ge|'
3397 r'greater|less|than|not|and|or)\s*($|(?=[^0-9a-z_\-]))', Operator.Word),
3398 ],
3399
3400 # \"[^\"\n]*\"|\'[^\'\n]*\'
3401 'strings': [
3402 # apparently strings can be delimited by EOL if they are continued
3403 # in the next line
3404 (r'"[^"\n]*("|\n)', String.Double),
3405 (r"'[^'\n]*('|\n)", String.Single),
3406 ],
3407
3408 'nums': [
3409 (r'\d+(\s*|\.$|$)', Number.Integer),
3410 (r'[+-]?\d*\.\d+([eE][-+]?\d+)?', Number.Float),
3411 (r'[+-]?\d+\.\d*([eE][-+]?\d+)?', Number.Float),
3412 ],
3413 }
3414
3415
3416 class CobolFreeformatLexer(CobolLexer):
3417 """
3418 Lexer for Free format OpenCOBOL code.
3419
3420 *New in Pygments 1.6.*
3421 """
3422 name = 'COBOLFree'
3423 aliases = ['cobolfree']
3424 filenames = ['*.cbl', '*.CBL']
3425 mimetypes = []
3426 flags = re.IGNORECASE | re.MULTILINE
3427
3428 tokens = {
3429 'comment': [
3430 (r'(\*>.*\n|^\w*\*.*$)', Comment),
3431 ],
3432 }
3433
3434
3435 class LogosLexer(ObjectiveCppLexer):
3436 """
3437 For Logos + Objective-C source code with preprocessor directives.
3438
3439 *New in Pygments 1.6.*
3440 """
3441
3442 name = 'Logos'
3443 aliases = ['logos']
3444 filenames = ['*.x', '*.xi', '*.xm', '*.xmi']
3445 mimetypes = ['text/x-logos']
3446 priority = 0.25
3447
3448 tokens = {
3449 'statements': [
3450 (r'(%orig|%log)\b', Keyword),
3451 (r'(%c)\b(\()(\s*)([a-zA-Z$_][a-zA-Z0-9$_]*)(\s*)(\))',
3452 bygroups(Keyword, Punctuation, Text, Name.Class, Text, Punctuation)),
3453 (r'(%init)\b(\()',
3454 bygroups(Keyword, Punctuation), 'logos_init_directive'),
3455 (r'(%init)(?=\s*;)', bygroups(Keyword)),
3456 (r'(%hook|%group)(\s+)([a-zA-Z$_][a-zA-Z0-9$_]+)',
3457 bygroups(Keyword, Text, Name.Class), '#pop'),
3458 (r'(%subclass)(\s+)', bygroups(Keyword, Text),
3459 ('#pop', 'logos_classname')),
3460 inherit,
3461 ],
3462 'logos_init_directive' : [
3463 ('\s+', Text),
3464 (',', Punctuation, ('logos_init_directive', '#pop')),
3465 ('([a-zA-Z$_][a-zA-Z0-9$_]*)(\s*)(=)(\s*)([^);]*)',
3466 bygroups(Name.Class, Text, Punctuation, Text, Text)),
3467 ('([a-zA-Z$_][a-zA-Z0-9$_]*)', Name.Class),
3468 ('\)', Punctuation, '#pop'),
3469 ],
3470 'logos_classname' : [
3471 ('([a-zA-Z$_][a-zA-Z0-9$_]*)(\s*:\s*)([a-zA-Z$_][a-zA-Z0-9$_]*)?',
3472 bygroups(Name.Class, Text, Name.Class), '#pop'),
3473 ('([a-zA-Z$_][a-zA-Z0-9$_]*)', Name.Class, '#pop')
3474 ],
3475 'root': [
3476 (r'(%subclass)(\s+)', bygroups(Keyword, Text),
3477 'logos_classname'),
3478 (r'(%hook|%group)(\s+)([a-zA-Z$_][a-zA-Z0-9$_]+)',
3479 bygroups(Keyword, Text, Name.Class)),
3480 (r'(%config)(\s*\(\s*)(\w+)(\s*=\s*)(.*?)(\s*\)\s*)',
3481 bygroups(Keyword, Text, Name.Variable, Text, String, Text)),
3482 (r'(%ctor)(\s*)({)', bygroups(Keyword, Text, Punctuation),
3483 'function'),
3484 (r'(%new)(\s*)(\()(\s*.*?\s*)(\))',
3485 bygroups(Keyword, Text, Keyword, String, Keyword)),
3486 (r'(\s*)(%end)(\s*)', bygroups(Text, Keyword, Text)),
3487 inherit,
3488 ],
3489 }
3490
3491 _logos_keywords = re.compile(r'%(?:hook|ctor|init|c\()')
3492
3493 def analyse_text(text):
3494 if LogosLexer._logos_keywords.search(text):
3495 return 1.0
3496 return 0

eric ide

mercurial