zephir.js 3.4 KB

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