c_like.py 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664
  1. """
  2. pygments.lexers.c_like
  3. ~~~~~~~~~~~~~~~~~~~~~~
  4. Lexers for other C-like languages.
  5. :copyright: Copyright 2006-2021 by the Pygments team, see AUTHORS.
  6. :license: BSD, see LICENSE for details.
  7. """
  8. import re
  9. from pygments.lexer import RegexLexer, include, bygroups, inherit, words, \
  10. default
  11. from pygments.token import Text, Comment, Operator, Keyword, Name, String, \
  12. Number, Punctuation, Whitespace
  13. from pygments.lexers.c_cpp import CLexer, CppLexer
  14. from pygments.lexers import _mql_builtins
  15. __all__ = ['PikeLexer', 'NesCLexer', 'ClayLexer', 'ECLexer', 'ValaLexer',
  16. 'CudaLexer', 'SwigLexer', 'MqlLexer', 'ArduinoLexer', 'CharmciLexer',
  17. 'OmgIdlLexer']
  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. }
  156. class ValaLexer(RegexLexer):
  157. """
  158. For Vala source code with preprocessor directives.
  159. .. versionadded:: 1.1
  160. """
  161. name = 'Vala'
  162. aliases = ['vala', 'vapi']
  163. filenames = ['*.vala', '*.vapi']
  164. mimetypes = ['text/x-vala']
  165. tokens = {
  166. 'whitespace': [
  167. (r'^\s*#if\s+0', Comment.Preproc, 'if0'),
  168. (r'\n', Text),
  169. (r'\s+', Text),
  170. (r'\\\n', Text), # line continuation
  171. (r'//(\n|(.|\n)*?[^\\]\n)', Comment.Single),
  172. (r'/(\\\n)?[*](.|\n)*?[*](\\\n)?/', Comment.Multiline),
  173. ],
  174. 'statements': [
  175. (r'[L@]?"', String, 'string'),
  176. (r"L?'(\\.|\\[0-7]{1,3}|\\x[a-fA-F0-9]{1,2}|[^\\\'\n])'",
  177. String.Char),
  178. (r'(?s)""".*?"""', String), # verbatim strings
  179. (r'(\d+\.\d*|\.\d+|\d+)[eE][+-]?\d+[lL]?', Number.Float),
  180. (r'(\d+\.\d*|\.\d+|\d+[fF])[fF]?', Number.Float),
  181. (r'0x[0-9a-fA-F]+[Ll]?', Number.Hex),
  182. (r'0[0-7]+[Ll]?', Number.Oct),
  183. (r'\d+[Ll]?', Number.Integer),
  184. (r'[~!%^&*+=|?:<>/-]', Operator),
  185. (r'(\[)(Compact|Immutable|(?:Boolean|Simple)Type)(\])',
  186. bygroups(Punctuation, Name.Decorator, Punctuation)),
  187. # TODO: "correctly" parse complex code attributes
  188. (r'(\[)(CCode|(?:Integer|Floating)Type)',
  189. bygroups(Punctuation, Name.Decorator)),
  190. (r'[()\[\],.]', Punctuation),
  191. (words((
  192. 'as', 'base', 'break', 'case', 'catch', 'construct', 'continue',
  193. 'default', 'delete', 'do', 'else', 'enum', 'finally', 'for',
  194. 'foreach', 'get', 'if', 'in', 'is', 'lock', 'new', 'out', 'params',
  195. 'return', 'set', 'sizeof', 'switch', 'this', 'throw', 'try',
  196. 'typeof', 'while', 'yield'), suffix=r'\b'),
  197. Keyword),
  198. (words((
  199. 'abstract', 'const', 'delegate', 'dynamic', 'ensures', 'extern',
  200. 'inline', 'internal', 'override', 'owned', 'private', 'protected',
  201. 'public', 'ref', 'requires', 'signal', 'static', 'throws', 'unowned',
  202. 'var', 'virtual', 'volatile', 'weak', 'yields'), suffix=r'\b'),
  203. Keyword.Declaration),
  204. (r'(namespace|using)(\s+)', bygroups(Keyword.Namespace, Text),
  205. 'namespace'),
  206. (r'(class|errordomain|interface|struct)(\s+)',
  207. bygroups(Keyword.Declaration, Text), 'class'),
  208. (r'(\.)([a-zA-Z_]\w*)',
  209. bygroups(Operator, Name.Attribute)),
  210. # void is an actual keyword, others are in glib-2.0.vapi
  211. (words((
  212. 'void', 'bool', 'char', 'double', 'float', 'int', 'int8', 'int16',
  213. 'int32', 'int64', 'long', 'short', 'size_t', 'ssize_t', 'string',
  214. 'time_t', 'uchar', 'uint', 'uint8', 'uint16', 'uint32', 'uint64',
  215. 'ulong', 'unichar', 'ushort'), suffix=r'\b'),
  216. Keyword.Type),
  217. (r'(true|false|null)\b', Name.Builtin),
  218. (r'[a-zA-Z_]\w*', Name),
  219. ],
  220. 'root': [
  221. include('whitespace'),
  222. default('statement'),
  223. ],
  224. 'statement': [
  225. include('whitespace'),
  226. include('statements'),
  227. ('[{}]', Punctuation),
  228. (';', Punctuation, '#pop'),
  229. ],
  230. 'string': [
  231. (r'"', String, '#pop'),
  232. (r'\\([\\abfnrtv"\']|x[a-fA-F0-9]{2,4}|[0-7]{1,3})', String.Escape),
  233. (r'[^\\"\n]+', String), # all other characters
  234. (r'\\\n', String), # line continuation
  235. (r'\\', String), # stray backslash
  236. ],
  237. 'if0': [
  238. (r'^\s*#if.*?(?<!\\)\n', Comment.Preproc, '#push'),
  239. (r'^\s*#el(?:se|if).*\n', Comment.Preproc, '#pop'),
  240. (r'^\s*#endif.*?(?<!\\)\n', Comment.Preproc, '#pop'),
  241. (r'.*?\n', Comment),
  242. ],
  243. 'class': [
  244. (r'[a-zA-Z_]\w*', Name.Class, '#pop')
  245. ],
  246. 'namespace': [
  247. (r'[a-zA-Z_][\w.]*', Name.Namespace, '#pop')
  248. ],
  249. }
  250. class CudaLexer(CLexer):
  251. """
  252. For NVIDIA `CUDA™ <http://developer.nvidia.com/category/zone/cuda-zone>`_
  253. source.
  254. .. versionadded:: 1.6
  255. """
  256. name = 'CUDA'
  257. filenames = ['*.cu', '*.cuh']
  258. aliases = ['cuda', 'cu']
  259. mimetypes = ['text/x-cuda']
  260. function_qualifiers = {'__device__', '__global__', '__host__',
  261. '__noinline__', '__forceinline__'}
  262. variable_qualifiers = {'__device__', '__constant__', '__shared__',
  263. '__restrict__'}
  264. vector_types = {'char1', 'uchar1', 'char2', 'uchar2', 'char3', 'uchar3',
  265. 'char4', 'uchar4', 'short1', 'ushort1', 'short2', 'ushort2',
  266. 'short3', 'ushort3', 'short4', 'ushort4', 'int1', 'uint1',
  267. 'int2', 'uint2', 'int3', 'uint3', 'int4', 'uint4', 'long1',
  268. 'ulong1', 'long2', 'ulong2', 'long3', 'ulong3', 'long4',
  269. 'ulong4', 'longlong1', 'ulonglong1', 'longlong2',
  270. 'ulonglong2', 'float1', 'float2', 'float3', 'float4',
  271. 'double1', 'double2', 'dim3'}
  272. variables = {'gridDim', 'blockIdx', 'blockDim', 'threadIdx', 'warpSize'}
  273. functions = {'__threadfence_block', '__threadfence', '__threadfence_system',
  274. '__syncthreads', '__syncthreads_count', '__syncthreads_and',
  275. '__syncthreads_or'}
  276. execution_confs = {'<<<', '>>>'}
  277. def get_tokens_unprocessed(self, text):
  278. for index, token, value in CLexer.get_tokens_unprocessed(self, text):
  279. if token is Name:
  280. if value in self.variable_qualifiers:
  281. token = Keyword.Type
  282. elif value in self.vector_types:
  283. token = Keyword.Type
  284. elif value in self.variables:
  285. token = Name.Builtin
  286. elif value in self.execution_confs:
  287. token = Keyword.Pseudo
  288. elif value in self.function_qualifiers:
  289. token = Keyword.Reserved
  290. elif value in self.functions:
  291. token = Name.Function
  292. yield index, token, value
  293. class SwigLexer(CppLexer):
  294. """
  295. For `SWIG <http://www.swig.org/>`_ source code.
  296. .. versionadded:: 2.0
  297. """
  298. name = 'SWIG'
  299. aliases = ['swig']
  300. filenames = ['*.swg', '*.i']
  301. mimetypes = ['text/swig']
  302. priority = 0.04 # Lower than C/C++ and Objective C/C++
  303. tokens = {
  304. 'root': [
  305. # Match it here so it won't be matched as a function in the rest of root
  306. (r'\$\**\&?\w+', Name),
  307. inherit
  308. ],
  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. 'keywords': [
  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. }
  515. class OmgIdlLexer(CLexer):
  516. """
  517. Lexer for `Object Management Group Interface Definition Language <https://www.omg.org/spec/IDL/About-IDL/>`_.
  518. .. versionadded:: 2.9
  519. """
  520. name = 'OMG Interface Definition Language'
  521. aliases = ['omg-idl']
  522. filenames = ['*.idl', '*.pidl']
  523. mimetypes = []
  524. scoped_name = r'((::)?\w+)+'
  525. tokens = {
  526. 'values': [
  527. (words(('true', 'false'), prefix=r'(?i)', suffix=r'\b'), Number),
  528. (r'([Ll]?)(")', bygroups(String.Affix, String.Double), 'string'),
  529. (r'([Ll]?)(\')(\\[^\']+)(\')',
  530. bygroups(String.Affix, String.Char, String.Escape, String.Char)),
  531. (r'([Ll]?)(\')(\\\')(\')',
  532. bygroups(String.Affix, String.Char, String.Escape, String.Char)),
  533. (r'([Ll]?)(\'.\')', bygroups(String.Affix, String.Char)),
  534. (r'[+-]?\d+(\.\d*)?[Ee][+-]?\d+', Number.Float),
  535. (r'[+-]?(\d+\.\d*)|(\d*\.\d+)([Ee][+-]?\d+)?', Number.Float),
  536. (r'(?i)[+-]?0x[0-9a-f]+', Number.Hex),
  537. (r'[+-]?[1-9]\d*', Number.Integer),
  538. (r'[+-]?0[0-7]*', Number.Oct),
  539. (r'[\+\-\*\/%^&\|~]', Operator),
  540. (words(('<<', '>>')), Operator),
  541. (scoped_name, Name),
  542. (r'[{};:,<>\[\]]', Punctuation),
  543. ],
  544. 'annotation_params': [
  545. include('whitespace'),
  546. (r'\(', Punctuation, '#push'),
  547. include('values'),
  548. (r'=', Punctuation),
  549. (r'\)', Punctuation, '#pop'),
  550. ],
  551. 'annotation_params_maybe': [
  552. (r'\(', Punctuation, 'annotation_params'),
  553. include('whitespace'),
  554. default('#pop'),
  555. ],
  556. 'annotation_appl': [
  557. (r'@' + scoped_name, Name.Decorator, 'annotation_params_maybe'),
  558. ],
  559. 'enum': [
  560. include('whitespace'),
  561. (r'[{,]', Punctuation),
  562. (r'\w+', Name.Constant),
  563. include('annotation_appl'),
  564. (r'\}', Punctuation, '#pop'),
  565. ],
  566. 'root': [
  567. include('whitespace'),
  568. (words((
  569. 'typedef', 'const',
  570. 'in', 'out', 'inout', 'local',
  571. ), prefix=r'(?i)', suffix=r'\b'), Keyword.Declaration),
  572. (words((
  573. 'void', 'any', 'native', 'bitfield',
  574. 'unsigned', 'boolean', 'char', 'wchar', 'octet', 'short', 'long',
  575. 'int8', 'uint8', 'int16', 'int32', 'int64', 'uint16', 'uint32', 'uint64',
  576. 'float', 'double', 'fixed',
  577. 'sequence', 'string', 'wstring', 'map',
  578. ), prefix=r'(?i)', suffix=r'\b'), Keyword.Type),
  579. (words((
  580. '@annotation', 'struct', 'union', 'bitset', 'interface',
  581. 'exception', 'valuetype', 'eventtype', 'component',
  582. ), prefix=r'(?i)', suffix=r'(\s+)(\w+)'), bygroups(Keyword, Whitespace, Name.Class)),
  583. (words((
  584. 'abstract', 'alias', 'attribute', 'case', 'connector',
  585. 'consumes', 'context', 'custom', 'default', 'emits', 'factory',
  586. 'finder', 'getraises', 'home', 'import', 'manages', 'mirrorport',
  587. 'multiple', 'Object', 'oneway', 'primarykey', 'private', 'port',
  588. 'porttype', 'provides', 'public', 'publishes', 'raises',
  589. 'readonly', 'setraises', 'supports', 'switch', 'truncatable',
  590. 'typeid', 'typename', 'typeprefix', 'uses', 'ValueBase',
  591. ), prefix=r'(?i)', suffix=r'\b'), Keyword),
  592. (r'(?i)(enum|bitmask)(\s+)(\w+)',
  593. bygroups(Keyword, Whitespace, Name.Class), 'enum'),
  594. (r'(?i)(module)(\s+)(\w+)',
  595. bygroups(Keyword.Namespace, Whitespace, Name.Namespace)),
  596. (r'(\w+)(\s*)(=)', bygroups(Name.Constant, Whitespace, Operator)),
  597. (r'[\(\)]', Punctuation),
  598. include('values'),
  599. include('annotation_appl'),
  600. ],
  601. }