zephir.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. module.exports = function(hljs) {
  2. var STRING = {
  3. className: 'string',
  4. contains: [hljs.BACKSLASH_ESCAPE],
  5. variants: [
  6. {
  7. begin: 'b"', end: '"'
  8. },
  9. {
  10. begin: 'b\'', end: '\''
  11. },
  12. hljs.inherit(hljs.APOS_STRING_MODE, {illegal: null}),
  13. hljs.inherit(hljs.QUOTE_STRING_MODE, {illegal: null})
  14. ]
  15. };
  16. var NUMBER = {variants: [hljs.BINARY_NUMBER_MODE, hljs.C_NUMBER_MODE]};
  17. return {
  18. aliases: ['zep'],
  19. case_insensitive: true,
  20. keywords:
  21. 'and include_once list abstract global private echo interface as static endswitch ' +
  22. 'array null if endwhile or const for endforeach self var let while isset public ' +
  23. 'protected exit foreach throw elseif include __FILE__ empty require_once do xor ' +
  24. 'return parent clone use __CLASS__ __LINE__ else break print eval new ' +
  25. 'catch __METHOD__ case exception default die require __FUNCTION__ ' +
  26. 'enddeclare final try switch continue endfor endif declare unset true false ' +
  27. 'trait goto instanceof insteadof __DIR__ __NAMESPACE__ ' +
  28. 'yield finally int uint long ulong char uchar double float bool boolean string' +
  29. 'likely unlikely',
  30. contains: [
  31. hljs.C_LINE_COMMENT_MODE,
  32. hljs.HASH_COMMENT_MODE,
  33. hljs.COMMENT(
  34. '/\\*',
  35. '\\*/',
  36. {
  37. contains: [
  38. {
  39. className: 'doctag',
  40. begin: '@[A-Za-z]+'
  41. }
  42. ]
  43. }
  44. ),
  45. hljs.COMMENT(
  46. '__halt_compiler.+?;',
  47. false,
  48. {
  49. endsWithParent: true,
  50. keywords: '__halt_compiler',
  51. lexemes: hljs.UNDERSCORE_IDENT_RE
  52. }
  53. ),
  54. {
  55. className: 'string',
  56. begin: '<<<[\'"]?\\w+[\'"]?$', end: '^\\w+;',
  57. contains: [hljs.BACKSLASH_ESCAPE]
  58. },
  59. {
  60. // swallow composed identifiers to avoid parsing them as keywords
  61. begin: /(::|->)+[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*/
  62. },
  63. {
  64. className: 'function',
  65. beginKeywords: 'function', end: /[;{]/, excludeEnd: true,
  66. illegal: '\\$|\\[|%',
  67. contains: [
  68. hljs.UNDERSCORE_TITLE_MODE,
  69. {
  70. className: 'params',
  71. begin: '\\(', end: '\\)',
  72. contains: [
  73. 'self',
  74. hljs.C_BLOCK_COMMENT_MODE,
  75. STRING,
  76. NUMBER
  77. ]
  78. }
  79. ]
  80. },
  81. {
  82. className: 'class',
  83. beginKeywords: 'class interface', end: '{', excludeEnd: true,
  84. illegal: /[:\(\$"]/,
  85. contains: [
  86. {beginKeywords: 'extends implements'},
  87. hljs.UNDERSCORE_TITLE_MODE
  88. ]
  89. },
  90. {
  91. beginKeywords: 'namespace', end: ';',
  92. illegal: /[\.']/,
  93. contains: [hljs.UNDERSCORE_TITLE_MODE]
  94. },
  95. {
  96. beginKeywords: 'use', end: ';',
  97. contains: [hljs.UNDERSCORE_TITLE_MODE]
  98. },
  99. {
  100. begin: '=>' // No markup, just a relevance booster
  101. },
  102. STRING,
  103. NUMBER
  104. ]
  105. };
  106. };