delphi.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. module.exports = function(hljs) {
  2. var KEYWORDS =
  3. 'exports register file shl array record property for mod while set ally label uses raise not ' +
  4. 'stored class safecall var interface or private static exit index inherited to else stdcall ' +
  5. 'override shr asm far resourcestring finalization packed virtual out and protected library do ' +
  6. 'xorwrite goto near function end div overload object unit begin string on inline repeat until ' +
  7. 'destructor write message program with read initialization except default nil if case cdecl in ' +
  8. 'downto threadvar of try pascal const external constructor type public then implementation ' +
  9. 'finally published procedure absolute reintroduce operator as is abstract alias assembler ' +
  10. 'bitpacked break continue cppdecl cvar enumerator experimental platform deprecated ' +
  11. 'unimplemented dynamic export far16 forward generic helper implements interrupt iochecks ' +
  12. 'local name nodefault noreturn nostackframe oldfpccall otherwise saveregisters softfloat ' +
  13. 'specialize strict unaligned varargs ';
  14. var COMMENT_MODES = [
  15. hljs.C_LINE_COMMENT_MODE,
  16. hljs.COMMENT(/\{/, /\}/, {relevance: 0}),
  17. hljs.COMMENT(/\(\*/, /\*\)/, {relevance: 10})
  18. ];
  19. var DIRECTIVE = {
  20. className: 'meta',
  21. variants: [
  22. {begin: /\{\$/, end: /\}/},
  23. {begin: /\(\*\$/, end: /\*\)/}
  24. ]
  25. };
  26. var STRING = {
  27. className: 'string',
  28. begin: /'/, end: /'/,
  29. contains: [{begin: /''/}]
  30. };
  31. var CHAR_STRING = {
  32. className: 'string', begin: /(#\d+)+/
  33. };
  34. var CLASS = {
  35. begin: hljs.IDENT_RE + '\\s*=\\s*class\\s*\\(', returnBegin: true,
  36. contains: [
  37. hljs.TITLE_MODE
  38. ]
  39. };
  40. var FUNCTION = {
  41. className: 'function',
  42. beginKeywords: 'function constructor destructor procedure', end: /[:;]/,
  43. keywords: 'function constructor|10 destructor|10 procedure|10',
  44. contains: [
  45. hljs.TITLE_MODE,
  46. {
  47. className: 'params',
  48. begin: /\(/, end: /\)/,
  49. keywords: KEYWORDS,
  50. contains: [STRING, CHAR_STRING, DIRECTIVE].concat(COMMENT_MODES)
  51. },
  52. DIRECTIVE
  53. ].concat(COMMENT_MODES)
  54. };
  55. return {
  56. aliases: ['dpr', 'dfm', 'pas', 'pascal', 'freepascal', 'lazarus', 'lpr', 'lfm'],
  57. case_insensitive: true,
  58. keywords: KEYWORDS,
  59. illegal: /"|\$[G-Zg-z]|\/\*|<\/|\|/,
  60. contains: [
  61. STRING, CHAR_STRING,
  62. hljs.NUMBER_MODE,
  63. CLASS,
  64. FUNCTION,
  65. DIRECTIVE
  66. ].concat(COMMENT_MODES)
  67. };
  68. };