hdl.py 22 KB

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