systemverilog.js 11 KB

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