c_like.py 24 KB

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