zephir.js 3.4 KB

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