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