systemverilog.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561
  1. /*---------------------------------------------------------------------------------------------
  2. * Copyright (c) Microsoft Corporation. All rights reserved.
  3. * Licensed under the MIT License. See License.txt in the project root for license information.
  4. *--------------------------------------------------------------------------------------------*/
  5. export var conf = {
  6. comments: {
  7. lineComment: '//',
  8. blockComment: ['/*', '*/']
  9. },
  10. brackets: [
  11. ['{', '}'],
  12. ['[', ']'],
  13. ['(', ')'],
  14. ['begin', 'end'],
  15. ['case', 'endcase'],
  16. ['casex', 'endcase'],
  17. ['casez', 'endcase'],
  18. ['checker', 'endchecker'],
  19. ['class', 'endclass'],
  20. ['clocking', 'endclocking'],
  21. ['config', 'endconfig'],
  22. ['function', 'endfunction'],
  23. ['generate', 'endgenerate'],
  24. ['group', 'endgroup'],
  25. ['interface', 'endinterface'],
  26. ['module', 'endmodule'],
  27. ['package', 'endpackage'],
  28. ['primitive', 'endprimitive'],
  29. ['program', 'endprogram'],
  30. ['property', 'endproperty'],
  31. ['specify', 'endspecify'],
  32. ['sequence', 'endsequence'],
  33. ['table', 'endtable'],
  34. ['task', 'endtask']
  35. ],
  36. autoClosingPairs: [
  37. { open: '[', close: ']' },
  38. { open: '{', close: '}' },
  39. { open: '(', close: ')' },
  40. { open: "'", close: "'", notIn: ['string', 'comment'] },
  41. { open: '"', close: '"', notIn: ['string'] }
  42. ],
  43. surroundingPairs: [
  44. { open: '{', close: '}' },
  45. { open: '[', close: ']' },
  46. { open: '(', close: ')' },
  47. { open: '"', close: '"' },
  48. { open: "'", close: "'" }
  49. ],
  50. folding: {
  51. offSide: false,
  52. markers: {
  53. start: new RegExp('^(?:\\s*|.*(?!\\/[\\/\\*])[^\\w])(?:begin|case(x|z)?|class|clocking|config|covergroup|function|generate|interface|module|package|primitive|property|program|sequence|specify|table|task)\\b'),
  54. end: new RegExp('^(?:\\s*|.*(?!\\/[\\/\\*])[^\\w])(?:end|endcase|endclass|endclocking|endconfig|endgroup|endfunction|endgenerate|endinterface|endmodule|endpackage|endprimitive|endproperty|endprogram|endsequence|endspecify|endtable|endtask)\\b')
  55. }
  56. }
  57. };
  58. export var language = {
  59. defaultToken: '',
  60. tokenPostfix: '.sv',
  61. brackets: [
  62. { token: 'delimiter.curly', open: '{', close: '}' },
  63. { token: 'delimiter.parenthesis', open: '(', close: ')' },
  64. { token: 'delimiter.square', open: '[', close: ']' },
  65. { token: 'delimiter.angle', open: '<', close: '>' }
  66. ],
  67. keywords: [
  68. 'accept_on',
  69. 'alias',
  70. 'always',
  71. 'always_comb',
  72. 'always_ff',
  73. 'always_latch',
  74. 'and',
  75. 'assert',
  76. 'assign',
  77. 'assume',
  78. 'automatic',
  79. 'before',
  80. 'begin',
  81. 'bind',
  82. 'bins',
  83. 'binsof',
  84. 'bit',
  85. 'break',
  86. 'buf',
  87. 'bufif0',
  88. 'bufif1',
  89. 'byte',
  90. 'case',
  91. 'casex',
  92. 'casez',
  93. 'cell',
  94. 'chandle',
  95. 'checker',
  96. 'class',
  97. 'clocking',
  98. 'cmos',
  99. 'config',
  100. 'const',
  101. 'constraint',
  102. 'context',
  103. 'continue',
  104. 'cover',
  105. 'covergroup',
  106. 'coverpoint',
  107. 'cross',
  108. 'deassign',
  109. 'default',
  110. 'defparam',
  111. 'design',
  112. 'disable',
  113. 'dist',
  114. 'do',
  115. 'edge',
  116. 'else',
  117. 'end',
  118. 'endcase',
  119. 'endchecker',
  120. 'endclass',
  121. 'endclocking',
  122. 'endconfig',
  123. 'endfunction',
  124. 'endgenerate',
  125. 'endgroup',
  126. 'endinterface',
  127. 'endmodule',
  128. 'endpackage',
  129. 'endprimitive',
  130. 'endprogram',
  131. 'endproperty',
  132. 'endspecify',
  133. 'endsequence',
  134. 'endtable',
  135. 'endtask',
  136. 'enum',
  137. 'event',
  138. 'eventually',
  139. 'expect',
  140. 'export',
  141. 'extends',
  142. 'extern',
  143. 'final',
  144. 'first_match',
  145. 'for',
  146. 'force',
  147. 'foreach',
  148. 'forever',
  149. 'fork',
  150. 'forkjoin',
  151. 'function',
  152. 'generate',
  153. 'genvar',
  154. 'global',
  155. 'highz0',
  156. 'highz1',
  157. 'if',
  158. 'iff',
  159. 'ifnone',
  160. 'ignore_bins',
  161. 'illegal_bins',
  162. 'implements',
  163. 'implies',
  164. 'import',
  165. 'incdir',
  166. 'include',
  167. 'initial',
  168. 'inout',
  169. 'input',
  170. 'inside',
  171. 'instance',
  172. 'int',
  173. 'integer',
  174. 'interconnect',
  175. 'interface',
  176. 'intersect',
  177. 'join',
  178. 'join_any',
  179. 'join_none',
  180. 'large',
  181. 'let',
  182. 'liblist',
  183. 'library',
  184. 'local',
  185. 'localparam',
  186. 'logic',
  187. 'longint',
  188. 'macromodule',
  189. 'matches',
  190. 'medium',
  191. 'modport',
  192. 'module',
  193. 'nand',
  194. 'negedge',
  195. 'nettype',
  196. 'new',
  197. 'nexttime',
  198. 'nmos',
  199. 'nor',
  200. 'noshowcancelled',
  201. 'not',
  202. 'notif0',
  203. 'notif1',
  204. 'null',
  205. 'or',
  206. 'output',
  207. 'package',
  208. 'packed',
  209. 'parameter',
  210. 'pmos',
  211. 'posedge',
  212. 'primitive',
  213. 'priority',
  214. 'program',
  215. 'property',
  216. 'protected',
  217. 'pull0',
  218. 'pull1',
  219. 'pulldown',
  220. 'pullup',
  221. 'pulsestyle_ondetect',
  222. 'pulsestyle_onevent',
  223. 'pure',
  224. 'rand',
  225. 'randc',
  226. 'randcase',
  227. 'randsequence',
  228. 'rcmos',
  229. 'real',
  230. 'realtime',
  231. 'ref',
  232. 'reg',
  233. 'reject_on',
  234. 'release',
  235. 'repeat',
  236. 'restrict',
  237. 'return',
  238. 'rnmos',
  239. 'rpmos',
  240. 'rtran',
  241. 'rtranif0',
  242. 'rtranif1',
  243. 's_always',
  244. 's_eventually',
  245. 's_nexttime',
  246. 's_until',
  247. 's_until_with',
  248. 'scalared',
  249. 'sequence',
  250. 'shortint',
  251. 'shortreal',
  252. 'showcancelled',
  253. 'signed',
  254. 'small',
  255. 'soft',
  256. 'solve',
  257. 'specify',
  258. 'specparam',
  259. 'static',
  260. 'string',
  261. 'strong',
  262. 'strong0',
  263. 'strong1',
  264. 'struct',
  265. 'super',
  266. 'supply0',
  267. 'supply1',
  268. 'sync_accept_on',
  269. 'sync_reject_on',
  270. 'table',
  271. 'tagged',
  272. 'task',
  273. 'this',
  274. 'throughout',
  275. 'time',
  276. 'timeprecision',
  277. 'timeunit',
  278. 'tran',
  279. 'tranif0',
  280. 'tranif1',
  281. 'tri',
  282. 'tri0',
  283. 'tri1',
  284. 'triand',
  285. 'trior',
  286. 'trireg',
  287. 'type',
  288. 'typedef',
  289. 'union',
  290. 'unique',
  291. 'unique0',
  292. 'unsigned',
  293. 'until',
  294. 'until_with',
  295. 'untyped',
  296. 'use',
  297. 'uwire',
  298. 'var',
  299. 'vectored',
  300. 'virtual',
  301. 'void',
  302. 'wait',
  303. 'wait_order',
  304. 'wand',
  305. 'weak',
  306. 'weak0',
  307. 'weak1',
  308. 'while',
  309. 'wildcard',
  310. 'wire',
  311. 'with',
  312. 'within',
  313. 'wor',
  314. 'xnor',
  315. 'xor'
  316. ],
  317. builtin_gates: [
  318. 'and',
  319. 'nand',
  320. 'nor',
  321. 'or',
  322. 'xor',
  323. 'xnor',
  324. 'buf',
  325. 'not',
  326. 'bufif0',
  327. 'bufif1',
  328. 'notif1',
  329. 'notif0',
  330. 'cmos',
  331. 'nmos',
  332. 'pmos',
  333. 'rcmos',
  334. 'rnmos',
  335. 'rpmos',
  336. 'tran',
  337. 'tranif1',
  338. 'tranif0',
  339. 'rtran',
  340. 'rtranif1',
  341. 'rtranif0'
  342. ],
  343. operators: [
  344. // assignment operators
  345. '=',
  346. '+=',
  347. '-=',
  348. '*=',
  349. '/=',
  350. '%=',
  351. '&=',
  352. '|=',
  353. '^=',
  354. '<<=',
  355. '>>+',
  356. '<<<=',
  357. '>>>=',
  358. // conditional expression
  359. '?',
  360. ':',
  361. // Unary operators
  362. '+',
  363. '-',
  364. '!',
  365. '~',
  366. '&',
  367. '~&',
  368. '|',
  369. '~|',
  370. '^',
  371. '~^',
  372. '^~',
  373. //binary operators
  374. '+',
  375. '-',
  376. '*',
  377. '/',
  378. '%',
  379. '==',
  380. '!=',
  381. '===',
  382. '!==',
  383. '==?',
  384. '!=?',
  385. '&&',
  386. '||',
  387. '**',
  388. '<',
  389. '<=',
  390. '>',
  391. '>=',
  392. '&',
  393. '|',
  394. '^',
  395. '>>',
  396. '<<',
  397. '>>>',
  398. '<<<',
  399. // increment or decrement operator
  400. '++',
  401. '--',
  402. //binary logical operator
  403. '->',
  404. '<->',
  405. // binary set membership operator
  406. 'inside',
  407. // binary distrubution operator
  408. 'dist',
  409. '::',
  410. '+:',
  411. '-:',
  412. '*>',
  413. '&&&',
  414. '|->',
  415. '|=>',
  416. '#=#'
  417. ],
  418. // we include these common regular expressions
  419. symbols: /[=><!~?:&|+\-*\/\^%#]+/,
  420. escapes: /%%|\\(?:[antvf\\"']|x[0-9A-Fa-f]{1,2}|[0-7]{1,3})/,
  421. identifier: /(?:[a-zA-Z_][a-zA-Z0-9_$\.]*|\\\S+ )/,
  422. systemcall: /[$][a-zA-Z0-9_]+/,
  423. timeunits: /s|ms|us|ns|ps|fs/,
  424. // The main tokenizer for our languages
  425. tokenizer: {
  426. root: [
  427. // module instances
  428. [
  429. /^(\s*)(@identifier)/,
  430. [
  431. '',
  432. {
  433. cases: {
  434. '@builtin_gates': {
  435. token: 'keyword.$2',
  436. next: '@module_instance'
  437. },
  438. '@keywords': { token: 'keyword.$2' },
  439. '@default': {
  440. token: 'identifier',
  441. next: '@module_instance'
  442. }
  443. }
  444. }
  445. ]
  446. ],
  447. // include statements
  448. [/^\s*`include/, { token: 'keyword.directive.include', next: '@include' }],
  449. // Preprocessor directives
  450. [/^\s*`\s*\w+/, 'keyword'],
  451. // identifiers and keywords
  452. { include: '@identifier_or_keyword' },
  453. // whitespace
  454. { include: '@whitespace' },
  455. // (* attributes *).
  456. [/\(\*.*\*\)/, 'annotation'],
  457. // Systemcall
  458. [/@systemcall/, 'variable.predefined'],
  459. // delimiters and operators
  460. [/[{}()\[\]]/, '@brackets'],
  461. [/[<>](?!@symbols)/, '@brackets'],
  462. [
  463. /@symbols/,
  464. {
  465. cases: {
  466. '@operators': 'delimiter',
  467. '@default': ''
  468. }
  469. }
  470. ],
  471. // numbers
  472. { include: '@numbers' },
  473. // delimiter: after number because of .\d floats
  474. [/[;,.]/, 'delimiter'],
  475. // strings
  476. { include: '@strings' }
  477. ],
  478. identifier_or_keyword: [
  479. [
  480. /@identifier/,
  481. {
  482. cases: {
  483. '@keywords': { token: 'keyword.$0' },
  484. '@default': 'identifier'
  485. }
  486. }
  487. ]
  488. ],
  489. numbers: [
  490. [/\d+?[\d_]*(?:\.[\d_]+)?[eE][\-+]?\d+/, 'number.float'],
  491. [/\d+?[\d_]*\.[\d_]+(?:\s*@timeunits)?/, 'number.float'],
  492. [/(?:\d+?[\d_]*\s*)?'[sS]?[dD]\s*[0-9xXzZ?]+?[0-9xXzZ?_]*/, 'number'],
  493. [/(?:\d+?[\d_]*\s*)?'[sS]?[bB]\s*[0-1xXzZ?]+?[0-1xXzZ?_]*/, 'number.binary'],
  494. [/(?:\d+?[\d_]*\s*)?'[sS]?[oO]\s*[0-7xXzZ?]+?[0-7xXzZ?_]*/, 'number.octal'],
  495. [/(?:\d+?[\d_]*\s*)?'[sS]?[hH]\s*[0-9a-fA-FxXzZ?]+?[0-9a-fA-FxXzZ?_]*/, 'number.hex'],
  496. [/1step/, 'number'],
  497. [/[\dxXzZ]+?[\dxXzZ_]*(?:\s*@timeunits)?/, 'number'],
  498. [/'[01xXzZ]+/, 'number']
  499. ],
  500. module_instance: [
  501. { include: '@whitespace' },
  502. [/(#?)(\()/, ['', { token: '@brackets', next: '@port_connection' }]],
  503. [/@identifier\s*[;={}\[\],]/, { token: '@rematch', next: '@pop' }],
  504. [/@symbols|[;={}\[\],]/, { token: '@rematch', next: '@pop' }],
  505. [/@identifier/, 'type'],
  506. [/;/, 'delimiter', '@pop']
  507. ],
  508. port_connection: [
  509. { include: '@identifier_or_keyword' },
  510. { include: '@whitespace' },
  511. [/@systemcall/, 'variable.predefined'],
  512. { include: '@numbers' },
  513. { include: '@strings' },
  514. [/[,]/, 'delimiter'],
  515. [/\(/, '@brackets', '@port_connection'],
  516. [/\)/, '@brackets', '@pop']
  517. ],
  518. whitespace: [
  519. [/[ \t\r\n]+/, ''],
  520. [/\/\*/, 'comment', '@comment'],
  521. [/\/\/.*$/, 'comment']
  522. ],
  523. comment: [
  524. [/[^\/*]+/, 'comment'],
  525. [/\*\//, 'comment', '@pop'],
  526. [/[\/*]/, 'comment']
  527. ],
  528. strings: [
  529. [/"([^"\\]|\\.)*$/, 'string.invalid'],
  530. [/"/, 'string', '@string']
  531. ],
  532. string: [
  533. [/[^\\"]+/, 'string'],
  534. [/@escapes/, 'string.escape'],
  535. [/\\./, 'string.escape.invalid'],
  536. [/"/, 'string', '@pop']
  537. ],
  538. include: [
  539. [
  540. /(\s*)(")([\w*\/*]*)(.\w*)(")/,
  541. [
  542. '',
  543. 'string.include.identifier',
  544. 'string.include.identifier',
  545. 'string.include.identifier',
  546. { token: 'string.include.identifier', next: '@pop' }
  547. ]
  548. ],
  549. [
  550. /(\s*)(<)([\w*\/*]*)(.\w*)(>)/,
  551. [
  552. '',
  553. 'string.include.identifier',
  554. 'string.include.identifier',
  555. 'string.include.identifier',
  556. { token: 'string.include.identifier', next: '@pop' }
  557. ]
  558. ]
  559. ]
  560. }
  561. };