2024-01-16 21:26:16 +08:00
|
|
|
/*
|
|
|
|
Language: Zephir
|
|
|
|
Description: Zephir, an open source, high-level language designed to ease the creation and maintainability of extensions for PHP with a focus on type and memory safety.
|
|
|
|
Author: Oleg Efimov <efimovov@gmail.com>
|
|
|
|
Website: https://zephir-lang.com/en
|
|
|
|
Audit: 2020
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** @type LanguageFn */
|
|
|
|
function zephir(hljs) {
|
|
|
|
const STRING = {
|
2023-12-18 13:12:25 +08:00
|
|
|
className: 'string',
|
2024-01-16 21:26:16 +08:00
|
|
|
contains: [ hljs.BACKSLASH_ESCAPE ],
|
2023-12-18 13:12:25 +08:00
|
|
|
variants: [
|
2024-01-16 21:26:16 +08:00
|
|
|
hljs.inherit(hljs.APOS_STRING_MODE, {
|
|
|
|
illegal: null
|
|
|
|
}),
|
|
|
|
hljs.inherit(hljs.QUOTE_STRING_MODE, {
|
|
|
|
illegal: null
|
|
|
|
})
|
|
|
|
]
|
|
|
|
};
|
|
|
|
const TITLE_MODE = hljs.UNDERSCORE_TITLE_MODE;
|
|
|
|
const NUMBER = {
|
|
|
|
variants: [
|
|
|
|
hljs.BINARY_NUMBER_MODE,
|
|
|
|
hljs.C_NUMBER_MODE
|
2023-12-18 13:12:25 +08:00
|
|
|
]
|
|
|
|
};
|
2024-01-16 21:26:16 +08:00
|
|
|
const KEYWORDS =
|
|
|
|
// classes and objects
|
|
|
|
'namespace class interface use extends ' +
|
|
|
|
'function return ' +
|
|
|
|
'abstract final public protected private static deprecated ' +
|
|
|
|
// error handling
|
|
|
|
'throw try catch Exception ' +
|
|
|
|
// keyword-ish things their website does NOT seem to highlight (in their own snippets)
|
|
|
|
// 'typeof fetch in ' +
|
|
|
|
// operators/helpers
|
|
|
|
'echo empty isset instanceof unset ' +
|
|
|
|
// assignment/variables
|
|
|
|
'let var new const self ' +
|
|
|
|
// control
|
|
|
|
'require ' +
|
|
|
|
'if else elseif switch case default ' +
|
|
|
|
'do while loop for continue break ' +
|
|
|
|
'likely unlikely ' +
|
|
|
|
// magic constants
|
|
|
|
// https://github.com/phalcon/zephir/blob/master/Library/Expression/Constants.php
|
|
|
|
'__LINE__ __FILE__ __DIR__ __FUNCTION__ __CLASS__ __TRAIT__ __METHOD__ __NAMESPACE__ ' +
|
|
|
|
// types - https://docs.zephir-lang.com/0.12/en/types
|
|
|
|
'array boolean float double integer object resource string ' +
|
|
|
|
'char long unsigned bool int uint ulong uchar ' +
|
|
|
|
// built-ins
|
|
|
|
'true false null undefined';
|
|
|
|
|
2023-12-18 13:12:25 +08:00
|
|
|
return {
|
2024-01-16 21:26:16 +08:00
|
|
|
name: 'Zephir',
|
|
|
|
aliases: [ 'zep' ],
|
|
|
|
keywords: KEYWORDS,
|
2023-12-18 13:12:25 +08:00
|
|
|
contains: [
|
|
|
|
hljs.C_LINE_COMMENT_MODE,
|
|
|
|
hljs.COMMENT(
|
2024-01-16 21:26:16 +08:00
|
|
|
/\/\*/,
|
|
|
|
/\*\//,
|
2023-12-18 13:12:25 +08:00
|
|
|
{
|
|
|
|
contains: [
|
|
|
|
{
|
|
|
|
className: 'doctag',
|
2024-01-16 21:26:16 +08:00
|
|
|
begin: /@[A-Za-z]+/
|
2023-12-18 13:12:25 +08:00
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
),
|
|
|
|
{
|
|
|
|
className: 'string',
|
2024-01-16 21:26:16 +08:00
|
|
|
begin: /<<<['"]?\w+['"]?$/,
|
|
|
|
end: /^\w+;/,
|
|
|
|
contains: [ hljs.BACKSLASH_ESCAPE ]
|
2023-12-18 13:12:25 +08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
// swallow composed identifiers to avoid parsing them as keywords
|
|
|
|
begin: /(::|->)+[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*/
|
|
|
|
},
|
|
|
|
{
|
|
|
|
className: 'function',
|
2024-01-16 21:26:16 +08:00
|
|
|
beginKeywords: 'function fn',
|
|
|
|
end: /[;{]/,
|
|
|
|
excludeEnd: true,
|
|
|
|
illegal: /\$|\[|%/,
|
2023-12-18 13:12:25 +08:00
|
|
|
contains: [
|
2024-01-16 21:26:16 +08:00
|
|
|
TITLE_MODE,
|
2023-12-18 13:12:25 +08:00
|
|
|
{
|
|
|
|
className: 'params',
|
2024-01-16 21:26:16 +08:00
|
|
|
begin: /\(/,
|
|
|
|
end: /\)/,
|
|
|
|
keywords: KEYWORDS,
|
2023-12-18 13:12:25 +08:00
|
|
|
contains: [
|
|
|
|
'self',
|
|
|
|
hljs.C_BLOCK_COMMENT_MODE,
|
|
|
|
STRING,
|
|
|
|
NUMBER
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
className: 'class',
|
2024-01-16 21:26:16 +08:00
|
|
|
beginKeywords: 'class interface',
|
|
|
|
end: /\{/,
|
|
|
|
excludeEnd: true,
|
|
|
|
illegal: /[:($"]/,
|
2023-12-18 13:12:25 +08:00
|
|
|
contains: [
|
2024-01-16 21:26:16 +08:00
|
|
|
{
|
|
|
|
beginKeywords: 'extends implements'
|
|
|
|
},
|
|
|
|
TITLE_MODE
|
2023-12-18 13:12:25 +08:00
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
2024-01-16 21:26:16 +08:00
|
|
|
beginKeywords: 'namespace',
|
|
|
|
end: /;/,
|
|
|
|
illegal: /[.']/,
|
|
|
|
contains: [ TITLE_MODE ]
|
2023-12-18 13:12:25 +08:00
|
|
|
},
|
|
|
|
{
|
2024-01-16 21:26:16 +08:00
|
|
|
beginKeywords: 'use',
|
|
|
|
end: /;/,
|
|
|
|
contains: [ TITLE_MODE ]
|
2023-12-18 13:12:25 +08:00
|
|
|
},
|
|
|
|
{
|
2024-01-16 21:26:16 +08:00
|
|
|
begin: /=>/ // No markup, just a relevance booster
|
2023-12-18 13:12:25 +08:00
|
|
|
},
|
|
|
|
STRING,
|
|
|
|
NUMBER
|
|
|
|
]
|
|
|
|
};
|
2024-01-16 21:26:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = zephir;
|