1"""
2 pygments.lexers.c_like
3 ~~~~~~~~~~~~~~~~~~~~~~
4
5 Lexers for other C-like languages.
6
7 :copyright: Copyright 2006-2025 by the Pygments team, see AUTHORS.
8 :license: BSD, see LICENSE for details.
9"""
10
11import re
12
13from pygments.lexer import RegexLexer, include, bygroups, inherit, words, \
14 default
15from pygments.token import Text, Comment, Operator, Keyword, Name, String, \
16 Number, Punctuation, Whitespace
17
18from pygments.lexers.c_cpp import CLexer, CppLexer
19from pygments.lexers import _mql_builtins
20
21__all__ = ['PikeLexer', 'NesCLexer', 'ClayLexer', 'ECLexer', 'ValaLexer',
22 'CudaLexer', 'SwigLexer', 'MqlLexer', 'ArduinoLexer', 'CharmciLexer',
23 'OmgIdlLexer', 'PromelaLexer']
24
25
26class PikeLexer(CppLexer):
27 """
28 For `Pike <http://pike.lysator.liu.se/>`_ source code.
29 """
30 name = 'Pike'
31 aliases = ['pike']
32 filenames = ['*.pike', '*.pmod']
33 mimetypes = ['text/x-pike']
34 version_added = '2.0'
35
36 tokens = {
37 'statements': [
38 (words((
39 'catch', 'new', 'private', 'protected', 'public', 'gauge',
40 'throw', 'throws', 'class', 'interface', 'implement', 'abstract',
41 'extends', 'from', 'this', 'super', 'constant', 'final', 'static',
42 'import', 'use', 'extern', 'inline', 'proto', 'break', 'continue',
43 'if', 'else', 'for', 'while', 'do', 'switch', 'case', 'as', 'in',
44 'version', 'return', 'true', 'false', 'null',
45 '__VERSION__', '__MAJOR__', '__MINOR__', '__BUILD__', '__REAL_VERSION__',
46 '__REAL_MAJOR__', '__REAL_MINOR__', '__REAL_BUILD__', '__DATE__', '__TIME__',
47 '__FILE__', '__DIR__', '__LINE__', '__AUTO_BIGNUM__', '__NT__', '__PIKE__',
48 '__amigaos__', '_Pragma', 'static_assert', 'defined', 'sscanf'), suffix=r'\b'),
49 Keyword),
50 (r'(bool|int|long|float|short|double|char|string|object|void|mapping|'
51 r'array|multiset|program|function|lambda|mixed|'
52 r'[a-z_][a-z0-9_]*_t)\b',
53 Keyword.Type),
54 (r'(class)(\s+)', bygroups(Keyword, Whitespace), 'classname'),
55 (r'[~!%^&*+=|?:<>/@-]', Operator),
56 inherit,
57 ],
58 'classname': [
59 (r'[a-zA-Z_]\w*', Name.Class, '#pop'),
60 # template specification
61 (r'\s*(?=>)', Whitespace, '#pop'),
62 ],
63 }
64
65
66class NesCLexer(CLexer):
67 """
68 For `nesC <https://github.com/tinyos/nesc>`_ source code with preprocessor
69 directives.
70 """
71 name = 'nesC'
72 aliases = ['nesc']
73 filenames = ['*.nc']
74 mimetypes = ['text/x-nescsrc']
75 version_added = '2.0'
76
77 tokens = {
78 'statements': [
79 (words((
80 'abstract', 'as', 'async', 'atomic', 'call', 'command', 'component',
81 'components', 'configuration', 'event', 'extends', 'generic',
82 'implementation', 'includes', 'interface', 'module', 'new', 'norace',
83 'post', 'provides', 'signal', 'task', 'uses'), suffix=r'\b'),
84 Keyword),
85 (words(('nx_struct', 'nx_union', 'nx_int8_t', 'nx_int16_t', 'nx_int32_t',
86 'nx_int64_t', 'nx_uint8_t', 'nx_uint16_t', 'nx_uint32_t',
87 'nx_uint64_t'), suffix=r'\b'),
88 Keyword.Type),
89 inherit,
90 ],
91 }
92
93
94class ClayLexer(RegexLexer):
95 """
96 For Clay source.
97 """
98 name = 'Clay'
99 filenames = ['*.clay']
100 aliases = ['clay']
101 mimetypes = ['text/x-clay']
102 url = 'http://claylabs.com/clay'
103 version_added = '2.0'
104
105 tokens = {
106 'root': [
107 (r'\s+', Whitespace),
108 (r'//.*?$', Comment.Single),
109 (r'/(\\\n)?[*](.|\n)*?[*](\\\n)?/', Comment.Multiline),
110 (r'\b(public|private|import|as|record|variant|instance'
111 r'|define|overload|default|external|alias'
112 r'|rvalue|ref|forward|inline|noinline|forceinline'
113 r'|enum|var|and|or|not|if|else|goto|return|while'
114 r'|switch|case|break|continue|for|in|true|false|try|catch|throw'
115 r'|finally|onerror|staticassert|eval|when|newtype'
116 r'|__FILE__|__LINE__|__COLUMN__|__ARG__'
117 r')\b', Keyword),
118 (r'[~!%^&*+=|:<>/-]', Operator),
119 (r'[#(){}\[\],;.]', Punctuation),
120 (r'0x[0-9a-fA-F]+[LlUu]*', Number.Hex),
121 (r'\d+[LlUu]*', Number.Integer),
122 (r'\b(true|false)\b', Name.Builtin),
123 (r'(?i)[a-z_?][\w?]*', Name),
124 (r'"""', String, 'tdqs'),
125 (r'"', String, 'dqs'),
126 ],
127 'strings': [
128 (r'(?i)\\(x[0-9a-f]{2}|.)', String.Escape),
129 (r'[^\\"]+', String),
130 ],
131 'nl': [
132 (r'\n', String),
133 ],
134 'dqs': [
135 (r'"', String, '#pop'),
136 include('strings'),
137 ],
138 'tdqs': [
139 (r'"""', String, '#pop'),
140 include('strings'),
141 include('nl'),
142 ],
143 }
144
145
146class ECLexer(CLexer):
147 """
148 For eC source code with preprocessor directives.
149 """
150 name = 'eC'
151 aliases = ['ec']
152 filenames = ['*.ec', '*.eh']
153 mimetypes = ['text/x-echdr', 'text/x-ecsrc']
154 url = 'https://ec-lang.org'
155 version_added = '1.5'
156
157 tokens = {
158 'statements': [
159 (words((
160 'virtual', 'class', 'private', 'public', 'property', 'import',
161 'delete', 'new', 'new0', 'renew', 'renew0', 'define', 'get',
162 'set', 'remote', 'dllexport', 'dllimport', 'stdcall', 'subclass',
163 '__on_register_module', 'namespace', 'using', 'typed_object',
164 'any_object', 'incref', 'register', 'watch', 'stopwatching', 'firewatchers',
165 'watchable', 'class_designer', 'class_fixed', 'class_no_expansion', 'isset',
166 'class_default_property', 'property_category', 'class_data',
167 'class_property', 'thisclass', 'dbtable', 'dbindex',
168 'database_open', 'dbfield'), suffix=r'\b'), Keyword),
169 (words(('uint', 'uint16', 'uint32', 'uint64', 'bool', 'byte',
170 'unichar', 'int64'), suffix=r'\b'),
171 Keyword.Type),
172 (r'(class)(\s+)', bygroups(Keyword, Whitespace), 'classname'),
173 (r'(null|value|this)\b', Name.Builtin),
174 inherit,
175 ]
176 }
177
178
179class ValaLexer(RegexLexer):
180 """
181 For Vala source code with preprocessor directives.
182 """
183 name = 'Vala'
184 aliases = ['vala', 'vapi']
185 filenames = ['*.vala', '*.vapi']
186 mimetypes = ['text/x-vala']
187 url = 'https://vala.dev'
188 version_added = '1.1'
189
190 tokens = {
191 'whitespace': [
192 (r'^\s*#if\s+0', Comment.Preproc, 'if0'),
193 (r'\n', Whitespace),
194 (r'\s+', Whitespace),
195 (r'\\\n', Text), # line continuation
196 (r'//(\n|(.|\n)*?[^\\]\n)', Comment.Single),
197 (r'/(\\\n)?[*](.|\n)*?[*](\\\n)?/', Comment.Multiline),
198 ],
199 'statements': [
200 (r'[L@]?"', String, 'string'),
201 (r"L?'(\\.|\\[0-7]{1,3}|\\x[a-fA-F0-9]{1,2}|[^\\\'\n])'",
202 String.Char),
203 (r'(?s)""".*?"""', String), # verbatim strings
204 (r'(\d+\.\d*|\.\d+|\d+)[eE][+-]?\d+[lL]?', Number.Float),
205 (r'(\d+\.\d*|\.\d+|\d+[fF])[fF]?', Number.Float),
206 (r'0x[0-9a-fA-F]+[Ll]?', Number.Hex),
207 (r'0[0-7]+[Ll]?', Number.Oct),
208 (r'\d+[Ll]?', Number.Integer),
209 (r'[~!%^&*+=|?:<>/-]', Operator),
210 (r'(\[)(Compact|Immutable|(?:Boolean|Simple)Type)(\])',
211 bygroups(Punctuation, Name.Decorator, Punctuation)),
212 # TODO: "correctly" parse complex code attributes
213 (r'(\[)(CCode|(?:Integer|Floating)Type)',
214 bygroups(Punctuation, Name.Decorator)),
215 (r'[()\[\],.]', Punctuation),
216 (words((
217 'as', 'base', 'break', 'case', 'catch', 'construct', 'continue',
218 'default', 'delete', 'do', 'else', 'enum', 'finally', 'for',
219 'foreach', 'get', 'if', 'in', 'is', 'lock', 'new', 'out', 'params',
220 'return', 'set', 'sizeof', 'switch', 'this', 'throw', 'try',
221 'typeof', 'while', 'yield'), suffix=r'\b'),
222 Keyword),
223 (words((
224 'abstract', 'const', 'delegate', 'dynamic', 'ensures', 'extern',
225 'inline', 'internal', 'override', 'owned', 'private', 'protected',
226 'public', 'ref', 'requires', 'signal', 'static', 'throws', 'unowned',
227 'var', 'virtual', 'volatile', 'weak', 'yields'), suffix=r'\b'),
228 Keyword.Declaration),
229 (r'(namespace|using)(\s+)', bygroups(Keyword.Namespace, Whitespace),
230 'namespace'),
231 (r'(class|errordomain|interface|struct)(\s+)',
232 bygroups(Keyword.Declaration, Whitespace), 'class'),
233 (r'(\.)([a-zA-Z_]\w*)',
234 bygroups(Operator, Name.Attribute)),
235 # void is an actual keyword, others are in glib-2.0.vapi
236 (words((
237 'void', 'bool', 'char', 'double', 'float', 'int', 'int8', 'int16',
238 'int32', 'int64', 'long', 'short', 'size_t', 'ssize_t', 'string',
239 'time_t', 'uchar', 'uint', 'uint8', 'uint16', 'uint32', 'uint64',
240 'ulong', 'unichar', 'ushort'), suffix=r'\b'),
241 Keyword.Type),
242 (r'(true|false|null)\b', Name.Builtin),
243 (r'[a-zA-Z_]\w*', Name),
244 ],
245 'root': [
246 include('whitespace'),
247 default('statement'),
248 ],
249 'statement': [
250 include('whitespace'),
251 include('statements'),
252 ('[{}]', Punctuation),
253 (';', Punctuation, '#pop'),
254 ],
255 'string': [
256 (r'"', String, '#pop'),
257 (r'\\([\\abfnrtv"\']|x[a-fA-F0-9]{2,4}|[0-7]{1,3})', String.Escape),
258 (r'[^\\"\n]+', String), # all other characters
259 (r'\\\n', String), # line continuation
260 (r'\\', String), # stray backslash
261 ],
262 'if0': [
263 (r'^\s*#if.*?(?<!\\)\n', Comment.Preproc, '#push'),
264 (r'^\s*#el(?:se|if).*\n', Comment.Preproc, '#pop'),
265 (r'^\s*#endif.*?(?<!\\)\n', Comment.Preproc, '#pop'),
266 (r'.*?\n', Comment),
267 ],
268 'class': [
269 (r'[a-zA-Z_]\w*', Name.Class, '#pop')
270 ],
271 'namespace': [
272 (r'[a-zA-Z_][\w.]*', Name.Namespace, '#pop')
273 ],
274 }
275
276
277class CudaLexer(CLexer):
278 """
279 For NVIDIA CUDA™ source.
280 """
281 name = 'CUDA'
282 filenames = ['*.cu', '*.cuh']
283 aliases = ['cuda', 'cu']
284 mimetypes = ['text/x-cuda']
285 url = 'https://developer.nvidia.com/category/zone/cuda-zone'
286 version_added = '1.6'
287
288 function_qualifiers = {'__device__', '__global__', '__host__',
289 '__noinline__', '__forceinline__'}
290 variable_qualifiers = {'__device__', '__constant__', '__shared__',
291 '__restrict__'}
292 vector_types = {'char1', 'uchar1', 'char2', 'uchar2', 'char3', 'uchar3',
293 'char4', 'uchar4', 'short1', 'ushort1', 'short2', 'ushort2',
294 'short3', 'ushort3', 'short4', 'ushort4', 'int1', 'uint1',
295 'int2', 'uint2', 'int3', 'uint3', 'int4', 'uint4', 'long1',
296 'ulong1', 'long2', 'ulong2', 'long3', 'ulong3', 'long4',
297 'ulong4', 'longlong1', 'ulonglong1', 'longlong2',
298 'ulonglong2', 'float1', 'float2', 'float3', 'float4',
299 'double1', 'double2', 'dim3'}
300 variables = {'gridDim', 'blockIdx', 'blockDim', 'threadIdx', 'warpSize'}
301 functions = {'__threadfence_block', '__threadfence', '__threadfence_system',
302 '__syncthreads', '__syncthreads_count', '__syncthreads_and',
303 '__syncthreads_or'}
304 execution_confs = {'<<<', '>>>'}
305
306 def get_tokens_unprocessed(self, text, stack=('root',)):
307 for index, token, value in CLexer.get_tokens_unprocessed(self, text, stack):
308 if token is Name:
309 if value in self.variable_qualifiers:
310 token = Keyword.Type
311 elif value in self.vector_types:
312 token = Keyword.Type
313 elif value in self.variables:
314 token = Name.Builtin
315 elif value in self.execution_confs:
316 token = Keyword.Pseudo
317 elif value in self.function_qualifiers:
318 token = Keyword.Reserved
319 elif value in self.functions:
320 token = Name.Function
321 yield index, token, value
322
323
324class SwigLexer(CppLexer):
325 """
326 For `SWIG <http://www.swig.org/>`_ source code.
327 """
328 name = 'SWIG'
329 aliases = ['swig']
330 filenames = ['*.swg', '*.i']
331 mimetypes = ['text/swig']
332 version_added = '2.0'
333 priority = 0.04 # Lower than C/C++ and Objective C/C++
334
335 tokens = {
336 'root': [
337 # Match it here so it won't be matched as a function in the rest of root
338 (r'\$\**\&?\w+', Name),
339 inherit
340 ],
341 'statements': [
342 # SWIG directives
343 (r'(%[a-z_][a-z0-9_]*)', Name.Function),
344 # Special variables
345 (r'\$\**\&?\w+', Name),
346 # Stringification / additional preprocessor directives
347 (r'##*[a-zA-Z_]\w*', Comment.Preproc),
348 inherit,
349 ],
350 }
351
352 # This is a far from complete set of SWIG directives
353 swig_directives = {
354 # Most common directives
355 '%apply', '%define', '%director', '%enddef', '%exception', '%extend',
356 '%feature', '%fragment', '%ignore', '%immutable', '%import', '%include',
357 '%inline', '%insert', '%module', '%newobject', '%nspace', '%pragma',
358 '%rename', '%shared_ptr', '%template', '%typecheck', '%typemap',
359 # Less common directives
360 '%arg', '%attribute', '%bang', '%begin', '%callback', '%catches', '%clear',
361 '%constant', '%copyctor', '%csconst', '%csconstvalue', '%csenum',
362 '%csmethodmodifiers', '%csnothrowexception', '%default', '%defaultctor',
363 '%defaultdtor', '%defined', '%delete', '%delobject', '%descriptor',
364 '%exceptionclass', '%exceptionvar', '%extend_smart_pointer', '%fragments',
365 '%header', '%ifcplusplus', '%ignorewarn', '%implicit', '%implicitconv',
366 '%init', '%javaconst', '%javaconstvalue', '%javaenum', '%javaexception',
367 '%javamethodmodifiers', '%kwargs', '%luacode', '%mutable', '%naturalvar',
368 '%nestedworkaround', '%perlcode', '%pythonabc', '%pythonappend',
369 '%pythoncallback', '%pythoncode', '%pythondynamic', '%pythonmaybecall',
370 '%pythonnondynamic', '%pythonprepend', '%refobject', '%shadow', '%sizeof',
371 '%trackobjects', '%types', '%unrefobject', '%varargs', '%warn',
372 '%warnfilter'}
373
374 def analyse_text(text):
375 rv = 0
376 # Search for SWIG directives, which are conventionally at the beginning of
377 # a line. The probability of them being within a line is low, so let another
378 # lexer win in this case.
379 matches = re.findall(r'^\s*(%[a-z_][a-z0-9_]*)', text, re.M)
380 for m in matches:
381 if m in SwigLexer.swig_directives:
382 rv = 0.98
383 break
384 else:
385 rv = 0.91 # Fraction higher than MatlabLexer
386 return rv
387
388
389class MqlLexer(CppLexer):
390 """
391 For `MQL4 <http://docs.mql4.com/>`_ and
392 `MQL5 <http://www.mql5.com/en/docs>`_ source code.
393 """
394 name = 'MQL'
395 aliases = ['mql', 'mq4', 'mq5', 'mql4', 'mql5']
396 filenames = ['*.mq4', '*.mq5', '*.mqh']
397 mimetypes = ['text/x-mql']
398 version_added = '2.0'
399
400 tokens = {
401 'statements': [
402 (words(_mql_builtins.keywords, suffix=r'\b'), Keyword),
403 (words(_mql_builtins.c_types, suffix=r'\b'), Keyword.Type),
404 (words(_mql_builtins.types, suffix=r'\b'), Name.Function),
405 (words(_mql_builtins.constants, suffix=r'\b'), Name.Constant),
406 (words(_mql_builtins.colors, prefix='(clr)?', suffix=r'\b'),
407 Name.Constant),
408 inherit,
409 ],
410 }
411
412
413class ArduinoLexer(CppLexer):
414 """
415 For `Arduino(tm) <https://arduino.cc/>`_ source.
416
417 This is an extension of the CppLexer, as the Arduino® Language is a superset
418 of C++
419 """
420
421 name = 'Arduino'
422 aliases = ['arduino']
423 filenames = ['*.ino']
424 mimetypes = ['text/x-arduino']
425 version_added = '2.1'
426
427 # Language sketch main structure functions
428 structure = {'setup', 'loop'}
429
430 # Language operators
431 operators = {'not', 'or', 'and', 'xor'}
432
433 # Language 'variables'
434 variables = {
435 'DIGITAL_MESSAGE', 'FIRMATA_STRING', 'ANALOG_MESSAGE', 'REPORT_DIGITAL',
436 'REPORT_ANALOG', 'INPUT_PULLUP', 'SET_PIN_MODE', 'INTERNAL2V56', 'SYSTEM_RESET',
437 'LED_BUILTIN', 'INTERNAL1V1', 'SYSEX_START', 'INTERNAL', 'EXTERNAL', 'HIGH',
438 'LOW', 'INPUT', 'OUTPUT', 'INPUT_PULLUP', 'LED_BUILTIN', 'true', 'false',
439 'void', 'boolean', 'char', 'unsigned char', 'byte', 'int', 'unsigned int',
440 'word', 'long', 'unsigned long', 'short', 'float', 'double', 'string', 'String',
441 'array', 'static', 'volatile', 'const', 'boolean', 'byte', 'word', 'string',
442 'String', 'array', 'int', 'float', 'private', 'char', 'virtual', 'operator',
443 'sizeof', 'uint8_t', 'uint16_t', 'uint32_t', 'uint64_t', 'int8_t', 'int16_t',
444 'int32_t', 'int64_t', 'dynamic_cast', 'typedef', 'const_cast', 'const',
445 'struct', 'static_cast', 'union', 'unsigned', 'long', 'volatile', 'static',
446 'protected', 'bool', 'public', 'friend', 'auto', 'void', 'enum', 'extern',
447 'class', 'short', 'reinterpret_cast', 'double', 'register', 'explicit',
448 'signed', 'inline', 'delete', '_Bool', 'complex', '_Complex', '_Imaginary',
449 'atomic_bool', 'atomic_char', 'atomic_schar', 'atomic_uchar', 'atomic_short',
450 'atomic_ushort', 'atomic_int', 'atomic_uint', 'atomic_long', 'atomic_ulong',
451 'atomic_llong', 'atomic_ullong', 'PROGMEM'}
452
453 # Language shipped functions and class ( )
454 functions = {
455 'KeyboardController', 'MouseController', 'SoftwareSerial', 'EthernetServer',
456 'EthernetClient', 'LiquidCrystal', 'RobotControl', 'GSMVoiceCall',
457 'EthernetUDP', 'EsploraTFT', 'HttpClient', 'RobotMotor', 'WiFiClient',
458 'GSMScanner', 'FileSystem', 'Scheduler', 'GSMServer', 'YunClient', 'YunServer',
459 'IPAddress', 'GSMClient', 'GSMModem', 'Keyboard', 'Ethernet', 'Console',
460 'GSMBand', 'Esplora', 'Stepper', 'Process', 'WiFiUDP', 'GSM_SMS', 'Mailbox',
461 'USBHost', 'Firmata', 'PImage', 'Client', 'Server', 'GSMPIN', 'FileIO',
462 'Bridge', 'Serial', 'EEPROM', 'Stream', 'Mouse', 'Audio', 'Servo', 'File',
463 'Task', 'GPRS', 'WiFi', 'Wire', 'TFT', 'GSM', 'SPI', 'SD',
464 'runShellCommandAsynchronously', 'analogWriteResolution',
465 'retrieveCallingNumber', 'printFirmwareVersion', 'analogReadResolution',
466 'sendDigitalPortPair', 'noListenOnLocalhost', 'readJoystickButton',
467 'setFirmwareVersion', 'readJoystickSwitch', 'scrollDisplayRight',
468 'getVoiceCallStatus', 'scrollDisplayLeft', 'writeMicroseconds',
469 'delayMicroseconds', 'beginTransmission', 'getSignalStrength',
470 'runAsynchronously', 'getAsynchronously', 'listenOnLocalhost',
471 'getCurrentCarrier', 'readAccelerometer', 'messageAvailable',
472 'sendDigitalPorts', 'lineFollowConfig', 'countryNameWrite', 'runShellCommand',
473 'readStringUntil', 'rewindDirectory', 'readTemperature', 'setClockDivider',
474 'readLightSensor', 'endTransmission', 'analogReference', 'detachInterrupt',
475 'countryNameRead', 'attachInterrupt', 'encryptionType', 'readBytesUntil',
476 'robotNameWrite', 'readMicrophone', 'robotNameRead', 'cityNameWrite',
477 'userNameWrite', 'readJoystickY', 'readJoystickX', 'mouseReleased',
478 'openNextFile', 'scanNetworks', 'noInterrupts', 'digitalWrite', 'beginSpeaker',
479 'mousePressed', 'isActionDone', 'mouseDragged', 'displayLogos', 'noAutoscroll',
480 'addParameter', 'remoteNumber', 'getModifiers', 'keyboardRead', 'userNameRead',
481 'waitContinue', 'processInput', 'parseCommand', 'printVersion', 'readNetworks',
482 'writeMessage', 'blinkVersion', 'cityNameRead', 'readMessage', 'setDataMode',
483 'parsePacket', 'isListening', 'setBitOrder', 'beginPacket', 'isDirectory',
484 'motorsWrite', 'drawCompass', 'digitalRead', 'clearScreen', 'serialEvent',
485 'rightToLeft', 'setTextSize', 'leftToRight', 'requestFrom', 'keyReleased',
486 'compassRead', 'analogWrite', 'interrupts', 'WiFiServer', 'disconnect',
487 'playMelody', 'parseFloat', 'autoscroll', 'getPINUsed', 'setPINUsed',
488 'setTimeout', 'sendAnalog', 'readSlider', 'analogRead', 'beginWrite',
489 'createChar', 'motorsStop', 'keyPressed', 'tempoWrite', 'readButton',
490 'subnetMask', 'debugPrint', 'macAddress', 'writeGreen', 'randomSeed',
491 'attachGPRS', 'readString', 'sendString', 'remotePort', 'releaseAll',
492 'mouseMoved', 'background', 'getXChange', 'getYChange', 'answerCall',
493 'getResult', 'voiceCall', 'endPacket', 'constrain', 'getSocket', 'writeJSON',
494 'getButton', 'available', 'connected', 'findUntil', 'readBytes', 'exitValue',
495 'readGreen', 'writeBlue', 'startLoop', 'IPAddress', 'isPressed', 'sendSysex',
496 'pauseMode', 'gatewayIP', 'setCursor', 'getOemKey', 'tuneWrite', 'noDisplay',
497 'loadImage', 'switchPIN', 'onRequest', 'onReceive', 'changePIN', 'playFile',
498 'noBuffer', 'parseInt', 'overflow', 'checkPIN', 'knobRead', 'beginTFT',
499 'bitClear', 'updateIR', 'bitWrite', 'position', 'writeRGB', 'highByte',
500 'writeRed', 'setSpeed', 'readBlue', 'noStroke', 'remoteIP', 'transfer',
501 'shutdown', 'hangCall', 'beginSMS', 'endWrite', 'attached', 'maintain',
502 'noCursor', 'checkReg', 'checkPUK', 'shiftOut', 'isValid', 'shiftIn', 'pulseIn',
503 'connect', 'println', 'localIP', 'pinMode', 'getIMEI', 'display', 'noBlink',
504 'process', 'getBand', 'running', 'beginSD', 'drawBMP', 'lowByte', 'setBand',
505 'release', 'bitRead', 'prepare', 'pointTo', 'readRed', 'setMode', 'noFill',
506 'remove', 'listen', 'stroke', 'detach', 'attach', 'noTone', 'exists', 'buffer',
507 'height', 'bitSet', 'circle', 'config', 'cursor', 'random', 'IRread', 'setDNS',
508 'endSMS', 'getKey', 'micros', 'millis', 'begin', 'print', 'write', 'ready',
509 'flush', 'width', 'isPIN', 'blink', 'clear', 'press', 'mkdir', 'rmdir', 'close',
510 'point', 'yield', 'image', 'BSSID', 'click', 'delay', 'read', 'text', 'move',
511 'peek', 'beep', 'rect', 'line', 'open', 'seek', 'fill', 'size', 'turn', 'stop',
512 'home', 'find', 'step', 'tone', 'sqrt', 'RSSI', 'SSID', 'end', 'bit', 'tan',
513 'cos', 'sin', 'pow', 'map', 'abs', 'max', 'min', 'get', 'run', 'put',
514 'isAlphaNumeric', 'isAlpha', 'isAscii', 'isWhitespace', 'isControl', 'isDigit',
515 'isGraph', 'isLowerCase', 'isPrintable', 'isPunct', 'isSpace', 'isUpperCase',
516 'isHexadecimalDigit'}
517
518 # do not highlight
519 suppress_highlight = {
520 'namespace', 'template', 'mutable', 'using', 'asm', 'typeid',
521 'typename', 'this', 'alignof', 'constexpr', 'decltype', 'noexcept',
522 'static_assert', 'thread_local', 'restrict'}
523
524 def get_tokens_unprocessed(self, text, stack=('root',)):
525 for index, token, value in CppLexer.get_tokens_unprocessed(self, text, stack):
526 if value in self.structure:
527 yield index, Name.Builtin, value
528 elif value in self.operators:
529 yield index, Operator, value
530 elif value in self.variables:
531 yield index, Keyword.Reserved, value
532 elif value in self.suppress_highlight:
533 yield index, Name, value
534 elif value in self.functions:
535 yield index, Name.Function, value
536 else:
537 yield index, token, value
538
539
540class CharmciLexer(CppLexer):
541 """
542 For `Charm++ <https://charm.cs.illinois.edu>`_ interface files (.ci).
543 """
544
545 name = 'Charmci'
546 aliases = ['charmci']
547 filenames = ['*.ci']
548 version_added = '2.4'
549
550 mimetypes = []
551
552 tokens = {
553 'keywords': [
554 (r'(module)(\s+)', bygroups(Keyword, Text), 'classname'),
555 (words(('mainmodule', 'mainchare', 'chare', 'array', 'group',
556 'nodegroup', 'message', 'conditional')), Keyword),
557 (words(('entry', 'aggregate', 'threaded', 'sync', 'exclusive',
558 'nokeep', 'notrace', 'immediate', 'expedited', 'inline',
559 'local', 'python', 'accel', 'readwrite', 'writeonly',
560 'accelblock', 'memcritical', 'packed', 'varsize',
561 'initproc', 'initnode', 'initcall', 'stacksize',
562 'createhere', 'createhome', 'reductiontarget', 'iget',
563 'nocopy', 'mutable', 'migratable', 'readonly')), Keyword),
564 inherit,
565 ],
566 }
567
568
569class OmgIdlLexer(CLexer):
570 """
571 Lexer for Object Management Group Interface Definition Language.
572 """
573
574 name = 'OMG Interface Definition Language'
575 url = 'https://www.omg.org/spec/IDL/About-IDL/'
576 aliases = ['omg-idl']
577 filenames = ['*.idl', '*.pidl']
578 mimetypes = []
579 version_added = '2.9'
580
581 scoped_name = r'((::)?\w+)+'
582
583 tokens = {
584 'values': [
585 (words(('true', 'false'), prefix=r'(?i)', suffix=r'\b'), Number),
586 (r'([Ll]?)(")', bygroups(String.Affix, String.Double), 'string'),
587 (r'([Ll]?)(\')(\\[^\']+)(\')',
588 bygroups(String.Affix, String.Char, String.Escape, String.Char)),
589 (r'([Ll]?)(\')(\\\')(\')',
590 bygroups(String.Affix, String.Char, String.Escape, String.Char)),
591 (r'([Ll]?)(\'.\')', bygroups(String.Affix, String.Char)),
592 (r'[+-]?\d+(\.\d*)?[Ee][+-]?\d+', Number.Float),
593 (r'[+-]?(\d+\.\d*)|(\d*\.\d+)([Ee][+-]?\d+)?', Number.Float),
594 (r'(?i)[+-]?0x[0-9a-f]+', Number.Hex),
595 (r'[+-]?[1-9]\d*', Number.Integer),
596 (r'[+-]?0[0-7]*', Number.Oct),
597 (r'[\+\-\*\/%^&\|~]', Operator),
598 (words(('<<', '>>')), Operator),
599 (scoped_name, Name),
600 (r'[{};:,<>\[\]]', Punctuation),
601 ],
602 'annotation_params': [
603 include('whitespace'),
604 (r'\(', Punctuation, '#push'),
605 include('values'),
606 (r'=', Punctuation),
607 (r'\)', Punctuation, '#pop'),
608 ],
609 'annotation_params_maybe': [
610 (r'\(', Punctuation, 'annotation_params'),
611 include('whitespace'),
612 default('#pop'),
613 ],
614 'annotation_appl': [
615 (r'@' + scoped_name, Name.Decorator, 'annotation_params_maybe'),
616 ],
617 'enum': [
618 include('whitespace'),
619 (r'[{,]', Punctuation),
620 (r'\w+', Name.Constant),
621 include('annotation_appl'),
622 (r'\}', Punctuation, '#pop'),
623 ],
624 'root': [
625 include('whitespace'),
626 (words((
627 'typedef', 'const',
628 'in', 'out', 'inout', 'local',
629 ), prefix=r'(?i)', suffix=r'\b'), Keyword.Declaration),
630 (words((
631 'void', 'any', 'native', 'bitfield',
632 'unsigned', 'boolean', 'char', 'wchar', 'octet', 'short', 'long',
633 'int8', 'uint8', 'int16', 'int32', 'int64', 'uint16', 'uint32', 'uint64',
634 'float', 'double', 'fixed',
635 'sequence', 'string', 'wstring', 'map',
636 ), prefix=r'(?i)', suffix=r'\b'), Keyword.Type),
637 (words((
638 '@annotation', 'struct', 'union', 'bitset', 'interface',
639 'exception', 'valuetype', 'eventtype', 'component',
640 ), prefix=r'(?i)', suffix=r'(\s+)(\w+)'), bygroups(Keyword, Whitespace, Name.Class)),
641 (words((
642 'abstract', 'alias', 'attribute', 'case', 'connector',
643 'consumes', 'context', 'custom', 'default', 'emits', 'factory',
644 'finder', 'getraises', 'home', 'import', 'manages', 'mirrorport',
645 'multiple', 'Object', 'oneway', 'primarykey', 'private', 'port',
646 'porttype', 'provides', 'public', 'publishes', 'raises',
647 'readonly', 'setraises', 'supports', 'switch', 'truncatable',
648 'typeid', 'typename', 'typeprefix', 'uses', 'ValueBase',
649 ), prefix=r'(?i)', suffix=r'\b'), Keyword),
650 (r'(?i)(enum|bitmask)(\s+)(\w+)',
651 bygroups(Keyword, Whitespace, Name.Class), 'enum'),
652 (r'(?i)(module)(\s+)(\w+)',
653 bygroups(Keyword.Namespace, Whitespace, Name.Namespace)),
654 (r'(\w+)(\s*)(=)', bygroups(Name.Constant, Whitespace, Operator)),
655 (r'[\(\)]', Punctuation),
656 include('values'),
657 include('annotation_appl'),
658 ],
659 }
660
661
662class PromelaLexer(CLexer):
663 """
664 For the Promela language used with SPIN.
665 """
666
667 name = 'Promela'
668 aliases = ['promela']
669 filenames = ['*.pml', '*.prom', '*.prm', '*.promela', '*.pr', '*.pm']
670 mimetypes = ['text/x-promela']
671 url = 'https://spinroot.com/spin/whatispin.html'
672 version_added = '2.18'
673
674 # Promela's language reference:
675 # https://spinroot.com/spin/Man/promela.html
676 # Promela's grammar definition:
677 # https://spinroot.com/spin/Man/grammar.html
678
679 tokens = {
680 'statements': [
681 (r'(\[\]|<>|/\\|\\/)|(U|W|V)\b', Operator), # LTL Operators
682 (r'@', Punctuation), #remoterefs
683 (r'(\.)([a-zA-Z_]\w*)', bygroups(Operator, Name.Attribute)),
684 inherit
685 ],
686 'types': [
687 # Predefined (data types)
688 (words((
689 'bit', 'bool', 'byte', 'pid', 'short', 'int', 'unsigned'),
690 suffix=r'\b'),
691 Keyword.Type),
692 ],
693 'keywords': [
694 # ControlFlow
695 (words((
696 'atomic', 'break', 'd_step', 'do', 'od', 'for', 'in', 'goto',
697 'if', 'fi', 'unless'), suffix=r'\b'),
698 Keyword),
699 # BasicStatements
700 (words((
701 'assert', 'get_priority', 'printf', 'printm', 'set_priority'),
702 suffix=r'\b'),
703 Name.Function),
704 # Embedded C Code
705 (words((
706 'c_code', 'c_decl', 'c_expr', 'c_state', 'c_track'),
707 suffix=r'\b'),
708 Keyword),
709 # Predefined (local/global variables)
710 (words((
711 '_', '_last', '_nr_pr', '_pid', '_priority', 'else', 'np_',
712 'STDIN'), suffix=r'\b'),
713 Name.Builtin),
714 # Predefined (functions)
715 (words((
716 'empty', 'enabled', 'eval', 'full', 'len', 'nempty', 'nfull',
717 'pc_value'), suffix=r'\b'),
718 Name.Function),
719 # Predefined (operators)
720 (r'run\b', Operator.Word),
721 # Declarators
722 (words((
723 'active', 'chan', 'D_proctype', 'hidden', 'init', 'local',
724 'mtype', 'never', 'notrace', 'proctype', 'show', 'trace',
725 'typedef', 'xr', 'xs'), suffix=r'\b'),
726 Keyword.Declaration),
727 # Declarators (suffixes)
728 (words((
729 'priority', 'provided'), suffix=r'\b'),
730 Keyword),
731 # MetaTerms (declarators)
732 (words((
733 'inline', 'ltl', 'select'), suffix=r'\b'),
734 Keyword.Declaration),
735 # MetaTerms (keywords)
736 (r'skip\b', Keyword),
737 ],
738 }