vhdl.js 3.8 KB

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