delphi.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*
  2. Language: Delphi
  3. Website: https://www.embarcadero.com/products/delphi
  4. */
  5. /** @type LanguageFn */
  6. function delphi(hljs) {
  7. const KEYWORDS =
  8. 'exports register file shl array record property for mod while set ally label uses raise not ' +
  9. 'stored class safecall var interface or private static exit index inherited to else stdcall ' +
  10. 'override shr asm far resourcestring finalization packed virtual out and protected library do ' +
  11. 'xorwrite goto near function end div overload object unit begin string on inline repeat until ' +
  12. 'destructor write message program with read initialization except default nil if case cdecl in ' +
  13. 'downto threadvar of try pascal const external constructor type public then implementation ' +
  14. 'finally published procedure absolute reintroduce operator as is abstract alias assembler ' +
  15. 'bitpacked break continue cppdecl cvar enumerator experimental platform deprecated ' +
  16. 'unimplemented dynamic export far16 forward generic helper implements interrupt iochecks ' +
  17. 'local name nodefault noreturn nostackframe oldfpccall otherwise saveregisters softfloat ' +
  18. 'specialize strict unaligned varargs ';
  19. const COMMENT_MODES = [
  20. hljs.C_LINE_COMMENT_MODE,
  21. hljs.COMMENT(/\{/, /\}/, {
  22. relevance: 0
  23. }),
  24. hljs.COMMENT(/\(\*/, /\*\)/, {
  25. relevance: 10
  26. })
  27. ];
  28. const DIRECTIVE = {
  29. className: 'meta',
  30. variants: [
  31. {
  32. begin: /\{\$/,
  33. end: /\}/
  34. },
  35. {
  36. begin: /\(\*\$/,
  37. end: /\*\)/
  38. }
  39. ]
  40. };
  41. const STRING = {
  42. className: 'string',
  43. begin: /'/,
  44. end: /'/,
  45. contains: [{
  46. begin: /''/
  47. }]
  48. };
  49. const NUMBER = {
  50. className: 'number',
  51. relevance: 0,
  52. // Source: https://www.freepascal.org/docs-html/ref/refse6.html
  53. variants: [
  54. {
  55. // Hexadecimal notation, e.g., $7F.
  56. begin: '\\$[0-9A-Fa-f]+'
  57. },
  58. {
  59. // Octal notation, e.g., &42.
  60. begin: '&[0-7]+'
  61. },
  62. {
  63. // Binary notation, e.g., %1010.
  64. begin: '%[01]+'
  65. }
  66. ]
  67. };
  68. const CHAR_STRING = {
  69. className: 'string',
  70. begin: /(#\d+)+/
  71. };
  72. const CLASS = {
  73. begin: hljs.IDENT_RE + '\\s*=\\s*class\\s*\\(',
  74. returnBegin: true,
  75. contains: [hljs.TITLE_MODE]
  76. };
  77. const FUNCTION = {
  78. className: 'function',
  79. beginKeywords: 'function constructor destructor procedure',
  80. end: /[:;]/,
  81. keywords: 'function constructor|10 destructor|10 procedure|10',
  82. contains: [
  83. hljs.TITLE_MODE,
  84. {
  85. className: 'params',
  86. begin: /\(/,
  87. end: /\)/,
  88. keywords: KEYWORDS,
  89. contains: [
  90. STRING,
  91. CHAR_STRING,
  92. DIRECTIVE
  93. ].concat(COMMENT_MODES)
  94. },
  95. DIRECTIVE
  96. ].concat(COMMENT_MODES)
  97. };
  98. return {
  99. name: 'Delphi',
  100. aliases: [
  101. 'dpr',
  102. 'dfm',
  103. 'pas',
  104. 'pascal',
  105. 'freepascal',
  106. 'lazarus',
  107. 'lpr',
  108. 'lfm'
  109. ],
  110. case_insensitive: true,
  111. keywords: KEYWORDS,
  112. illegal: /"|\$[G-Zg-z]|\/\*|<\/|\|/,
  113. contains: [
  114. STRING,
  115. CHAR_STRING,
  116. hljs.NUMBER_MODE,
  117. NUMBER,
  118. CLASS,
  119. FUNCTION,
  120. DIRECTIVE
  121. ].concat(COMMENT_MODES)
  122. };
  123. }
  124. module.exports = delphi;