zephir.js 3.5 KB

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