php.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579
  1. /*---------------------------------------------------------------------------------------------
  2. * Copyright (c) Microsoft Corporation. All rights reserved.
  3. * Licensed under the MIT License. See License.txt in the project root for license information.
  4. *--------------------------------------------------------------------------------------------*/
  5. define('vs/basic-languages/php/php',["require", "exports"], function (require, exports) {
  6. "use strict";
  7. Object.defineProperty(exports, "__esModule", { value: true });
  8. exports.language = exports.conf = void 0;
  9. exports.conf = {
  10. wordPattern: /(-?\d*\.\d\w*)|([^\`\~\!\@\#\%\^\&\*\(\)\-\=\+\[\{\]\}\\\|\;\:\'\"\,\.\<\>\/\?\s]+)/g,
  11. comments: {
  12. lineComment: '//',
  13. blockComment: ['/*', '*/']
  14. },
  15. brackets: [
  16. ['{', '}'],
  17. ['[', ']'],
  18. ['(', ')']
  19. ],
  20. autoClosingPairs: [
  21. { open: '{', close: '}', notIn: ['string'] },
  22. { open: '[', close: ']', notIn: ['string'] },
  23. { open: '(', close: ')', notIn: ['string'] },
  24. { open: '"', close: '"', notIn: ['string'] },
  25. { open: "'", close: "'", notIn: ['string', 'comment'] }
  26. ],
  27. folding: {
  28. markers: {
  29. start: new RegExp('^\\s*(#|//)region\\b'),
  30. end: new RegExp('^\\s*(#|//)endregion\\b')
  31. }
  32. }
  33. };
  34. exports.language = {
  35. defaultToken: '',
  36. tokenPostfix: '',
  37. // ignoreCase: true,
  38. // The main tokenizer for our languages
  39. tokenizer: {
  40. root: [
  41. [/<\?((php)|=)?/, { token: '@rematch', switchTo: '@phpInSimpleState.root' }],
  42. [/<!DOCTYPE/, 'metatag.html', '@doctype'],
  43. [/<!--/, 'comment.html', '@comment'],
  44. [/(<)(\w+)(\/>)/, ['delimiter.html', 'tag.html', 'delimiter.html']],
  45. [/(<)(script)/, ['delimiter.html', { token: 'tag.html', next: '@script' }]],
  46. [/(<)(style)/, ['delimiter.html', { token: 'tag.html', next: '@style' }]],
  47. [/(<)([:\w]+)/, ['delimiter.html', { token: 'tag.html', next: '@otherTag' }]],
  48. [/(<\/)(\w+)/, ['delimiter.html', { token: 'tag.html', next: '@otherTag' }]],
  49. [/</, 'delimiter.html'],
  50. [/[^<]+/] // text
  51. ],
  52. doctype: [
  53. [/<\?((php)|=)?/, { token: '@rematch', switchTo: '@phpInSimpleState.comment' }],
  54. [/[^>]+/, 'metatag.content.html'],
  55. [/>/, 'metatag.html', '@pop']
  56. ],
  57. comment: [
  58. [/<\?((php)|=)?/, { token: '@rematch', switchTo: '@phpInSimpleState.comment' }],
  59. [/-->/, 'comment.html', '@pop'],
  60. [/[^-]+/, 'comment.content.html'],
  61. [/./, 'comment.content.html']
  62. ],
  63. otherTag: [
  64. [/<\?((php)|=)?/, { token: '@rematch', switchTo: '@phpInSimpleState.otherTag' }],
  65. [/\/?>/, 'delimiter.html', '@pop'],
  66. [/"([^"]*)"/, 'attribute.value'],
  67. [/'([^']*)'/, 'attribute.value'],
  68. [/[\w\-]+/, 'attribute.name'],
  69. [/=/, 'delimiter'],
  70. [/[ \t\r\n]+/] // whitespace
  71. ],
  72. // -- BEGIN <script> tags handling
  73. // After <script
  74. script: [
  75. [/<\?((php)|=)?/, { token: '@rematch', switchTo: '@phpInSimpleState.script' }],
  76. [/type/, 'attribute.name', '@scriptAfterType'],
  77. [/"([^"]*)"/, 'attribute.value'],
  78. [/'([^']*)'/, 'attribute.value'],
  79. [/[\w\-]+/, 'attribute.name'],
  80. [/=/, 'delimiter'],
  81. [
  82. />/,
  83. {
  84. token: 'delimiter.html',
  85. next: '@scriptEmbedded.text/javascript',
  86. nextEmbedded: 'text/javascript'
  87. }
  88. ],
  89. [/[ \t\r\n]+/],
  90. [
  91. /(<\/)(script\s*)(>)/,
  92. ['delimiter.html', 'tag.html', { token: 'delimiter.html', next: '@pop' }]
  93. ]
  94. ],
  95. // After <script ... type
  96. scriptAfterType: [
  97. [
  98. /<\?((php)|=)?/,
  99. {
  100. token: '@rematch',
  101. switchTo: '@phpInSimpleState.scriptAfterType'
  102. }
  103. ],
  104. [/=/, 'delimiter', '@scriptAfterTypeEquals'],
  105. [
  106. />/,
  107. {
  108. token: 'delimiter.html',
  109. next: '@scriptEmbedded.text/javascript',
  110. nextEmbedded: 'text/javascript'
  111. }
  112. ],
  113. [/[ \t\r\n]+/],
  114. [/<\/script\s*>/, { token: '@rematch', next: '@pop' }]
  115. ],
  116. // After <script ... type =
  117. scriptAfterTypeEquals: [
  118. [
  119. /<\?((php)|=)?/,
  120. {
  121. token: '@rematch',
  122. switchTo: '@phpInSimpleState.scriptAfterTypeEquals'
  123. }
  124. ],
  125. [
  126. /"([^"]*)"/,
  127. {
  128. token: 'attribute.value',
  129. switchTo: '@scriptWithCustomType.$1'
  130. }
  131. ],
  132. [
  133. /'([^']*)'/,
  134. {
  135. token: 'attribute.value',
  136. switchTo: '@scriptWithCustomType.$1'
  137. }
  138. ],
  139. [
  140. />/,
  141. {
  142. token: 'delimiter.html',
  143. next: '@scriptEmbedded.text/javascript',
  144. nextEmbedded: 'text/javascript'
  145. }
  146. ],
  147. [/[ \t\r\n]+/],
  148. [/<\/script\s*>/, { token: '@rematch', next: '@pop' }]
  149. ],
  150. // After <script ... type = $S2
  151. scriptWithCustomType: [
  152. [
  153. /<\?((php)|=)?/,
  154. {
  155. token: '@rematch',
  156. switchTo: '@phpInSimpleState.scriptWithCustomType.$S2'
  157. }
  158. ],
  159. [
  160. />/,
  161. {
  162. token: 'delimiter.html',
  163. next: '@scriptEmbedded.$S2',
  164. nextEmbedded: '$S2'
  165. }
  166. ],
  167. [/"([^"]*)"/, 'attribute.value'],
  168. [/'([^']*)'/, 'attribute.value'],
  169. [/[\w\-]+/, 'attribute.name'],
  170. [/=/, 'delimiter'],
  171. [/[ \t\r\n]+/],
  172. [/<\/script\s*>/, { token: '@rematch', next: '@pop' }]
  173. ],
  174. scriptEmbedded: [
  175. [
  176. /<\?((php)|=)?/,
  177. {
  178. token: '@rematch',
  179. switchTo: '@phpInEmbeddedState.scriptEmbedded.$S2',
  180. nextEmbedded: '@pop'
  181. }
  182. ],
  183. [/<\/script/, { token: '@rematch', next: '@pop', nextEmbedded: '@pop' }]
  184. ],
  185. // -- END <script> tags handling
  186. // -- BEGIN <style> tags handling
  187. // After <style
  188. style: [
  189. [/<\?((php)|=)?/, { token: '@rematch', switchTo: '@phpInSimpleState.style' }],
  190. [/type/, 'attribute.name', '@styleAfterType'],
  191. [/"([^"]*)"/, 'attribute.value'],
  192. [/'([^']*)'/, 'attribute.value'],
  193. [/[\w\-]+/, 'attribute.name'],
  194. [/=/, 'delimiter'],
  195. [
  196. />/,
  197. {
  198. token: 'delimiter.html',
  199. next: '@styleEmbedded.text/css',
  200. nextEmbedded: 'text/css'
  201. }
  202. ],
  203. [/[ \t\r\n]+/],
  204. [
  205. /(<\/)(style\s*)(>)/,
  206. ['delimiter.html', 'tag.html', { token: 'delimiter.html', next: '@pop' }]
  207. ]
  208. ],
  209. // After <style ... type
  210. styleAfterType: [
  211. [
  212. /<\?((php)|=)?/,
  213. {
  214. token: '@rematch',
  215. switchTo: '@phpInSimpleState.styleAfterType'
  216. }
  217. ],
  218. [/=/, 'delimiter', '@styleAfterTypeEquals'],
  219. [
  220. />/,
  221. {
  222. token: 'delimiter.html',
  223. next: '@styleEmbedded.text/css',
  224. nextEmbedded: 'text/css'
  225. }
  226. ],
  227. [/[ \t\r\n]+/],
  228. [/<\/style\s*>/, { token: '@rematch', next: '@pop' }]
  229. ],
  230. // After <style ... type =
  231. styleAfterTypeEquals: [
  232. [
  233. /<\?((php)|=)?/,
  234. {
  235. token: '@rematch',
  236. switchTo: '@phpInSimpleState.styleAfterTypeEquals'
  237. }
  238. ],
  239. [
  240. /"([^"]*)"/,
  241. {
  242. token: 'attribute.value',
  243. switchTo: '@styleWithCustomType.$1'
  244. }
  245. ],
  246. [
  247. /'([^']*)'/,
  248. {
  249. token: 'attribute.value',
  250. switchTo: '@styleWithCustomType.$1'
  251. }
  252. ],
  253. [
  254. />/,
  255. {
  256. token: 'delimiter.html',
  257. next: '@styleEmbedded.text/css',
  258. nextEmbedded: 'text/css'
  259. }
  260. ],
  261. [/[ \t\r\n]+/],
  262. [/<\/style\s*>/, { token: '@rematch', next: '@pop' }]
  263. ],
  264. // After <style ... type = $S2
  265. styleWithCustomType: [
  266. [
  267. /<\?((php)|=)?/,
  268. {
  269. token: '@rematch',
  270. switchTo: '@phpInSimpleState.styleWithCustomType.$S2'
  271. }
  272. ],
  273. [
  274. />/,
  275. {
  276. token: 'delimiter.html',
  277. next: '@styleEmbedded.$S2',
  278. nextEmbedded: '$S2'
  279. }
  280. ],
  281. [/"([^"]*)"/, 'attribute.value'],
  282. [/'([^']*)'/, 'attribute.value'],
  283. [/[\w\-]+/, 'attribute.name'],
  284. [/=/, 'delimiter'],
  285. [/[ \t\r\n]+/],
  286. [/<\/style\s*>/, { token: '@rematch', next: '@pop' }]
  287. ],
  288. styleEmbedded: [
  289. [
  290. /<\?((php)|=)?/,
  291. {
  292. token: '@rematch',
  293. switchTo: '@phpInEmbeddedState.styleEmbedded.$S2',
  294. nextEmbedded: '@pop'
  295. }
  296. ],
  297. [/<\/style/, { token: '@rematch', next: '@pop', nextEmbedded: '@pop' }]
  298. ],
  299. // -- END <style> tags handling
  300. phpInSimpleState: [
  301. [/<\?((php)|=)?/, 'metatag.php'],
  302. [/\?>/, { token: 'metatag.php', switchTo: '@$S2.$S3' }],
  303. { include: 'phpRoot' }
  304. ],
  305. phpInEmbeddedState: [
  306. [/<\?((php)|=)?/, 'metatag.php'],
  307. [
  308. /\?>/,
  309. {
  310. token: 'metatag.php',
  311. switchTo: '@$S2.$S3',
  312. nextEmbedded: '$S3'
  313. }
  314. ],
  315. { include: 'phpRoot' }
  316. ],
  317. phpRoot: [
  318. [
  319. /[a-zA-Z_]\w*/,
  320. {
  321. cases: {
  322. '@phpKeywords': { token: 'keyword.php' },
  323. '@phpCompileTimeConstants': { token: 'constant.php' },
  324. '@default': 'identifier.php'
  325. }
  326. }
  327. ],
  328. [
  329. /[$a-zA-Z_]\w*/,
  330. {
  331. cases: {
  332. '@phpPreDefinedVariables': {
  333. token: 'variable.predefined.php'
  334. },
  335. '@default': 'variable.php'
  336. }
  337. }
  338. ],
  339. // brackets
  340. [/[{}]/, 'delimiter.bracket.php'],
  341. [/[\[\]]/, 'delimiter.array.php'],
  342. [/[()]/, 'delimiter.parenthesis.php'],
  343. // whitespace
  344. [/[ \t\r\n]+/],
  345. // comments
  346. [/(#|\/\/)$/, 'comment.php'],
  347. [/(#|\/\/)/, 'comment.php', '@phpLineComment'],
  348. // block comments
  349. [/\/\*/, 'comment.php', '@phpComment'],
  350. // strings
  351. [/"/, 'string.php', '@phpDoubleQuoteString'],
  352. [/'/, 'string.php', '@phpSingleQuoteString'],
  353. // delimiters
  354. [/[\+\-\*\%\&\|\^\~\!\=\<\>\/\?\;\:\.\,\@]/, 'delimiter.php'],
  355. // numbers
  356. [/\d*\d+[eE]([\-+]?\d+)?/, 'number.float.php'],
  357. [/\d*\.\d+([eE][\-+]?\d+)?/, 'number.float.php'],
  358. [/0[xX][0-9a-fA-F']*[0-9a-fA-F]/, 'number.hex.php'],
  359. [/0[0-7']*[0-7]/, 'number.octal.php'],
  360. [/0[bB][0-1']*[0-1]/, 'number.binary.php'],
  361. [/\d[\d']*/, 'number.php'],
  362. [/\d/, 'number.php']
  363. ],
  364. phpComment: [
  365. [/\*\//, 'comment.php', '@pop'],
  366. [/[^*]+/, 'comment.php'],
  367. [/./, 'comment.php']
  368. ],
  369. phpLineComment: [
  370. [/\?>/, { token: '@rematch', next: '@pop' }],
  371. [/.$/, 'comment.php', '@pop'],
  372. [/[^?]+$/, 'comment.php', '@pop'],
  373. [/[^?]+/, 'comment.php'],
  374. [/./, 'comment.php']
  375. ],
  376. phpDoubleQuoteString: [
  377. [/[^\\"]+/, 'string.php'],
  378. [/@escapes/, 'string.escape.php'],
  379. [/\\./, 'string.escape.invalid.php'],
  380. [/"/, 'string.php', '@pop']
  381. ],
  382. phpSingleQuoteString: [
  383. [/[^\\']+/, 'string.php'],
  384. [/@escapes/, 'string.escape.php'],
  385. [/\\./, 'string.escape.invalid.php'],
  386. [/'/, 'string.php', '@pop']
  387. ]
  388. },
  389. phpKeywords: [
  390. 'abstract',
  391. 'and',
  392. 'array',
  393. 'as',
  394. 'break',
  395. 'callable',
  396. 'case',
  397. 'catch',
  398. 'cfunction',
  399. 'class',
  400. 'clone',
  401. 'const',
  402. 'continue',
  403. 'declare',
  404. 'default',
  405. 'do',
  406. 'else',
  407. 'elseif',
  408. 'enddeclare',
  409. 'endfor',
  410. 'endforeach',
  411. 'endif',
  412. 'endswitch',
  413. 'endwhile',
  414. 'extends',
  415. 'false',
  416. 'final',
  417. 'for',
  418. 'foreach',
  419. 'function',
  420. 'global',
  421. 'goto',
  422. 'if',
  423. 'implements',
  424. 'interface',
  425. 'instanceof',
  426. 'insteadof',
  427. 'namespace',
  428. 'new',
  429. 'null',
  430. 'object',
  431. 'old_function',
  432. 'or',
  433. 'private',
  434. 'protected',
  435. 'public',
  436. 'resource',
  437. 'static',
  438. 'switch',
  439. 'throw',
  440. 'trait',
  441. 'try',
  442. 'true',
  443. 'use',
  444. 'var',
  445. 'while',
  446. 'xor',
  447. 'die',
  448. 'echo',
  449. 'empty',
  450. 'exit',
  451. 'eval',
  452. 'include',
  453. 'include_once',
  454. 'isset',
  455. 'list',
  456. 'require',
  457. 'require_once',
  458. 'return',
  459. 'print',
  460. 'unset',
  461. 'yield',
  462. '__construct'
  463. ],
  464. phpCompileTimeConstants: [
  465. '__CLASS__',
  466. '__DIR__',
  467. '__FILE__',
  468. '__LINE__',
  469. '__NAMESPACE__',
  470. '__METHOD__',
  471. '__FUNCTION__',
  472. '__TRAIT__'
  473. ],
  474. phpPreDefinedVariables: [
  475. '$GLOBALS',
  476. '$_SERVER',
  477. '$_GET',
  478. '$_POST',
  479. '$_FILES',
  480. '$_REQUEST',
  481. '$_SESSION',
  482. '$_ENV',
  483. '$_COOKIE',
  484. '$php_errormsg',
  485. '$HTTP_RAW_POST_DATA',
  486. '$http_response_header',
  487. '$argc',
  488. '$argv'
  489. ],
  490. escapes: /\\(?:[abfnrtv\\"']|x[0-9A-Fa-f]{1,4}|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})/
  491. };
  492. });
  493. // TESTED WITH
  494. // <style type="text/css" >
  495. // .boo { background: blue;
  496. // <?=''?>
  497. // }
  498. // .boo { background: blue; <?=''?> }
  499. // </style>
  500. // <!--
  501. // <?= '' ?>
  502. // -->
  503. // <?php
  504. // // The next line contains a syntax error:
  505. // __construct
  506. // if () {
  507. // return "The parser recovers from this type of syntax error";
  508. // }
  509. // ?>
  510. // <html>
  511. // <head>
  512. // <title <?=''?>>Example page</title>
  513. // <style <?=''?>>
  514. // .boo { background: blue; <?=''?> }
  515. // </style>
  516. // </head>
  517. // <body>
  518. // <script <?=''?> type<?=''?>=<?=''?>"text/javascript"<?=''?>>
  519. // // Some PHP embedded inside JS
  520. // // Generated <?=date('l, F jS, Y')?>
  521. // var server_token = <?=rand(5, 10000)?>
  522. // if (typeof server_token === 'number') {
  523. // alert('token: ' + server_token);
  524. // }
  525. // </script>
  526. // <div>
  527. // Hello
  528. // <? if (isset($user)) { ?>
  529. // <b><?=$user?></b>
  530. // <? } else { ?>
  531. // <i>guest</i>
  532. // <? } ?>
  533. // !
  534. // </div>
  535. // <?php
  536. // /* Example PHP file
  537. // multiline comment
  538. // */
  539. // # Another single line comment
  540. // $cards = array("ah", "ac", "ad", "as",
  541. // "2h", "2c", "2d", "2s",
  542. // "3h", "3c", "3d", "3s",
  543. // "4h", "4c", "4d", "4s",
  544. // "5h", "5c", "5d", "5s",
  545. // "6h", "6c", "6d", "6s",
  546. // "7h", "7c", "7d", "7s",
  547. // "8h", "8c", "8d", "8s",
  548. // "9h", "9c", "9d", "9s",
  549. // "th", "tc", "td", "ts",
  550. // "jh", "jc", "jd", "js",
  551. // "qh", "qc", "qd", "qs",
  552. // "kh", "kc", "kd", "ks");
  553. // srand(time());
  554. // for($i = 0; $i < 52; $i++) {
  555. // $count = count($cards);
  556. // $random = (rand()%$count);
  557. // if($cards[$random] == "") {
  558. // $i--;
  559. // } else {
  560. // $deck[] = $cards[$random];
  561. // $cards[$random] = "";
  562. // }
  563. // }
  564. // $_GET
  565. // __CLASS__
  566. // srand(time());
  567. // $starting_point = (rand()%51);
  568. // print("Starting point for cut cards is: $starting_point<p>");
  569. // // display shuffled cards (EXAMPLE ONLY)
  570. // for ($index = 0; $index < 52; $index++) {
  571. // if ($starting_point == 52) { $starting_point = 0; }
  572. // print("Uncut Point: <strong>$deck[$index]</strong> ");
  573. // print("Starting Point: <strong>$deck[$starting_point]</strong><br>");
  574. // $starting_point++;
  575. // }
  576. // ?>
  577. // </body>
  578. // </html>
  579. ;