c_like.py 29 KB

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