php.js 17 KB

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