123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246 |
- /*
- Language: Delphi
- Website: https://www.embarcadero.com/products/delphi
- Category: system
- */
- /** @type LanguageFn */
- function delphi(hljs) {
- const KEYWORDS = [
- "exports",
- "register",
- "file",
- "shl",
- "array",
- "record",
- "property",
- "for",
- "mod",
- "while",
- "set",
- "ally",
- "label",
- "uses",
- "raise",
- "not",
- "stored",
- "class",
- "safecall",
- "var",
- "interface",
- "or",
- "private",
- "static",
- "exit",
- "index",
- "inherited",
- "to",
- "else",
- "stdcall",
- "override",
- "shr",
- "asm",
- "far",
- "resourcestring",
- "finalization",
- "packed",
- "virtual",
- "out",
- "and",
- "protected",
- "library",
- "do",
- "xorwrite",
- "goto",
- "near",
- "function",
- "end",
- "div",
- "overload",
- "object",
- "unit",
- "begin",
- "string",
- "on",
- "inline",
- "repeat",
- "until",
- "destructor",
- "write",
- "message",
- "program",
- "with",
- "read",
- "initialization",
- "except",
- "default",
- "nil",
- "if",
- "case",
- "cdecl",
- "in",
- "downto",
- "threadvar",
- "of",
- "try",
- "pascal",
- "const",
- "external",
- "constructor",
- "type",
- "public",
- "then",
- "implementation",
- "finally",
- "published",
- "procedure",
- "absolute",
- "reintroduce",
- "operator",
- "as",
- "is",
- "abstract",
- "alias",
- "assembler",
- "bitpacked",
- "break",
- "continue",
- "cppdecl",
- "cvar",
- "enumerator",
- "experimental",
- "platform",
- "deprecated",
- "unimplemented",
- "dynamic",
- "export",
- "far16",
- "forward",
- "generic",
- "helper",
- "implements",
- "interrupt",
- "iochecks",
- "local",
- "name",
- "nodefault",
- "noreturn",
- "nostackframe",
- "oldfpccall",
- "otherwise",
- "saveregisters",
- "softfloat",
- "specialize",
- "strict",
- "unaligned",
- "varargs"
- ];
- const COMMENT_MODES = [
- hljs.C_LINE_COMMENT_MODE,
- hljs.COMMENT(/\{/, /\}/, { relevance: 0 }),
- hljs.COMMENT(/\(\*/, /\*\)/, { relevance: 10 })
- ];
- const DIRECTIVE = {
- className: 'meta',
- variants: [
- {
- begin: /\{\$/,
- end: /\}/
- },
- {
- begin: /\(\*\$/,
- end: /\*\)/
- }
- ]
- };
- const STRING = {
- className: 'string',
- begin: /'/,
- end: /'/,
- contains: [ { begin: /''/ } ]
- };
- const NUMBER = {
- className: 'number',
- relevance: 0,
- // Source: https://www.freepascal.org/docs-html/ref/refse6.html
- variants: [
- {
- // Regular numbers, e.g., 123, 123.456.
- match: /\b\d[\d_]*(\.\d[\d_]*)?/ },
- {
- // Hexadecimal notation, e.g., $7F.
- match: /\$[\dA-Fa-f_]+/ },
- {
- // Hexadecimal literal with no digits
- match: /\$/,
- relevance: 0 },
- {
- // Octal notation, e.g., &42.
- match: /&[0-7][0-7_]*/ },
- {
- // Binary notation, e.g., %1010.
- match: /%[01_]+/ },
- {
- // Binary literal with no digits
- match: /%/,
- relevance: 0 }
- ]
- };
- const CHAR_STRING = {
- className: 'string',
- variants: [
- { match: /#\d[\d_]*/ },
- { match: /#\$[\dA-Fa-f][\dA-Fa-f_]*/ },
- { match: /#&[0-7][0-7_]*/ },
- { match: /#%[01][01_]*/ }
- ]
- };
- const CLASS = {
- begin: hljs.IDENT_RE + '\\s*=\\s*class\\s*\\(',
- returnBegin: true,
- contains: [ hljs.TITLE_MODE ]
- };
- const FUNCTION = {
- className: 'function',
- beginKeywords: 'function constructor destructor procedure',
- end: /[:;]/,
- keywords: 'function constructor|10 destructor|10 procedure|10',
- contains: [
- hljs.TITLE_MODE,
- {
- className: 'params',
- begin: /\(/,
- end: /\)/,
- keywords: KEYWORDS,
- contains: [
- STRING,
- CHAR_STRING,
- DIRECTIVE
- ].concat(COMMENT_MODES)
- },
- DIRECTIVE
- ].concat(COMMENT_MODES)
- };
- return {
- name: 'Delphi',
- aliases: [
- 'dpr',
- 'dfm',
- 'pas',
- 'pascal'
- ],
- case_insensitive: true,
- keywords: KEYWORDS,
- illegal: /"|\$[G-Zg-z]|\/\*|<\/|\|/,
- contains: [
- STRING,
- CHAR_STRING,
- NUMBER,
- CLASS,
- FUNCTION,
- DIRECTIVE
- ].concat(COMMENT_MODES)
- };
- }
- export { delphi as default };
|