php.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /*
  2. Language: PHP
  3. Author: Victor Karamzin <[email protected]>
  4. Contributors: Evgeny Stepanischev <[email protected]>, Ivan Sagalaev <[email protected]>
  5. Category: common
  6. */
  7. function(hljs) {
  8. var VARIABLE = {
  9. begin: '\\$+[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*'
  10. };
  11. var PREPROCESSOR = {
  12. className: 'meta', begin: /<\?(php)?|\?>/
  13. };
  14. var STRING = {
  15. className: 'string',
  16. contains: [hljs.BACKSLASH_ESCAPE, PREPROCESSOR],
  17. variants: [
  18. {
  19. begin: 'b"', end: '"'
  20. },
  21. {
  22. begin: 'b\'', end: '\''
  23. },
  24. hljs.inherit(hljs.APOS_STRING_MODE, {illegal: null}),
  25. hljs.inherit(hljs.QUOTE_STRING_MODE, {illegal: null})
  26. ]
  27. };
  28. var NUMBER = {variants: [hljs.BINARY_NUMBER_MODE, hljs.C_NUMBER_MODE]};
  29. return {
  30. aliases: ['php3', 'php4', 'php5', 'php6'],
  31. case_insensitive: true,
  32. keywords:
  33. 'and include_once list abstract global private echo interface as static endswitch ' +
  34. 'array null if endwhile or const for endforeach self var while isset public ' +
  35. 'protected exit foreach throw elseif include __FILE__ empty require_once do xor ' +
  36. 'return parent clone use __CLASS__ __LINE__ else break print eval new ' +
  37. 'catch __METHOD__ case exception default die require __FUNCTION__ ' +
  38. 'enddeclare final try switch continue endfor endif declare unset true false ' +
  39. 'trait goto instanceof insteadof __DIR__ __NAMESPACE__ ' +
  40. 'yield finally',
  41. contains: [
  42. hljs.HASH_COMMENT_MODE,
  43. hljs.COMMENT('//', '$', {contains: [PREPROCESSOR]}),
  44. hljs.COMMENT(
  45. '/\\*',
  46. '\\*/',
  47. {
  48. contains: [
  49. {
  50. className: 'doctag',
  51. begin: '@[A-Za-z]+'
  52. }
  53. ]
  54. }
  55. ),
  56. hljs.COMMENT(
  57. '__halt_compiler.+?;',
  58. false,
  59. {
  60. endsWithParent: true,
  61. keywords: '__halt_compiler',
  62. lexemes: hljs.UNDERSCORE_IDENT_RE
  63. }
  64. ),
  65. {
  66. className: 'string',
  67. begin: /<<<['"]?\w+['"]?$/, end: /^\w+;?$/,
  68. contains: [
  69. hljs.BACKSLASH_ESCAPE,
  70. {
  71. className: 'subst',
  72. variants: [
  73. {begin: /\$\w+/},
  74. {begin: /\{\$/, end: /\}/}
  75. ]
  76. }
  77. ]
  78. },
  79. PREPROCESSOR,
  80. {
  81. className: 'keyword', begin: /\$this\b/
  82. },
  83. VARIABLE,
  84. {
  85. // swallow composed identifiers to avoid parsing them as keywords
  86. begin: /(::|->)+[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*/
  87. },
  88. {
  89. className: 'function',
  90. beginKeywords: 'function', end: /[;{]/, excludeEnd: true,
  91. illegal: '\\$|\\[|%',
  92. contains: [
  93. hljs.UNDERSCORE_TITLE_MODE,
  94. {
  95. className: 'params',
  96. begin: '\\(', end: '\\)',
  97. contains: [
  98. 'self',
  99. VARIABLE,
  100. hljs.C_BLOCK_COMMENT_MODE,
  101. STRING,
  102. NUMBER
  103. ]
  104. }
  105. ]
  106. },
  107. {
  108. className: 'class',
  109. beginKeywords: 'class interface', end: '{', excludeEnd: true,
  110. illegal: /[:\(\$"]/,
  111. contains: [
  112. {beginKeywords: 'extends implements'},
  113. hljs.UNDERSCORE_TITLE_MODE
  114. ]
  115. },
  116. {
  117. beginKeywords: 'namespace', end: ';',
  118. illegal: /[\.']/,
  119. contains: [hljs.UNDERSCORE_TITLE_MODE]
  120. },
  121. {
  122. beginKeywords: 'use', end: ';',
  123. contains: [hljs.UNDERSCORE_TITLE_MODE]
  124. },
  125. {
  126. begin: '=>' // No markup, just a relevance booster
  127. },
  128. STRING,
  129. NUMBER
  130. ]
  131. };
  132. }