vhdl.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. /*
  2. Language: VHDL
  3. Author: Igor Kalnitsky <igor@kalnitsky.org>
  4. Contributors: Daniel C.K. Kho <daniel.kho@tauhop.com>, Guillaume Savaton <guillaume.savaton@eseo.fr>
  5. Description: VHDL is a hardware description language used in electronic design automation to describe digital and mixed-signal systems.
  6. Website: https://en.wikipedia.org/wiki/VHDL
  7. */
  8. function vhdl(hljs) {
  9. // Regular expression for VHDL numeric literals.
  10. // Decimal literal:
  11. const INTEGER_RE = '\\d(_|\\d)*';
  12. const EXPONENT_RE = '[eE][-+]?' + INTEGER_RE;
  13. const DECIMAL_LITERAL_RE = INTEGER_RE + '(\\.' + INTEGER_RE + ')?' + '(' + EXPONENT_RE + ')?';
  14. // Based literal:
  15. const BASED_INTEGER_RE = '\\w+';
  16. const BASED_LITERAL_RE = INTEGER_RE + '#' + BASED_INTEGER_RE + '(\\.' + BASED_INTEGER_RE + ')?' + '#' + '(' + EXPONENT_RE + ')?';
  17. const NUMBER_RE = '\\b(' + BASED_LITERAL_RE + '|' + DECIMAL_LITERAL_RE + ')';
  18. const KEYWORDS = [
  19. "abs",
  20. "access",
  21. "after",
  22. "alias",
  23. "all",
  24. "and",
  25. "architecture",
  26. "array",
  27. "assert",
  28. "assume",
  29. "assume_guarantee",
  30. "attribute",
  31. "begin",
  32. "block",
  33. "body",
  34. "buffer",
  35. "bus",
  36. "case",
  37. "component",
  38. "configuration",
  39. "constant",
  40. "context",
  41. "cover",
  42. "disconnect",
  43. "downto",
  44. "default",
  45. "else",
  46. "elsif",
  47. "end",
  48. "entity",
  49. "exit",
  50. "fairness",
  51. "file",
  52. "for",
  53. "force",
  54. "function",
  55. "generate",
  56. "generic",
  57. "group",
  58. "guarded",
  59. "if",
  60. "impure",
  61. "in",
  62. "inertial",
  63. "inout",
  64. "is",
  65. "label",
  66. "library",
  67. "linkage",
  68. "literal",
  69. "loop",
  70. "map",
  71. "mod",
  72. "nand",
  73. "new",
  74. "next",
  75. "nor",
  76. "not",
  77. "null",
  78. "of",
  79. "on",
  80. "open",
  81. "or",
  82. "others",
  83. "out",
  84. "package",
  85. "parameter",
  86. "port",
  87. "postponed",
  88. "procedure",
  89. "process",
  90. "property",
  91. "protected",
  92. "pure",
  93. "range",
  94. "record",
  95. "register",
  96. "reject",
  97. "release",
  98. "rem",
  99. "report",
  100. "restrict",
  101. "restrict_guarantee",
  102. "return",
  103. "rol",
  104. "ror",
  105. "select",
  106. "sequence",
  107. "severity",
  108. "shared",
  109. "signal",
  110. "sla",
  111. "sll",
  112. "sra",
  113. "srl",
  114. "strong",
  115. "subtype",
  116. "then",
  117. "to",
  118. "transport",
  119. "type",
  120. "unaffected",
  121. "units",
  122. "until",
  123. "use",
  124. "variable",
  125. "view",
  126. "vmode",
  127. "vprop",
  128. "vunit",
  129. "wait",
  130. "when",
  131. "while",
  132. "with",
  133. "xnor",
  134. "xor"
  135. ];
  136. const BUILT_INS = [
  137. "boolean",
  138. "bit",
  139. "character",
  140. "integer",
  141. "time",
  142. "delay_length",
  143. "natural",
  144. "positive",
  145. "string",
  146. "bit_vector",
  147. "file_open_kind",
  148. "file_open_status",
  149. "std_logic",
  150. "std_logic_vector",
  151. "unsigned",
  152. "signed",
  153. "boolean_vector",
  154. "integer_vector",
  155. "std_ulogic",
  156. "std_ulogic_vector",
  157. "unresolved_unsigned",
  158. "u_unsigned",
  159. "unresolved_signed",
  160. "u_signed",
  161. "real_vector",
  162. "time_vector"
  163. ];
  164. const LITERALS = [
  165. // severity_level
  166. "false",
  167. "true",
  168. "note",
  169. "warning",
  170. "error",
  171. "failure",
  172. // textio
  173. "line",
  174. "text",
  175. "side",
  176. "width"
  177. ];
  178. return {
  179. name: 'VHDL',
  180. case_insensitive: true,
  181. keywords: {
  182. keyword: KEYWORDS,
  183. built_in: BUILT_INS,
  184. literal: LITERALS
  185. },
  186. illegal: /\{/,
  187. contains: [
  188. hljs.C_BLOCK_COMMENT_MODE, // VHDL-2008 block commenting.
  189. hljs.COMMENT('--', '$'),
  190. hljs.QUOTE_STRING_MODE,
  191. {
  192. className: 'number',
  193. begin: NUMBER_RE,
  194. relevance: 0
  195. },
  196. {
  197. className: 'string',
  198. begin: '\'(U|X|0|1|Z|W|L|H|-)\'',
  199. contains: [ hljs.BACKSLASH_ESCAPE ]
  200. },
  201. {
  202. className: 'symbol',
  203. begin: '\'[A-Za-z](_?[A-Za-z0-9])*',
  204. contains: [ hljs.BACKSLASH_ESCAPE ]
  205. }
  206. ]
  207. };
  208. }
  209. module.exports = vhdl;