[d24f17c] | 1 | /*
|
---|
| 2 | Language: Zephir
|
---|
| 3 | 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.
|
---|
| 4 | Author: Oleg Efimov <efimovov@gmail.com>
|
---|
| 5 | Website: https://zephir-lang.com/en
|
---|
| 6 | Audit: 2020
|
---|
| 7 | */
|
---|
| 8 |
|
---|
| 9 | /** @type LanguageFn */
|
---|
| 10 | function zephir(hljs) {
|
---|
| 11 | const STRING = {
|
---|
| 12 | className: 'string',
|
---|
| 13 | contains: [ hljs.BACKSLASH_ESCAPE ],
|
---|
| 14 | variants: [
|
---|
| 15 | hljs.inherit(hljs.APOS_STRING_MODE, {
|
---|
| 16 | illegal: null
|
---|
| 17 | }),
|
---|
| 18 | hljs.inherit(hljs.QUOTE_STRING_MODE, {
|
---|
| 19 | illegal: null
|
---|
| 20 | })
|
---|
| 21 | ]
|
---|
| 22 | };
|
---|
| 23 | const TITLE_MODE = hljs.UNDERSCORE_TITLE_MODE;
|
---|
| 24 | const NUMBER = {
|
---|
| 25 | variants: [
|
---|
| 26 | hljs.BINARY_NUMBER_MODE,
|
---|
| 27 | hljs.C_NUMBER_MODE
|
---|
| 28 | ]
|
---|
| 29 | };
|
---|
| 30 | const KEYWORDS =
|
---|
| 31 | // classes and objects
|
---|
| 32 | 'namespace class interface use extends ' +
|
---|
| 33 | 'function return ' +
|
---|
| 34 | 'abstract final public protected private static deprecated ' +
|
---|
| 35 | // error handling
|
---|
| 36 | 'throw try catch Exception ' +
|
---|
| 37 | // keyword-ish things their website does NOT seem to highlight (in their own snippets)
|
---|
| 38 | // 'typeof fetch in ' +
|
---|
| 39 | // operators/helpers
|
---|
| 40 | 'echo empty isset instanceof unset ' +
|
---|
| 41 | // assignment/variables
|
---|
| 42 | 'let var new const self ' +
|
---|
| 43 | // control
|
---|
| 44 | 'require ' +
|
---|
| 45 | 'if else elseif switch case default ' +
|
---|
| 46 | 'do while loop for continue break ' +
|
---|
| 47 | 'likely unlikely ' +
|
---|
| 48 | // magic constants
|
---|
| 49 | // https://github.com/phalcon/zephir/blob/master/Library/Expression/Constants.php
|
---|
| 50 | '__LINE__ __FILE__ __DIR__ __FUNCTION__ __CLASS__ __TRAIT__ __METHOD__ __NAMESPACE__ ' +
|
---|
| 51 | // types - https://docs.zephir-lang.com/0.12/en/types
|
---|
| 52 | 'array boolean float double integer object resource string ' +
|
---|
| 53 | 'char long unsigned bool int uint ulong uchar ' +
|
---|
| 54 | // built-ins
|
---|
| 55 | 'true false null undefined';
|
---|
| 56 |
|
---|
| 57 | return {
|
---|
| 58 | name: 'Zephir',
|
---|
| 59 | aliases: [ 'zep' ],
|
---|
| 60 | keywords: KEYWORDS,
|
---|
| 61 | contains: [
|
---|
| 62 | hljs.C_LINE_COMMENT_MODE,
|
---|
| 63 | hljs.COMMENT(
|
---|
| 64 | /\/\*/,
|
---|
| 65 | /\*\//,
|
---|
| 66 | {
|
---|
| 67 | contains: [
|
---|
| 68 | {
|
---|
| 69 | className: 'doctag',
|
---|
| 70 | begin: /@[A-Za-z]+/
|
---|
| 71 | }
|
---|
| 72 | ]
|
---|
| 73 | }
|
---|
| 74 | ),
|
---|
| 75 | {
|
---|
| 76 | className: 'string',
|
---|
| 77 | begin: /<<<['"]?\w+['"]?$/,
|
---|
| 78 | end: /^\w+;/,
|
---|
| 79 | contains: [ hljs.BACKSLASH_ESCAPE ]
|
---|
| 80 | },
|
---|
| 81 | {
|
---|
| 82 | // swallow composed identifiers to avoid parsing them as keywords
|
---|
| 83 | begin: /(::|->)+[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*/
|
---|
| 84 | },
|
---|
| 85 | {
|
---|
| 86 | className: 'function',
|
---|
| 87 | beginKeywords: 'function fn',
|
---|
| 88 | end: /[;{]/,
|
---|
| 89 | excludeEnd: true,
|
---|
| 90 | illegal: /\$|\[|%/,
|
---|
| 91 | contains: [
|
---|
| 92 | TITLE_MODE,
|
---|
| 93 | {
|
---|
| 94 | className: 'params',
|
---|
| 95 | begin: /\(/,
|
---|
| 96 | end: /\)/,
|
---|
| 97 | keywords: KEYWORDS,
|
---|
| 98 | contains: [
|
---|
| 99 | 'self',
|
---|
| 100 | hljs.C_BLOCK_COMMENT_MODE,
|
---|
| 101 | STRING,
|
---|
| 102 | NUMBER
|
---|
| 103 | ]
|
---|
| 104 | }
|
---|
| 105 | ]
|
---|
| 106 | },
|
---|
| 107 | {
|
---|
| 108 | className: 'class',
|
---|
| 109 | beginKeywords: 'class interface',
|
---|
| 110 | end: /\{/,
|
---|
| 111 | excludeEnd: true,
|
---|
| 112 | illegal: /[:($"]/,
|
---|
| 113 | contains: [
|
---|
| 114 | {
|
---|
| 115 | beginKeywords: 'extends implements'
|
---|
| 116 | },
|
---|
| 117 | TITLE_MODE
|
---|
| 118 | ]
|
---|
| 119 | },
|
---|
| 120 | {
|
---|
| 121 | beginKeywords: 'namespace',
|
---|
| 122 | end: /;/,
|
---|
| 123 | illegal: /[.']/,
|
---|
| 124 | contains: [ TITLE_MODE ]
|
---|
| 125 | },
|
---|
| 126 | {
|
---|
| 127 | beginKeywords: 'use',
|
---|
| 128 | end: /;/,
|
---|
| 129 | contains: [ TITLE_MODE ]
|
---|
| 130 | },
|
---|
| 131 | {
|
---|
| 132 | begin: /=>/ // No markup, just a relevance booster
|
---|
| 133 | },
|
---|
| 134 | STRING,
|
---|
| 135 | NUMBER
|
---|
| 136 | ]
|
---|
| 137 | };
|
---|
| 138 | }
|
---|
| 139 |
|
---|
| 140 | module.exports = zephir;
|
---|