zephir.js 3.3 KB

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