18 |
18 |
19 from pygments.lexers.c_cpp import CLexer, CppLexer |
19 from pygments.lexers.c_cpp import CLexer, CppLexer |
20 from pygments.lexers import _mql_builtins |
20 from pygments.lexers import _mql_builtins |
21 |
21 |
22 __all__ = ['PikeLexer', 'NesCLexer', 'ClayLexer', 'ECLexer', 'ValaLexer', |
22 __all__ = ['PikeLexer', 'NesCLexer', 'ClayLexer', 'ECLexer', 'ValaLexer', |
23 'CudaLexer', 'SwigLexer', 'MqlLexer', 'ArduinoLexer'] |
23 'CudaLexer', 'SwigLexer', 'MqlLexer', 'ArduinoLexer', 'CharmciLexer'] |
24 |
24 |
25 |
25 |
26 class PikeLexer(CppLexer): |
26 class PikeLexer(CppLexer): |
27 """ |
27 """ |
28 For `Pike <http://pike.lysator.liu.se/>`_ source code. |
28 For `Pike <http://pike.lysator.liu.se/>`_ source code. |
289 name = 'CUDA' |
289 name = 'CUDA' |
290 filenames = ['*.cu', '*.cuh'] |
290 filenames = ['*.cu', '*.cuh'] |
291 aliases = ['cuda', 'cu'] |
291 aliases = ['cuda', 'cu'] |
292 mimetypes = ['text/x-cuda'] |
292 mimetypes = ['text/x-cuda'] |
293 |
293 |
294 function_qualifiers = set(('__device__', '__global__', '__host__', |
294 function_qualifiers = {'__device__', '__global__', '__host__', |
295 '__noinline__', '__forceinline__')) |
295 '__noinline__', '__forceinline__'} |
296 variable_qualifiers = set(('__device__', '__constant__', '__shared__', |
296 variable_qualifiers = {'__device__', '__constant__', '__shared__', |
297 '__restrict__')) |
297 '__restrict__'} |
298 vector_types = set(('char1', 'uchar1', 'char2', 'uchar2', 'char3', 'uchar3', |
298 vector_types = {'char1', 'uchar1', 'char2', 'uchar2', 'char3', 'uchar3', |
299 'char4', 'uchar4', 'short1', 'ushort1', 'short2', 'ushort2', |
299 'char4', 'uchar4', 'short1', 'ushort1', 'short2', 'ushort2', |
300 'short3', 'ushort3', 'short4', 'ushort4', 'int1', 'uint1', |
300 'short3', 'ushort3', 'short4', 'ushort4', 'int1', 'uint1', |
301 'int2', 'uint2', 'int3', 'uint3', 'int4', 'uint4', 'long1', |
301 'int2', 'uint2', 'int3', 'uint3', 'int4', 'uint4', 'long1', |
302 'ulong1', 'long2', 'ulong2', 'long3', 'ulong3', 'long4', |
302 'ulong1', 'long2', 'ulong2', 'long3', 'ulong3', 'long4', |
303 'ulong4', 'longlong1', 'ulonglong1', 'longlong2', |
303 'ulong4', 'longlong1', 'ulonglong1', 'longlong2', |
304 'ulonglong2', 'float1', 'float2', 'float3', 'float4', |
304 'ulonglong2', 'float1', 'float2', 'float3', 'float4', |
305 'double1', 'double2', 'dim3')) |
305 'double1', 'double2', 'dim3'} |
306 variables = set(('gridDim', 'blockIdx', 'blockDim', 'threadIdx', 'warpSize')) |
306 variables = {'gridDim', 'blockIdx', 'blockDim', 'threadIdx', 'warpSize'} |
307 functions = set(('__threadfence_block', '__threadfence', '__threadfence_system', |
307 functions = {'__threadfence_block', '__threadfence', '__threadfence_system', |
308 '__syncthreads', '__syncthreads_count', '__syncthreads_and', |
308 '__syncthreads', '__syncthreads_count', '__syncthreads_and', |
309 '__syncthreads_or')) |
309 '__syncthreads_or'} |
310 execution_confs = set(('<<<', '>>>')) |
310 execution_confs = {'<<<', '>>>'} |
311 |
311 |
312 def get_tokens_unprocessed(self, text): |
312 def get_tokens_unprocessed(self, text): |
313 for index, token, value in CLexer.get_tokens_unprocessed(self, text): |
313 for index, token, value in CLexer.get_tokens_unprocessed(self, text): |
314 if token is Name: |
314 if token is Name: |
315 if value in self.variable_qualifiers: |
315 if value in self.variable_qualifiers: |
350 inherit, |
350 inherit, |
351 ], |
351 ], |
352 } |
352 } |
353 |
353 |
354 # This is a far from complete set of SWIG directives |
354 # This is a far from complete set of SWIG directives |
355 swig_directives = set(( |
355 swig_directives = { |
356 # Most common directives |
356 # Most common directives |
357 '%apply', '%define', '%director', '%enddef', '%exception', '%extend', |
357 '%apply', '%define', '%director', '%enddef', '%exception', '%extend', |
358 '%feature', '%fragment', '%ignore', '%immutable', '%import', '%include', |
358 '%feature', '%fragment', '%ignore', '%immutable', '%import', '%include', |
359 '%inline', '%insert', '%module', '%newobject', '%nspace', '%pragma', |
359 '%inline', '%insert', '%module', '%newobject', '%nspace', '%pragma', |
360 '%rename', '%shared_ptr', '%template', '%typecheck', '%typemap', |
360 '%rename', '%shared_ptr', '%template', '%typecheck', '%typemap', |
369 '%javamethodmodifiers', '%kwargs', '%luacode', '%mutable', '%naturalvar', |
369 '%javamethodmodifiers', '%kwargs', '%luacode', '%mutable', '%naturalvar', |
370 '%nestedworkaround', '%perlcode', '%pythonabc', '%pythonappend', |
370 '%nestedworkaround', '%perlcode', '%pythonabc', '%pythonappend', |
371 '%pythoncallback', '%pythoncode', '%pythondynamic', '%pythonmaybecall', |
371 '%pythoncallback', '%pythoncode', '%pythondynamic', '%pythonmaybecall', |
372 '%pythonnondynamic', '%pythonprepend', '%refobject', '%shadow', '%sizeof', |
372 '%pythonnondynamic', '%pythonprepend', '%refobject', '%shadow', '%sizeof', |
373 '%trackobjects', '%types', '%unrefobject', '%varargs', '%warn', |
373 '%trackobjects', '%types', '%unrefobject', '%varargs', '%warn', |
374 '%warnfilter')) |
374 '%warnfilter'} |
375 |
375 |
376 def analyse_text(text): |
376 def analyse_text(text): |
377 rv = 0 |
377 rv = 0 |
378 # Search for SWIG directives, which are conventionally at the beginning of |
378 # Search for SWIG directives, which are conventionally at the beginning of |
379 # a line. The probability of them being within a line is low, so let another |
379 # a line. The probability of them being within a line is low, so let another |
426 aliases = ['arduino'] |
427 aliases = ['arduino'] |
427 filenames = ['*.ino'] |
428 filenames = ['*.ino'] |
428 mimetypes = ['text/x-arduino'] |
429 mimetypes = ['text/x-arduino'] |
429 |
430 |
430 # Language sketch main structure functions |
431 # Language sketch main structure functions |
431 structure = set(('setup', 'loop')) |
432 structure = {'setup', 'loop'} |
432 |
433 |
433 # Language operators |
434 # Language operators |
434 operators = set(('not', 'or', 'and', 'xor')) |
435 operators = {'not', 'or', 'and', 'xor'} |
435 |
436 |
436 # Language 'variables' |
437 # Language 'variables' |
437 variables = set(( |
438 variables = { |
438 'DIGITAL_MESSAGE', 'FIRMATA_STRING', 'ANALOG_MESSAGE', 'REPORT_DIGITAL', |
439 'DIGITAL_MESSAGE', 'FIRMATA_STRING', 'ANALOG_MESSAGE', 'REPORT_DIGITAL', |
439 'REPORT_ANALOG', 'INPUT_PULLUP', 'SET_PIN_MODE', 'INTERNAL2V56', 'SYSTEM_RESET', |
440 'REPORT_ANALOG', 'INPUT_PULLUP', 'SET_PIN_MODE', 'INTERNAL2V56', 'SYSTEM_RESET', |
440 'LED_BUILTIN', 'INTERNAL1V1', 'SYSEX_START', 'INTERNAL', 'EXTERNAL', 'HIGH', |
441 'LED_BUILTIN', 'INTERNAL1V1', 'SYSEX_START', 'INTERNAL', 'EXTERNAL', 'HIGH', |
441 'LOW', 'INPUT', 'OUTPUT', 'INPUT_PULLUP', 'LED_BUILTIN', 'true', 'false', |
442 'LOW', 'INPUT', 'OUTPUT', 'INPUT_PULLUP', 'LED_BUILTIN', 'true', 'false', |
442 'void', 'boolean', 'char', 'unsigned char', 'byte', 'int', 'unsigned int', |
443 'void', 'boolean', 'char', 'unsigned char', 'byte', 'int', 'unsigned int', |
449 'protected', 'bool', 'public', 'friend', 'auto', 'void', 'enum', 'extern', |
450 'protected', 'bool', 'public', 'friend', 'auto', 'void', 'enum', 'extern', |
450 'class', 'short', 'reinterpret_cast', 'double', 'register', 'explicit', |
451 'class', 'short', 'reinterpret_cast', 'double', 'register', 'explicit', |
451 'signed', 'inline', 'delete', '_Bool', 'complex', '_Complex', '_Imaginary', |
452 'signed', 'inline', 'delete', '_Bool', 'complex', '_Complex', '_Imaginary', |
452 'atomic_bool', 'atomic_char', 'atomic_schar', 'atomic_uchar', 'atomic_short', |
453 'atomic_bool', 'atomic_char', 'atomic_schar', 'atomic_uchar', 'atomic_short', |
453 'atomic_ushort', 'atomic_int', 'atomic_uint', 'atomic_long', 'atomic_ulong', |
454 'atomic_ushort', 'atomic_int', 'atomic_uint', 'atomic_long', 'atomic_ulong', |
454 'atomic_llong', 'atomic_ullong', 'PROGMEM')) |
455 'atomic_llong', 'atomic_ullong', 'PROGMEM'} |
455 |
456 |
456 # Language shipped functions and class ( ) |
457 # Language shipped functions and class ( ) |
457 functions = set(( |
458 functions = { |
458 'KeyboardController', 'MouseController', 'SoftwareSerial', 'EthernetServer', |
459 'KeyboardController', 'MouseController', 'SoftwareSerial', 'EthernetServer', |
459 'EthernetClient', 'LiquidCrystal', 'RobotControl', 'GSMVoiceCall', |
460 'EthernetClient', 'LiquidCrystal', 'RobotControl', 'GSMVoiceCall', |
460 'EthernetUDP', 'EsploraTFT', 'HttpClient', 'RobotMotor', 'WiFiClient', |
461 'EthernetUDP', 'EsploraTFT', 'HttpClient', 'RobotMotor', 'WiFiClient', |
461 'GSMScanner', 'FileSystem', 'Scheduler', 'GSMServer', 'YunClient', 'YunServer', |
462 'GSMScanner', 'FileSystem', 'Scheduler', 'GSMServer', 'YunClient', 'YunServer', |
462 'IPAddress', 'GSMClient', 'GSMModem', 'Keyboard', 'Ethernet', 'Console', |
463 'IPAddress', 'GSMClient', 'GSMModem', 'Keyboard', 'Ethernet', 'Console', |
512 'flush', 'width', 'isPIN', 'blink', 'clear', 'press', 'mkdir', 'rmdir', 'close', |
513 'flush', 'width', 'isPIN', 'blink', 'clear', 'press', 'mkdir', 'rmdir', 'close', |
513 'point', 'yield', 'image', 'BSSID', 'click', 'delay', 'read', 'text', 'move', |
514 'point', 'yield', 'image', 'BSSID', 'click', 'delay', 'read', 'text', 'move', |
514 'peek', 'beep', 'rect', 'line', 'open', 'seek', 'fill', 'size', 'turn', 'stop', |
515 'peek', 'beep', 'rect', 'line', 'open', 'seek', 'fill', 'size', 'turn', 'stop', |
515 'home', 'find', 'step', 'tone', 'sqrt', 'RSSI', 'SSID', 'end', 'bit', 'tan', |
516 'home', 'find', 'step', 'tone', 'sqrt', 'RSSI', 'SSID', 'end', 'bit', 'tan', |
516 'cos', 'sin', 'pow', 'map', 'abs', 'max', 'min', 'get', 'run', 'put', |
517 'cos', 'sin', 'pow', 'map', 'abs', 'max', 'min', 'get', 'run', 'put', |
517 'isAlphaNumeric', 'isAlpha', 'isAscii', 'isWhitespace', 'isControl', 'isDigit', |
518 'isAlphaNumeric', 'isAlpha', 'isAscii', 'isWhitespace', 'isControl', 'isDigit', |
518 'isGraph', 'isLowerCase', 'isPrintable', 'isPunct', 'isSpace', 'isUpperCase', |
519 'isGraph', 'isLowerCase', 'isPrintable', 'isPunct', 'isSpace', 'isUpperCase', |
519 'isHexadecimalDigit')) |
520 'isHexadecimalDigit'} |
520 |
521 |
521 # do not highlight |
522 # do not highlight |
522 suppress_highlight = set(( |
523 suppress_highlight = { |
523 'namespace', 'template', 'mutable', 'using', 'asm', 'typeid', |
524 'namespace', 'template', 'mutable', 'using', 'asm', 'typeid', |
524 'typename', 'this', 'alignof', 'constexpr', 'decltype', 'noexcept', |
525 'typename', 'this', 'alignof', 'constexpr', 'decltype', 'noexcept', |
525 'static_assert', 'thread_local', 'restrict')) |
526 'static_assert', 'thread_local', 'restrict'} |
526 |
|
527 |
527 |
528 def get_tokens_unprocessed(self, text): |
528 def get_tokens_unprocessed(self, text): |
529 for index, token, value in CppLexer.get_tokens_unprocessed(self, text): |
529 for index, token, value in CppLexer.get_tokens_unprocessed(self, text): |
530 if value in self.structure: |
530 if value in self.structure: |
531 yield index, Name.Builtin, value |
531 yield index, Name.Builtin, value |
537 yield index, Name, value |
537 yield index, Name, value |
538 elif value in self.functions: |
538 elif value in self.functions: |
539 yield index, Name.Function, value |
539 yield index, Name.Function, value |
540 else: |
540 else: |
541 yield index, token, value |
541 yield index, token, value |
|
542 |
|
543 |
|
544 class CharmciLexer(CppLexer): |
|
545 """ |
|
546 For `Charm++ <https://charm.cs.illinois.edu>`_ interface files (.ci). |
|
547 |
|
548 .. versionadded:: 2.4 |
|
549 """ |
|
550 |
|
551 name = 'Charmci' |
|
552 aliases = ['charmci'] |
|
553 filenames = ['*.ci'] |
|
554 |
|
555 mimetypes = [] |
|
556 |
|
557 tokens = { |
|
558 'statements': [ |
|
559 (r'(module)(\s+)', bygroups(Keyword, Text), 'classname'), |
|
560 (words(('mainmodule', 'mainchare', 'chare', 'array', 'group', |
|
561 'nodegroup', 'message', 'conditional')), Keyword), |
|
562 (words(('entry', 'aggregate', 'threaded', 'sync', 'exclusive', |
|
563 'nokeep', 'notrace', 'immediate', 'expedited', 'inline', |
|
564 'local', 'python', 'accel', 'readwrite', 'writeonly', |
|
565 'accelblock', 'memcritical', 'packed', 'varsize', |
|
566 'initproc', 'initnode', 'initcall', 'stacksize', |
|
567 'createhere', 'createhome', 'reductiontarget', 'iget', |
|
568 'nocopy', 'mutable', 'migratable', 'readonly')), Keyword), |
|
569 inherit, |
|
570 ], |
|
571 } |