prismjs_components_prism-php.js 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. // node_modules/prismjs/components/prism-php.js
  2. (function(Prism2) {
  3. var comment = /\/\*[\s\S]*?\*\/|\/\/.*|#(?!\[).*/;
  4. var constant = [
  5. {
  6. pattern: /\b(?:false|true)\b/i,
  7. alias: "boolean"
  8. },
  9. {
  10. pattern: /(::\s*)\b[a-z_]\w*\b(?!\s*\()/i,
  11. greedy: true,
  12. lookbehind: true
  13. },
  14. {
  15. pattern: /(\b(?:case|const)\s+)\b[a-z_]\w*(?=\s*[;=])/i,
  16. greedy: true,
  17. lookbehind: true
  18. },
  19. /\b(?:null)\b/i,
  20. /\b[A-Z_][A-Z0-9_]*\b(?!\s*\()/
  21. ];
  22. var number = /\b0b[01]+(?:_[01]+)*\b|\b0o[0-7]+(?:_[0-7]+)*\b|\b0x[\da-f]+(?:_[\da-f]+)*\b|(?:\b\d+(?:_\d+)*\.?(?:\d+(?:_\d+)*)?|\B\.\d+)(?:e[+-]?\d+)?/i;
  23. var operator = /<?=>|\?\?=?|\.{3}|\??->|[!=]=?=?|::|\*\*=?|--|\+\+|&&|\|\||<<|>>|[?~]|[/^|%*&<>.+-]=?/;
  24. var punctuation = /[{}\[\](),:;]/;
  25. Prism2.languages.php = {
  26. "delimiter": {
  27. pattern: /\?>$|^<\?(?:php(?=\s)|=)?/i,
  28. alias: "important"
  29. },
  30. "comment": comment,
  31. "variable": /\$+(?:\w+\b|(?=\{))/,
  32. "package": {
  33. pattern: /(namespace\s+|use\s+(?:function\s+)?)(?:\\?\b[a-z_]\w*)+\b(?!\\)/i,
  34. lookbehind: true,
  35. inside: {
  36. "punctuation": /\\/
  37. }
  38. },
  39. "class-name-definition": {
  40. pattern: /(\b(?:class|enum|interface|trait)\s+)\b[a-z_]\w*(?!\\)\b/i,
  41. lookbehind: true,
  42. alias: "class-name"
  43. },
  44. "function-definition": {
  45. pattern: /(\bfunction\s+)[a-z_]\w*(?=\s*\()/i,
  46. lookbehind: true,
  47. alias: "function"
  48. },
  49. "keyword": [
  50. {
  51. pattern: /(\(\s*)\b(?:array|bool|boolean|float|int|integer|object|string)\b(?=\s*\))/i,
  52. alias: "type-casting",
  53. greedy: true,
  54. lookbehind: true
  55. },
  56. {
  57. pattern: /([(,?]\s*)\b(?:array(?!\s*\()|bool|callable|(?:false|null)(?=\s*\|)|float|int|iterable|mixed|object|self|static|string)\b(?=\s*\$)/i,
  58. alias: "type-hint",
  59. greedy: true,
  60. lookbehind: true
  61. },
  62. {
  63. pattern: /(\)\s*:\s*(?:\?\s*)?)\b(?:array(?!\s*\()|bool|callable|(?:false|null)(?=\s*\|)|float|int|iterable|mixed|never|object|self|static|string|void)\b/i,
  64. alias: "return-type",
  65. greedy: true,
  66. lookbehind: true
  67. },
  68. {
  69. pattern: /\b(?:array(?!\s*\()|bool|float|int|iterable|mixed|object|string|void)\b/i,
  70. alias: "type-declaration",
  71. greedy: true
  72. },
  73. {
  74. pattern: /(\|\s*)(?:false|null)\b|\b(?:false|null)(?=\s*\|)/i,
  75. alias: "type-declaration",
  76. greedy: true,
  77. lookbehind: true
  78. },
  79. {
  80. pattern: /\b(?:parent|self|static)(?=\s*::)/i,
  81. alias: "static-context",
  82. greedy: true
  83. },
  84. {
  85. // yield from
  86. pattern: /(\byield\s+)from\b/i,
  87. lookbehind: true
  88. },
  89. // `class` is always a keyword unlike other keywords
  90. /\bclass\b/i,
  91. {
  92. // https://www.php.net/manual/en/reserved.keywords.php
  93. //
  94. // keywords cannot be preceded by "->"
  95. // the complex lookbehind means `(?<!(?:->|::)\s*)`
  96. pattern: /((?:^|[^\s>:]|(?:^|[^-])>|(?:^|[^:]):)\s*)\b(?:abstract|and|array|as|break|callable|case|catch|clone|const|continue|declare|default|die|do|echo|else|elseif|empty|enddeclare|endfor|endforeach|endif|endswitch|endwhile|enum|eval|exit|extends|final|finally|fn|for|foreach|function|global|goto|if|implements|include|include_once|instanceof|insteadof|interface|isset|list|match|namespace|never|new|or|parent|print|private|protected|public|readonly|require|require_once|return|self|static|switch|throw|trait|try|unset|use|var|while|xor|yield|__halt_compiler)\b/i,
  97. lookbehind: true
  98. }
  99. ],
  100. "argument-name": {
  101. pattern: /([(,]\s*)\b[a-z_]\w*(?=\s*:(?!:))/i,
  102. lookbehind: true
  103. },
  104. "class-name": [
  105. {
  106. pattern: /(\b(?:extends|implements|instanceof|new(?!\s+self|\s+static))\s+|\bcatch\s*\()\b[a-z_]\w*(?!\\)\b/i,
  107. greedy: true,
  108. lookbehind: true
  109. },
  110. {
  111. pattern: /(\|\s*)\b[a-z_]\w*(?!\\)\b/i,
  112. greedy: true,
  113. lookbehind: true
  114. },
  115. {
  116. pattern: /\b[a-z_]\w*(?!\\)\b(?=\s*\|)/i,
  117. greedy: true
  118. },
  119. {
  120. pattern: /(\|\s*)(?:\\?\b[a-z_]\w*)+\b/i,
  121. alias: "class-name-fully-qualified",
  122. greedy: true,
  123. lookbehind: true,
  124. inside: {
  125. "punctuation": /\\/
  126. }
  127. },
  128. {
  129. pattern: /(?:\\?\b[a-z_]\w*)+\b(?=\s*\|)/i,
  130. alias: "class-name-fully-qualified",
  131. greedy: true,
  132. inside: {
  133. "punctuation": /\\/
  134. }
  135. },
  136. {
  137. pattern: /(\b(?:extends|implements|instanceof|new(?!\s+self\b|\s+static\b))\s+|\bcatch\s*\()(?:\\?\b[a-z_]\w*)+\b(?!\\)/i,
  138. alias: "class-name-fully-qualified",
  139. greedy: true,
  140. lookbehind: true,
  141. inside: {
  142. "punctuation": /\\/
  143. }
  144. },
  145. {
  146. pattern: /\b[a-z_]\w*(?=\s*\$)/i,
  147. alias: "type-declaration",
  148. greedy: true
  149. },
  150. {
  151. pattern: /(?:\\?\b[a-z_]\w*)+(?=\s*\$)/i,
  152. alias: ["class-name-fully-qualified", "type-declaration"],
  153. greedy: true,
  154. inside: {
  155. "punctuation": /\\/
  156. }
  157. },
  158. {
  159. pattern: /\b[a-z_]\w*(?=\s*::)/i,
  160. alias: "static-context",
  161. greedy: true
  162. },
  163. {
  164. pattern: /(?:\\?\b[a-z_]\w*)+(?=\s*::)/i,
  165. alias: ["class-name-fully-qualified", "static-context"],
  166. greedy: true,
  167. inside: {
  168. "punctuation": /\\/
  169. }
  170. },
  171. {
  172. pattern: /([(,?]\s*)[a-z_]\w*(?=\s*\$)/i,
  173. alias: "type-hint",
  174. greedy: true,
  175. lookbehind: true
  176. },
  177. {
  178. pattern: /([(,?]\s*)(?:\\?\b[a-z_]\w*)+(?=\s*\$)/i,
  179. alias: ["class-name-fully-qualified", "type-hint"],
  180. greedy: true,
  181. lookbehind: true,
  182. inside: {
  183. "punctuation": /\\/
  184. }
  185. },
  186. {
  187. pattern: /(\)\s*:\s*(?:\?\s*)?)\b[a-z_]\w*(?!\\)\b/i,
  188. alias: "return-type",
  189. greedy: true,
  190. lookbehind: true
  191. },
  192. {
  193. pattern: /(\)\s*:\s*(?:\?\s*)?)(?:\\?\b[a-z_]\w*)+\b(?!\\)/i,
  194. alias: ["class-name-fully-qualified", "return-type"],
  195. greedy: true,
  196. lookbehind: true,
  197. inside: {
  198. "punctuation": /\\/
  199. }
  200. }
  201. ],
  202. "constant": constant,
  203. "function": {
  204. pattern: /(^|[^\\\w])\\?[a-z_](?:[\w\\]*\w)?(?=\s*\()/i,
  205. lookbehind: true,
  206. inside: {
  207. "punctuation": /\\/
  208. }
  209. },
  210. "property": {
  211. pattern: /(->\s*)\w+/,
  212. lookbehind: true
  213. },
  214. "number": number,
  215. "operator": operator,
  216. "punctuation": punctuation
  217. };
  218. var string_interpolation = {
  219. pattern: /\{\$(?:\{(?:\{[^{}]+\}|[^{}]+)\}|[^{}])+\}|(^|[^\\{])\$+(?:\w+(?:\[[^\r\n\[\]]+\]|->\w+)?)/,
  220. lookbehind: true,
  221. inside: Prism2.languages.php
  222. };
  223. var string = [
  224. {
  225. pattern: /<<<'([^']+)'[\r\n](?:.*[\r\n])*?\1;/,
  226. alias: "nowdoc-string",
  227. greedy: true,
  228. inside: {
  229. "delimiter": {
  230. pattern: /^<<<'[^']+'|[a-z_]\w*;$/i,
  231. alias: "symbol",
  232. inside: {
  233. "punctuation": /^<<<'?|[';]$/
  234. }
  235. }
  236. }
  237. },
  238. {
  239. pattern: /<<<(?:"([^"]+)"[\r\n](?:.*[\r\n])*?\1;|([a-z_]\w*)[\r\n](?:.*[\r\n])*?\2;)/i,
  240. alias: "heredoc-string",
  241. greedy: true,
  242. inside: {
  243. "delimiter": {
  244. pattern: /^<<<(?:"[^"]+"|[a-z_]\w*)|[a-z_]\w*;$/i,
  245. alias: "symbol",
  246. inside: {
  247. "punctuation": /^<<<"?|[";]$/
  248. }
  249. },
  250. "interpolation": string_interpolation
  251. }
  252. },
  253. {
  254. pattern: /`(?:\\[\s\S]|[^\\`])*`/,
  255. alias: "backtick-quoted-string",
  256. greedy: true
  257. },
  258. {
  259. pattern: /'(?:\\[\s\S]|[^\\'])*'/,
  260. alias: "single-quoted-string",
  261. greedy: true
  262. },
  263. {
  264. pattern: /"(?:\\[\s\S]|[^\\"])*"/,
  265. alias: "double-quoted-string",
  266. greedy: true,
  267. inside: {
  268. "interpolation": string_interpolation
  269. }
  270. }
  271. ];
  272. Prism2.languages.insertBefore("php", "variable", {
  273. "string": string,
  274. "attribute": {
  275. pattern: /#\[(?:[^"'\/#]|\/(?![*/])|\/\/.*$|#(?!\[).*$|\/\*(?:[^*]|\*(?!\/))*\*\/|"(?:\\[\s\S]|[^\\"])*"|'(?:\\[\s\S]|[^\\'])*')+\](?=\s*[a-z$#])/im,
  276. greedy: true,
  277. inside: {
  278. "attribute-content": {
  279. pattern: /^(#\[)[\s\S]+(?=\]$)/,
  280. lookbehind: true,
  281. // inside can appear subset of php
  282. inside: {
  283. "comment": comment,
  284. "string": string,
  285. "attribute-class-name": [
  286. {
  287. pattern: /([^:]|^)\b[a-z_]\w*(?!\\)\b/i,
  288. alias: "class-name",
  289. greedy: true,
  290. lookbehind: true
  291. },
  292. {
  293. pattern: /([^:]|^)(?:\\?\b[a-z_]\w*)+/i,
  294. alias: [
  295. "class-name",
  296. "class-name-fully-qualified"
  297. ],
  298. greedy: true,
  299. lookbehind: true,
  300. inside: {
  301. "punctuation": /\\/
  302. }
  303. }
  304. ],
  305. "constant": constant,
  306. "number": number,
  307. "operator": operator,
  308. "punctuation": punctuation
  309. }
  310. },
  311. "delimiter": {
  312. pattern: /^#\[|\]$/,
  313. alias: "punctuation"
  314. }
  315. }
  316. }
  317. });
  318. Prism2.hooks.add("before-tokenize", function(env) {
  319. if (!/<\?/.test(env.code)) {
  320. return;
  321. }
  322. var phpPattern = /<\?(?:[^"'/#]|\/(?![*/])|("|')(?:\\[\s\S]|(?!\1)[^\\])*\1|(?:\/\/|#(?!\[))(?:[^?\n\r]|\?(?!>))*(?=$|\?>|[\r\n])|#\[|\/\*(?:[^*]|\*(?!\/))*(?:\*\/|$))*?(?:\?>|$)/g;
  323. Prism2.languages["markup-templating"].buildPlaceholders(env, "php", phpPattern);
  324. });
  325. Prism2.hooks.add("after-tokenize", function(env) {
  326. Prism2.languages["markup-templating"].tokenizePlaceholders(env, "php");
  327. });
  328. })(Prism);
  329. //# sourceMappingURL=prismjs_components_prism-php.js.map