hdl.py 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465
  1. """
  2. pygments.lexers.hdl
  3. ~~~~~~~~~~~~~~~~~~~
  4. Lexers for hardware descriptor 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, bygroups, include, using, this, words
  10. from pygments.token import Text, Comment, Operator, Keyword, Name, String, \
  11. Number, Punctuation, Whitespace
  12. __all__ = ['VerilogLexer', 'SystemVerilogLexer', 'VhdlLexer']
  13. class VerilogLexer(RegexLexer):
  14. """
  15. For verilog source code with preprocessor directives.
  16. .. versionadded:: 1.4
  17. """
  18. name = 'verilog'
  19. aliases = ['verilog', 'v']
  20. filenames = ['*.v']
  21. mimetypes = ['text/x-verilog']
  22. #: optional Comment or Whitespace
  23. _ws = r'(?:\s|//.*?\n|/[*].*?[*]/)+'
  24. tokens = {
  25. 'root': [
  26. (r'^\s*`define', Comment.Preproc, 'macro'),
  27. (r'\s+', Whitespace),
  28. (r'(\\)(\n)', bygroups(String.Escape, Whitespace)), # line continuation
  29. (r'/(\\\n)?/(\n|(.|\n)*?[^\\]\n)', Comment.Single),
  30. (r'/(\\\n)?[*](.|\n)*?[*](\\\n)?/', Comment.Multiline),
  31. (r'[{}#@]', Punctuation),
  32. (r'L?"', String, 'string'),
  33. (r"L?'(\\.|\\[0-7]{1,3}|\\x[a-fA-F0-9]{1,2}|[^\\\'\n])'", String.Char),
  34. (r'(\d+\.\d*|\.\d+|\d+)[eE][+-]?\d+[lL]?', Number.Float),
  35. (r'(\d+\.\d*|\.\d+|\d+[fF])[fF]?', Number.Float),
  36. (r'([0-9]+)|(\'h)[0-9a-fA-F]+', Number.Hex),
  37. (r'([0-9]+)|(\'b)[01]+', Number.Bin),
  38. (r'([0-9]+)|(\'d)[0-9]+', Number.Integer),
  39. (r'([0-9]+)|(\'o)[0-7]+', Number.Oct),
  40. (r'\'[01xz]', Number),
  41. (r'\d+[Ll]?', Number.Integer),
  42. (r'[~!%^&*+=|?:<>/-]', Operator),
  43. (r'[()\[\],.;\']', Punctuation),
  44. (r'`[a-zA-Z_]\w*', Name.Constant),
  45. (r'^(\s*)(package)(\s+)', bygroups(Whitespace, Keyword.Namespace, Text)),
  46. (r'^(\s*)(import)(\s+)', bygroups(Whitespace, Keyword.Namespace, Text),
  47. 'import'),
  48. (words((
  49. 'always', 'always_comb', 'always_ff', 'always_latch', 'and',
  50. 'assign', 'automatic', 'begin', 'break', 'buf', 'bufif0', 'bufif1',
  51. 'case', 'casex', 'casez', 'cmos', 'const', 'continue', 'deassign',
  52. 'default', 'defparam', 'disable', 'do', 'edge', 'else', 'end', 'endcase',
  53. 'endfunction', 'endgenerate', 'endmodule', 'endpackage', 'endprimitive',
  54. 'endspecify', 'endtable', 'endtask', 'enum', 'event', 'final', 'for',
  55. 'force', 'forever', 'fork', 'function', 'generate', 'genvar', 'highz0',
  56. 'highz1', 'if', 'initial', 'inout', 'input', 'integer', 'join', 'large',
  57. 'localparam', 'macromodule', 'medium', 'module', 'nand', 'negedge',
  58. 'nmos', 'nor', 'not', 'notif0', 'notif1', 'or', 'output', 'packed',
  59. 'parameter', 'pmos', 'posedge', 'primitive', 'pull0', 'pull1',
  60. 'pulldown', 'pullup', 'rcmos', 'ref', 'release', 'repeat', 'return',
  61. 'rnmos', 'rpmos', 'rtran', 'rtranif0', 'rtranif1', 'scalared', 'signed',
  62. 'small', 'specify', 'specparam', 'strength', 'string', 'strong0',
  63. 'strong1', 'struct', 'table', 'task', 'tran', 'tranif0', 'tranif1',
  64. 'type', 'typedef', 'unsigned', 'var', 'vectored', 'void', 'wait',
  65. 'weak0', 'weak1', 'while', 'xnor', 'xor'), suffix=r'\b'),
  66. Keyword),
  67. (words((
  68. 'accelerate', 'autoexpand_vectornets', 'celldefine', 'default_nettype',
  69. 'else', 'elsif', 'endcelldefine', 'endif', 'endprotect', 'endprotected',
  70. 'expand_vectornets', 'ifdef', 'ifndef', 'include', 'noaccelerate',
  71. 'noexpand_vectornets', 'noremove_gatenames', 'noremove_netnames',
  72. 'nounconnected_drive', 'protect', 'protected', 'remove_gatenames',
  73. 'remove_netnames', 'resetall', 'timescale', 'unconnected_drive',
  74. 'undef'), prefix=r'`', suffix=r'\b'),
  75. Comment.Preproc),
  76. (words((
  77. 'bits', 'bitstoreal', 'bitstoshortreal', 'countdrivers', 'display', 'fclose',
  78. 'fdisplay', 'finish', 'floor', 'fmonitor', 'fopen', 'fstrobe', 'fwrite',
  79. 'getpattern', 'history', 'incsave', 'input', 'itor', 'key', 'list', 'log',
  80. 'monitor', 'monitoroff', 'monitoron', 'nokey', 'nolog', 'printtimescale',
  81. 'random', 'readmemb', 'readmemh', 'realtime', 'realtobits', 'reset',
  82. 'reset_count', 'reset_value', 'restart', 'rtoi', 'save', 'scale', 'scope',
  83. 'shortrealtobits', 'showscopes', 'showvariables', 'showvars', 'sreadmemb',
  84. 'sreadmemh', 'stime', 'stop', 'strobe', 'time', 'timeformat', 'write'),
  85. prefix=r'\$', suffix=r'\b'),
  86. Name.Builtin),
  87. (words((
  88. 'byte', 'shortint', 'int', 'longint', 'integer', 'time',
  89. 'bit', 'logic', 'reg', 'supply0', 'supply1', 'tri', 'triand',
  90. 'trior', 'tri0', 'tri1', 'trireg', 'uwire', 'wire', 'wand', 'wor'
  91. 'shortreal', 'real', 'realtime'), suffix=r'\b'),
  92. Keyword.Type),
  93. (r'[a-zA-Z_]\w*:(?!:)', Name.Label),
  94. (r'\$?[a-zA-Z_]\w*', Name),
  95. (r'\\(\S+)', Name),
  96. ],
  97. 'string': [
  98. (r'"', String, '#pop'),
  99. (r'\\([\\abfnrtv"\']|x[a-fA-F0-9]{2,4}|[0-7]{1,3})', String.Escape),
  100. (r'[^\\"\n]+', String), # all other characters
  101. (r'(\\)(\n)', bygroups(String.Escape, Whitespace)), # line continuation
  102. (r'\\', String), # stray backslash
  103. ],
  104. 'macro': [
  105. (r'[^/\n]+', Comment.Preproc),
  106. (r'/[*](.|\n)*?[*]/', Comment.Multiline),
  107. (r'//.*?\n', Comment.Single, '#pop'),
  108. (r'/', Comment.Preproc),
  109. (r'(?<=\\)\n', Comment.Preproc),
  110. (r'\n', Whitespace, '#pop'),
  111. ],
  112. 'import': [
  113. (r'[\w:]+\*?', Name.Namespace, '#pop')
  114. ]
  115. }
  116. def analyse_text(text):
  117. """Verilog code will use one of reg/wire/assign for sure, and that
  118. is not common elsewhere."""
  119. result = 0
  120. if 'reg' in text:
  121. result += 0.1
  122. if 'wire' in text:
  123. result += 0.1
  124. if 'assign' in text:
  125. result += 0.1
  126. return result
  127. class SystemVerilogLexer(RegexLexer):
  128. """
  129. Extends verilog lexer to recognise all SystemVerilog keywords from IEEE
  130. 1800-2009 standard.
  131. .. versionadded:: 1.5
  132. """
  133. name = 'systemverilog'
  134. aliases = ['systemverilog', 'sv']
  135. filenames = ['*.sv', '*.svh']
  136. mimetypes = ['text/x-systemverilog']
  137. #: optional Comment or Whitespace
  138. _ws = r'(?:\s|//.*?\n|/[*].*?[*]/)+'
  139. tokens = {
  140. 'root': [
  141. (r'^(\s*)(`define)', bygroups(Whitespace, Comment.Preproc), 'macro'),
  142. (r'^(\s*)(package)(\s+)', bygroups(Whitespace, Keyword.Namespace, Whitespace)),
  143. (r'^(\s*)(import)(\s+)', bygroups(Whitespace, Keyword.Namespace, Whitespace), 'import'),
  144. (r'\s+', Whitespace),
  145. (r'(\\)(\n)', bygroups(String.Escape, Whitespace)), # line continuation
  146. (r'/(\\\n)?/(\n|(.|\n)*?[^\\]\n)', Comment.Single),
  147. (r'/(\\\n)?[*](.|\n)*?[*](\\\n)?/', Comment.Multiline),
  148. (r'[{}#@]', Punctuation),
  149. (r'L?"', String, 'string'),
  150. (r"L?'(\\.|\\[0-7]{1,3}|\\x[a-fA-F0-9]{1,2}|[^\\\'\n])'", String.Char),
  151. (r'(\d+\.\d*|\.\d+|\d+)[eE][+-]?\d+[lL]?', Number.Float),
  152. (r'(\d+\.\d*|\.\d+|\d+[fF])[fF]?', Number.Float),
  153. (r'([1-9][_0-9]*)?\s*\'[sS]?[bB]\s*[xXzZ?01][_xXzZ?01]*',
  154. Number.Bin),
  155. (r'([1-9][_0-9]*)?\s*\'[sS]?[oO]\s*[xXzZ?0-7][_xXzZ?0-7]*',
  156. Number.Oct),
  157. (r'([1-9][_0-9]*)?\s*\'[sS]?[dD]\s*[xXzZ?0-9][_xXzZ?0-9]*',
  158. Number.Integer),
  159. (r'([1-9][_0-9]*)?\s*\'[sS]?[hH]\s*[xXzZ?0-9a-fA-F][_xXzZ?0-9a-fA-F]*',
  160. Number.Hex),
  161. (r'\'[01xXzZ]', Number),
  162. (r'[0-9][_0-9]*', Number.Integer),
  163. (r'[~!%^&*+=|?:<>/-]', Operator),
  164. (words(('inside', 'dist'), suffix=r'\b'), Operator.Word),
  165. (r'[()\[\],.;\'$]', Punctuation),
  166. (r'`[a-zA-Z_]\w*', Name.Constant),
  167. (words((
  168. 'accept_on', 'alias', 'always', 'always_comb', 'always_ff',
  169. 'always_latch', 'and', 'assert', 'assign', 'assume', 'automatic',
  170. 'before', 'begin', 'bind', 'bins', 'binsof', 'break', 'buf',
  171. 'bufif0', 'bufif1', 'case', 'casex', 'casez', 'cell',
  172. 'checker', 'clocking', 'cmos', 'config',
  173. 'constraint', 'context', 'continue', 'cover', 'covergroup',
  174. 'coverpoint', 'cross', 'deassign', 'default', 'defparam', 'design',
  175. 'disable', 'do', 'edge', 'else', 'end', 'endcase',
  176. 'endchecker', 'endclocking', 'endconfig', 'endfunction',
  177. 'endgenerate', 'endgroup', 'endinterface', 'endmodule', 'endpackage',
  178. 'endprimitive', 'endprogram', 'endproperty', 'endsequence',
  179. 'endspecify', 'endtable', 'endtask', 'enum', 'eventually',
  180. 'expect', 'export', 'extern', 'final', 'first_match',
  181. 'for', 'force', 'foreach', 'forever', 'fork', 'forkjoin', 'function',
  182. 'generate', 'genvar', 'global', 'highz0', 'highz1', 'if', 'iff',
  183. 'ifnone', 'ignore_bins', 'illegal_bins', 'implies', 'implements', 'import',
  184. 'incdir', 'include', 'initial', 'inout', 'input',
  185. 'instance', 'interconnect', 'interface', 'intersect', 'join',
  186. 'join_any', 'join_none', 'large', 'let', 'liblist', 'library',
  187. 'local', 'localparam', 'macromodule', 'matches',
  188. 'medium', 'modport', 'module', 'nand', 'negedge', 'nettype', 'new', 'nexttime',
  189. 'nmos', 'nor', 'noshowcancelled', 'not', 'notif0', 'notif1', 'null',
  190. 'or', 'output', 'package', 'packed', 'parameter', 'pmos', 'posedge',
  191. 'primitive', 'priority', 'program', 'property', 'protected', 'pull0',
  192. 'pull1', 'pulldown', 'pullup', 'pulsestyle_ondetect',
  193. 'pulsestyle_onevent', 'pure', 'rand', 'randc', 'randcase',
  194. 'randsequence', 'rcmos', 'ref',
  195. 'reject_on', 'release', 'repeat', 'restrict', 'return', 'rnmos',
  196. 'rpmos', 'rtran', 'rtranif0', 'rtranif1', 's_always', 's_eventually',
  197. 's_nexttime', 's_until', 's_until_with', 'scalared', 'sequence',
  198. 'showcancelled', 'small', 'soft', 'solve',
  199. 'specify', 'specparam', 'static', 'strong', 'strong0',
  200. 'strong1', 'struct', 'super', 'sync_accept_on',
  201. 'sync_reject_on', 'table', 'tagged', 'task', 'this', 'throughout',
  202. 'timeprecision', 'timeunit', 'tran', 'tranif0', 'tranif1',
  203. 'typedef', 'union', 'unique', 'unique0', 'until',
  204. 'until_with', 'untyped', 'use', 'vectored',
  205. 'virtual', 'wait', 'wait_order', 'weak', 'weak0',
  206. 'weak1', 'while', 'wildcard', 'with', 'within',
  207. 'xnor', 'xor'),
  208. suffix=r'\b'),
  209. Keyword),
  210. (r'(class)(\s+)([a-zA-Z_]\w*)',
  211. bygroups(Keyword.Declaration, Whitespace, Name.Class)),
  212. (r'(extends)(\s+)([a-zA-Z_]\w*)',
  213. bygroups(Keyword.Declaration, Whitespace, Name.Class)),
  214. (r'(endclass\b)(?:(\s*)(:)(\s*)([a-zA-Z_]\w*))?',
  215. bygroups(Keyword.Declaration, Whitespace, Punctuation, Whitespace, Name.Class)),
  216. (words((
  217. # Variable types
  218. 'bit', 'byte', 'chandle', 'const', 'event', 'int', 'integer',
  219. 'logic', 'longint', 'real', 'realtime', 'reg', 'shortint',
  220. 'shortreal', 'signed', 'string', 'time', 'type', 'unsigned',
  221. 'var', 'void',
  222. # Net types
  223. 'supply0', 'supply1', 'tri', 'triand', 'trior', 'trireg',
  224. 'tri0', 'tri1', 'uwire', 'wand', 'wire', 'wor'),
  225. suffix=r'\b'),
  226. Keyword.Type),
  227. (words((
  228. '`__FILE__', '`__LINE__', '`begin_keywords', '`celldefine',
  229. '`default_nettype', '`define', '`else', '`elsif', '`end_keywords',
  230. '`endcelldefine', '`endif', '`ifdef', '`ifndef', '`include',
  231. '`line', '`nounconnected_drive', '`pragma', '`resetall',
  232. '`timescale', '`unconnected_drive', '`undef', '`undefineall'),
  233. suffix=r'\b'),
  234. Comment.Preproc),
  235. (words((
  236. # Simulation control tasks (20.2)
  237. '$exit', '$finish', '$stop',
  238. # Simulation time functions (20.3)
  239. '$realtime', '$stime', '$time',
  240. # Timescale tasks (20.4)
  241. '$printtimescale', '$timeformat',
  242. # Conversion functions
  243. '$bitstoreal', '$bitstoshortreal', '$cast', '$itor',
  244. '$realtobits', '$rtoi', '$shortrealtobits', '$signed',
  245. '$unsigned',
  246. # Data query functions (20.6)
  247. '$bits', '$isunbounded', '$typename',
  248. # Array query functions (20.7)
  249. '$dimensions', '$high', '$increment', '$left', '$low', '$right',
  250. '$size', '$unpacked_dimensions',
  251. # Math functions (20.8)
  252. '$acos', '$acosh', '$asin', '$asinh', '$atan', '$atan2',
  253. '$atanh', '$ceil', '$clog2', '$cos', '$cosh', '$exp', '$floor',
  254. '$hypot', '$ln', '$log10', '$pow', '$sin', '$sinh', '$sqrt',
  255. '$tan', '$tanh',
  256. # Bit vector system functions (20.9)
  257. '$countbits', '$countones', '$isunknown', '$onehot', '$onehot0',
  258. # Severity tasks (20.10)
  259. '$info', '$error', '$fatal', '$warning',
  260. # Assertion control tasks (20.12)
  261. '$assertcontrol', '$assertfailoff', '$assertfailon',
  262. '$assertkill', '$assertnonvacuouson', '$assertoff', '$asserton',
  263. '$assertpassoff', '$assertpasson', '$assertvacuousoff',
  264. # Sampled value system functions (20.13)
  265. '$changed', '$changed_gclk', '$changing_gclk', '$falling_gclk',
  266. '$fell', '$fell_gclk', '$future_gclk', '$past', '$past_gclk',
  267. '$rising_gclk', '$rose', '$rose_gclk', '$sampled', '$stable',
  268. '$stable_gclk', '$steady_gclk',
  269. # Coverage control functions (20.14)
  270. '$coverage_control', '$coverage_get', '$coverage_get_max',
  271. '$coverage_merge', '$coverage_save', '$get_coverage',
  272. '$load_coverage_db', '$set_coverage_db_name',
  273. # Probabilistic distribution functions (20.15)
  274. '$dist_chi_square', '$dist_erlang', '$dist_exponential',
  275. '$dist_normal', '$dist_poisson', '$dist_t', '$dist_uniform',
  276. '$random',
  277. # Stochastic analysis tasks and functions (20.16)
  278. '$q_add', '$q_exam', '$q_full', '$q_initialize', '$q_remove',
  279. # PLA modeling tasks (20.17)
  280. '$async$and$array', '$async$and$plane', '$async$nand$array',
  281. '$async$nand$plane', '$async$nor$array', '$async$nor$plane',
  282. '$async$or$array', '$async$or$plane', '$sync$and$array',
  283. '$sync$and$plane', '$sync$nand$array', '$sync$nand$plane',
  284. '$sync$nor$array', '$sync$nor$plane', '$sync$or$array',
  285. '$sync$or$plane',
  286. # Miscellaneous tasks and functions (20.18)
  287. '$system',
  288. # Display tasks (21.2)
  289. '$display', '$displayb', '$displayh', '$displayo', '$monitor',
  290. '$monitorb', '$monitorh', '$monitoro', '$monitoroff',
  291. '$monitoron', '$strobe', '$strobeb', '$strobeh', '$strobeo',
  292. '$write', '$writeb', '$writeh', '$writeo',
  293. # File I/O tasks and functions (21.3)
  294. '$fclose', '$fdisplay', '$fdisplayb', '$fdisplayh',
  295. '$fdisplayo', '$feof', '$ferror', '$fflush', '$fgetc', '$fgets',
  296. '$fmonitor', '$fmonitorb', '$fmonitorh', '$fmonitoro', '$fopen',
  297. '$fread', '$fscanf', '$fseek', '$fstrobe', '$fstrobeb',
  298. '$fstrobeh', '$fstrobeo', '$ftell', '$fwrite', '$fwriteb',
  299. '$fwriteh', '$fwriteo', '$rewind', '$sformat', '$sformatf',
  300. '$sscanf', '$swrite', '$swriteb', '$swriteh', '$swriteo',
  301. '$ungetc',
  302. # Memory load tasks (21.4)
  303. '$readmemb', '$readmemh',
  304. # Memory dump tasks (21.5)
  305. '$writememb', '$writememh',
  306. # Command line input (21.6)
  307. '$test$plusargs', '$value$plusargs',
  308. # VCD tasks (21.7)
  309. '$dumpall', '$dumpfile', '$dumpflush', '$dumplimit', '$dumpoff',
  310. '$dumpon', '$dumpports', '$dumpportsall', '$dumpportsflush',
  311. '$dumpportslimit', '$dumpportsoff', '$dumpportson', '$dumpvars',
  312. ), suffix=r'\b'),
  313. Name.Builtin),
  314. (r'[a-zA-Z_]\w*:(?!:)', Name.Label),
  315. (r'\$?[a-zA-Z_]\w*', Name),
  316. (r'\\(\S+)', Name),
  317. ],
  318. 'string': [
  319. (r'"', String, '#pop'),
  320. (r'\\([\\abfnrtv"\']|x[a-fA-F0-9]{2,4}|[0-7]{1,3})', String.Escape),
  321. (r'[^\\"\n]+', String), # all other characters
  322. (r'(\\)(\n)', bygroups(String.Escape, Whitespace)), # line continuation
  323. (r'\\', String), # stray backslash
  324. ],
  325. 'macro': [
  326. (r'[^/\n]+', Comment.Preproc),
  327. (r'/[*](.|\n)*?[*]/', Comment.Multiline),
  328. (r'//.*?$', Comment.Single, '#pop'),
  329. (r'/', Comment.Preproc),
  330. (r'(?<=\\)\n', Comment.Preproc),
  331. (r'\n', Whitespace, '#pop'),
  332. ],
  333. 'import': [
  334. (r'[\w:]+\*?', Name.Namespace, '#pop')
  335. ]
  336. }
  337. class VhdlLexer(RegexLexer):
  338. """
  339. For VHDL source code.
  340. .. versionadded:: 1.5
  341. """
  342. name = 'vhdl'
  343. aliases = ['vhdl']
  344. filenames = ['*.vhdl', '*.vhd']
  345. mimetypes = ['text/x-vhdl']
  346. flags = re.MULTILINE | re.IGNORECASE
  347. tokens = {
  348. 'root': [
  349. (r'\s+', Whitespace),
  350. (r'(\\)(\n)', bygroups(String.Escape, Whitespace)), # line continuation
  351. (r'--.*?$', Comment.Single),
  352. (r"'(U|X|0|1|Z|W|L|H|-)'", String.Char),
  353. (r'[~!%^&*+=|?:<>/-]', Operator),
  354. (r"'[a-z_]\w*", Name.Attribute),
  355. (r'[()\[\],.;\']', Punctuation),
  356. (r'"[^\n\\"]*"', String),
  357. (r'(library)(\s+)([a-z_]\w*)',
  358. bygroups(Keyword, Whitespace, Name.Namespace)),
  359. (r'(use)(\s+)(entity)', bygroups(Keyword, Whitespace, Keyword)),
  360. (r'(use)(\s+)([a-z_][\w.]*\.)(all)',
  361. bygroups(Keyword, Whitespace, Name.Namespace, Keyword)),
  362. (r'(use)(\s+)([a-z_][\w.]*)',
  363. bygroups(Keyword, Whitespace, Name.Namespace)),
  364. (r'(std|ieee)(\.[a-z_]\w*)',
  365. bygroups(Name.Namespace, Name.Namespace)),
  366. (words(('std', 'ieee', 'work'), suffix=r'\b'),
  367. Name.Namespace),
  368. (r'(entity|component)(\s+)([a-z_]\w*)',
  369. bygroups(Keyword, Whitespace, Name.Class)),
  370. (r'(architecture|configuration)(\s+)([a-z_]\w*)(\s+)'
  371. r'(of)(\s+)([a-z_]\w*)(\s+)(is)',
  372. bygroups(Keyword, Whitespace, Name.Class, Whitespace, Keyword, Whitespace,
  373. Name.Class, Whitespace, Keyword)),
  374. (r'([a-z_]\w*)(:)(\s+)(process|for)',
  375. bygroups(Name.Class, Operator, Whitespace, Keyword)),
  376. (r'(end)(\s+)', bygroups(using(this), Whitespace), 'endblock'),
  377. include('types'),
  378. include('keywords'),
  379. include('numbers'),
  380. (r'[a-z_]\w*', Name),
  381. ],
  382. 'endblock': [
  383. include('keywords'),
  384. (r'[a-z_]\w*', Name.Class),
  385. (r'\s+', Whitespace),
  386. (r';', Punctuation, '#pop'),
  387. ],
  388. 'types': [
  389. (words((
  390. 'boolean', 'bit', 'character', 'severity_level', 'integer', 'time',
  391. 'delay_length', 'natural', 'positive', 'string', 'bit_vector',
  392. 'file_open_kind', 'file_open_status', 'std_ulogic', 'std_ulogic_vector',
  393. 'std_logic', 'std_logic_vector', 'signed', 'unsigned'), suffix=r'\b'),
  394. Keyword.Type),
  395. ],
  396. 'keywords': [
  397. (words((
  398. 'abs', 'access', 'after', 'alias', 'all', 'and',
  399. 'architecture', 'array', 'assert', 'attribute', 'begin', 'block',
  400. 'body', 'buffer', 'bus', 'case', 'component', 'configuration',
  401. 'constant', 'disconnect', 'downto', 'else', 'elsif', 'end',
  402. 'entity', 'exit', 'file', 'for', 'function', 'generate',
  403. 'generic', 'group', 'guarded', 'if', 'impure', 'in',
  404. 'inertial', 'inout', 'is', 'label', 'library', 'linkage',
  405. 'literal', 'loop', 'map', 'mod', 'nand', 'new',
  406. 'next', 'nor', 'not', 'null', 'of', 'on',
  407. 'open', 'or', 'others', 'out', 'package', 'port',
  408. 'postponed', 'procedure', 'process', 'pure', 'range', 'record',
  409. 'register', 'reject', 'rem', 'return', 'rol', 'ror', 'select',
  410. 'severity', 'signal', 'shared', 'sla', 'sll', 'sra',
  411. 'srl', 'subtype', 'then', 'to', 'transport', 'type',
  412. 'units', 'until', 'use', 'variable', 'wait', 'when',
  413. 'while', 'with', 'xnor', 'xor'), suffix=r'\b'),
  414. Keyword),
  415. ],
  416. 'numbers': [
  417. (r'\d{1,2}#[0-9a-f_]+#?', Number.Integer),
  418. (r'\d+', Number.Integer),
  419. (r'(\d+\.\d*|\.\d+|\d+)E[+-]?\d+', Number.Float),
  420. (r'X"[0-9a-f_]+"', Number.Hex),
  421. (r'O"[0-7_]+"', Number.Oct),
  422. (r'B"[01_]+"', Number.Bin),
  423. ],
  424. }