delphi.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. /*
  2. Language: Delphi
  3. Website: https://www.embarcadero.com/products/delphi
  4. Category: system
  5. */
  6. /** @type LanguageFn */
  7. function delphi(hljs) {
  8. const KEYWORDS = [
  9. "exports",
  10. "register",
  11. "file",
  12. "shl",
  13. "array",
  14. "record",
  15. "property",
  16. "for",
  17. "mod",
  18. "while",
  19. "set",
  20. "ally",
  21. "label",
  22. "uses",
  23. "raise",
  24. "not",
  25. "stored",
  26. "class",
  27. "safecall",
  28. "var",
  29. "interface",
  30. "or",
  31. "private",
  32. "static",
  33. "exit",
  34. "index",
  35. "inherited",
  36. "to",
  37. "else",
  38. "stdcall",
  39. "override",
  40. "shr",
  41. "asm",
  42. "far",
  43. "resourcestring",
  44. "finalization",
  45. "packed",
  46. "virtual",
  47. "out",
  48. "and",
  49. "protected",
  50. "library",
  51. "do",
  52. "xorwrite",
  53. "goto",
  54. "near",
  55. "function",
  56. "end",
  57. "div",
  58. "overload",
  59. "object",
  60. "unit",
  61. "begin",
  62. "string",
  63. "on",
  64. "inline",
  65. "repeat",
  66. "until",
  67. "destructor",
  68. "write",
  69. "message",
  70. "program",
  71. "with",
  72. "read",
  73. "initialization",
  74. "except",
  75. "default",
  76. "nil",
  77. "if",
  78. "case",
  79. "cdecl",
  80. "in",
  81. "downto",
  82. "threadvar",
  83. "of",
  84. "try",
  85. "pascal",
  86. "const",
  87. "external",
  88. "constructor",
  89. "type",
  90. "public",
  91. "then",
  92. "implementation",
  93. "finally",
  94. "published",
  95. "procedure",
  96. "absolute",
  97. "reintroduce",
  98. "operator",
  99. "as",
  100. "is",
  101. "abstract",
  102. "alias",
  103. "assembler",
  104. "bitpacked",
  105. "break",
  106. "continue",
  107. "cppdecl",
  108. "cvar",
  109. "enumerator",
  110. "experimental",
  111. "platform",
  112. "deprecated",
  113. "unimplemented",
  114. "dynamic",
  115. "export",
  116. "far16",
  117. "forward",
  118. "generic",
  119. "helper",
  120. "implements",
  121. "interrupt",
  122. "iochecks",
  123. "local",
  124. "name",
  125. "nodefault",
  126. "noreturn",
  127. "nostackframe",
  128. "oldfpccall",
  129. "otherwise",
  130. "saveregisters",
  131. "softfloat",
  132. "specialize",
  133. "strict",
  134. "unaligned",
  135. "varargs"
  136. ];
  137. const COMMENT_MODES = [
  138. hljs.C_LINE_COMMENT_MODE,
  139. hljs.COMMENT(/\{/, /\}/, { relevance: 0 }),
  140. hljs.COMMENT(/\(\*/, /\*\)/, { relevance: 10 })
  141. ];
  142. const DIRECTIVE = {
  143. className: 'meta',
  144. variants: [
  145. {
  146. begin: /\{\$/,
  147. end: /\}/
  148. },
  149. {
  150. begin: /\(\*\$/,
  151. end: /\*\)/
  152. }
  153. ]
  154. };
  155. const STRING = {
  156. className: 'string',
  157. begin: /'/,
  158. end: /'/,
  159. contains: [ { begin: /''/ } ]
  160. };
  161. const NUMBER = {
  162. className: 'number',
  163. relevance: 0,
  164. // Source: https://www.freepascal.org/docs-html/ref/refse6.html
  165. variants: [
  166. {
  167. // Regular numbers, e.g., 123, 123.456.
  168. match: /\b\d[\d_]*(\.\d[\d_]*)?/ },
  169. {
  170. // Hexadecimal notation, e.g., $7F.
  171. match: /\$[\dA-Fa-f_]+/ },
  172. {
  173. // Hexadecimal literal with no digits
  174. match: /\$/,
  175. relevance: 0 },
  176. {
  177. // Octal notation, e.g., &42.
  178. match: /&[0-7][0-7_]*/ },
  179. {
  180. // Binary notation, e.g., %1010.
  181. match: /%[01_]+/ },
  182. {
  183. // Binary literal with no digits
  184. match: /%/,
  185. relevance: 0 }
  186. ]
  187. };
  188. const CHAR_STRING = {
  189. className: 'string',
  190. variants: [
  191. { match: /#\d[\d_]*/ },
  192. { match: /#\$[\dA-Fa-f][\dA-Fa-f_]*/ },
  193. { match: /#&[0-7][0-7_]*/ },
  194. { match: /#%[01][01_]*/ }
  195. ]
  196. };
  197. const CLASS = {
  198. begin: hljs.IDENT_RE + '\\s*=\\s*class\\s*\\(',
  199. returnBegin: true,
  200. contains: [ hljs.TITLE_MODE ]
  201. };
  202. const FUNCTION = {
  203. className: 'function',
  204. beginKeywords: 'function constructor destructor procedure',
  205. end: /[:;]/,
  206. keywords: 'function constructor|10 destructor|10 procedure|10',
  207. contains: [
  208. hljs.TITLE_MODE,
  209. {
  210. className: 'params',
  211. begin: /\(/,
  212. end: /\)/,
  213. keywords: KEYWORDS,
  214. contains: [
  215. STRING,
  216. CHAR_STRING,
  217. DIRECTIVE
  218. ].concat(COMMENT_MODES)
  219. },
  220. DIRECTIVE
  221. ].concat(COMMENT_MODES)
  222. };
  223. return {
  224. name: 'Delphi',
  225. aliases: [
  226. 'dpr',
  227. 'dfm',
  228. 'pas',
  229. 'pascal'
  230. ],
  231. case_insensitive: true,
  232. keywords: KEYWORDS,
  233. illegal: /"|\$[G-Zg-z]|\/\*|<\/|\|/,
  234. contains: [
  235. STRING,
  236. CHAR_STRING,
  237. NUMBER,
  238. CLASS,
  239. FUNCTION,
  240. DIRECTIVE
  241. ].concat(COMMENT_MODES)
  242. };
  243. }
  244. export { delphi as default };