php.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474
  1. /*!-----------------------------------------------------------------------------
  2. * Copyright (c) Microsoft Corporation. All rights reserved.
  3. * Version: 0.31.1(337587859b1c171314b40503171188b6cea6a32a)
  4. * Released under the MIT license
  5. * https://github.com/microsoft/monaco-editor/blob/main/LICENSE.txt
  6. *-----------------------------------------------------------------------------*/
  7. // src/basic-languages/php/php.ts
  8. var conf = {
  9. wordPattern: /(-?\d*\.\d\w*)|([^\`\~\!\@\#\%\^\&\*\(\)\-\=\+\[\{\]\}\\\|\;\:\'\"\,\.\<\>\/\?\s]+)/g,
  10. comments: {
  11. lineComment: "//",
  12. blockComment: ["/*", "*/"]
  13. },
  14. brackets: [
  15. ["{", "}"],
  16. ["[", "]"],
  17. ["(", ")"]
  18. ],
  19. autoClosingPairs: [
  20. { open: "{", close: "}", notIn: ["string"] },
  21. { open: "[", close: "]", notIn: ["string"] },
  22. { open: "(", close: ")", notIn: ["string"] },
  23. { open: '"', close: '"', notIn: ["string"] },
  24. { open: "'", close: "'", notIn: ["string", "comment"] }
  25. ],
  26. folding: {
  27. markers: {
  28. start: new RegExp("^\\s*(#|//)region\\b"),
  29. end: new RegExp("^\\s*(#|//)endregion\\b")
  30. }
  31. }
  32. };
  33. var language = {
  34. defaultToken: "",
  35. tokenPostfix: "",
  36. tokenizer: {
  37. root: [
  38. [/<\?((php)|=)?/, { token: "@rematch", switchTo: "@phpInSimpleState.root" }],
  39. [/<!DOCTYPE/, "metatag.html", "@doctype"],
  40. [/<!--/, "comment.html", "@comment"],
  41. [/(<)(\w+)(\/>)/, ["delimiter.html", "tag.html", "delimiter.html"]],
  42. [/(<)(script)/, ["delimiter.html", { token: "tag.html", next: "@script" }]],
  43. [/(<)(style)/, ["delimiter.html", { token: "tag.html", next: "@style" }]],
  44. [/(<)([:\w]+)/, ["delimiter.html", { token: "tag.html", next: "@otherTag" }]],
  45. [/(<\/)(\w+)/, ["delimiter.html", { token: "tag.html", next: "@otherTag" }]],
  46. [/</, "delimiter.html"],
  47. [/[^<]+/]
  48. ],
  49. doctype: [
  50. [/<\?((php)|=)?/, { token: "@rematch", switchTo: "@phpInSimpleState.comment" }],
  51. [/[^>]+/, "metatag.content.html"],
  52. [/>/, "metatag.html", "@pop"]
  53. ],
  54. comment: [
  55. [/<\?((php)|=)?/, { token: "@rematch", switchTo: "@phpInSimpleState.comment" }],
  56. [/-->/, "comment.html", "@pop"],
  57. [/[^-]+/, "comment.content.html"],
  58. [/./, "comment.content.html"]
  59. ],
  60. otherTag: [
  61. [/<\?((php)|=)?/, { token: "@rematch", switchTo: "@phpInSimpleState.otherTag" }],
  62. [/\/?>/, "delimiter.html", "@pop"],
  63. [/"([^"]*)"/, "attribute.value"],
  64. [/'([^']*)'/, "attribute.value"],
  65. [/[\w\-]+/, "attribute.name"],
  66. [/=/, "delimiter"],
  67. [/[ \t\r\n]+/]
  68. ],
  69. script: [
  70. [/<\?((php)|=)?/, { token: "@rematch", switchTo: "@phpInSimpleState.script" }],
  71. [/type/, "attribute.name", "@scriptAfterType"],
  72. [/"([^"]*)"/, "attribute.value"],
  73. [/'([^']*)'/, "attribute.value"],
  74. [/[\w\-]+/, "attribute.name"],
  75. [/=/, "delimiter"],
  76. [
  77. />/,
  78. {
  79. token: "delimiter.html",
  80. next: "@scriptEmbedded.text/javascript",
  81. nextEmbedded: "text/javascript"
  82. }
  83. ],
  84. [/[ \t\r\n]+/],
  85. [
  86. /(<\/)(script\s*)(>)/,
  87. ["delimiter.html", "tag.html", { token: "delimiter.html", next: "@pop" }]
  88. ]
  89. ],
  90. scriptAfterType: [
  91. [
  92. /<\?((php)|=)?/,
  93. {
  94. token: "@rematch",
  95. switchTo: "@phpInSimpleState.scriptAfterType"
  96. }
  97. ],
  98. [/=/, "delimiter", "@scriptAfterTypeEquals"],
  99. [
  100. />/,
  101. {
  102. token: "delimiter.html",
  103. next: "@scriptEmbedded.text/javascript",
  104. nextEmbedded: "text/javascript"
  105. }
  106. ],
  107. [/[ \t\r\n]+/],
  108. [/<\/script\s*>/, { token: "@rematch", next: "@pop" }]
  109. ],
  110. scriptAfterTypeEquals: [
  111. [
  112. /<\?((php)|=)?/,
  113. {
  114. token: "@rematch",
  115. switchTo: "@phpInSimpleState.scriptAfterTypeEquals"
  116. }
  117. ],
  118. [
  119. /"([^"]*)"/,
  120. {
  121. token: "attribute.value",
  122. switchTo: "@scriptWithCustomType.$1"
  123. }
  124. ],
  125. [
  126. /'([^']*)'/,
  127. {
  128. token: "attribute.value",
  129. switchTo: "@scriptWithCustomType.$1"
  130. }
  131. ],
  132. [
  133. />/,
  134. {
  135. token: "delimiter.html",
  136. next: "@scriptEmbedded.text/javascript",
  137. nextEmbedded: "text/javascript"
  138. }
  139. ],
  140. [/[ \t\r\n]+/],
  141. [/<\/script\s*>/, { token: "@rematch", next: "@pop" }]
  142. ],
  143. scriptWithCustomType: [
  144. [
  145. /<\?((php)|=)?/,
  146. {
  147. token: "@rematch",
  148. switchTo: "@phpInSimpleState.scriptWithCustomType.$S2"
  149. }
  150. ],
  151. [
  152. />/,
  153. {
  154. token: "delimiter.html",
  155. next: "@scriptEmbedded.$S2",
  156. nextEmbedded: "$S2"
  157. }
  158. ],
  159. [/"([^"]*)"/, "attribute.value"],
  160. [/'([^']*)'/, "attribute.value"],
  161. [/[\w\-]+/, "attribute.name"],
  162. [/=/, "delimiter"],
  163. [/[ \t\r\n]+/],
  164. [/<\/script\s*>/, { token: "@rematch", next: "@pop" }]
  165. ],
  166. scriptEmbedded: [
  167. [
  168. /<\?((php)|=)?/,
  169. {
  170. token: "@rematch",
  171. switchTo: "@phpInEmbeddedState.scriptEmbedded.$S2",
  172. nextEmbedded: "@pop"
  173. }
  174. ],
  175. [/<\/script/, { token: "@rematch", next: "@pop", nextEmbedded: "@pop" }]
  176. ],
  177. style: [
  178. [/<\?((php)|=)?/, { token: "@rematch", switchTo: "@phpInSimpleState.style" }],
  179. [/type/, "attribute.name", "@styleAfterType"],
  180. [/"([^"]*)"/, "attribute.value"],
  181. [/'([^']*)'/, "attribute.value"],
  182. [/[\w\-]+/, "attribute.name"],
  183. [/=/, "delimiter"],
  184. [
  185. />/,
  186. {
  187. token: "delimiter.html",
  188. next: "@styleEmbedded.text/css",
  189. nextEmbedded: "text/css"
  190. }
  191. ],
  192. [/[ \t\r\n]+/],
  193. [
  194. /(<\/)(style\s*)(>)/,
  195. ["delimiter.html", "tag.html", { token: "delimiter.html", next: "@pop" }]
  196. ]
  197. ],
  198. styleAfterType: [
  199. [
  200. /<\?((php)|=)?/,
  201. {
  202. token: "@rematch",
  203. switchTo: "@phpInSimpleState.styleAfterType"
  204. }
  205. ],
  206. [/=/, "delimiter", "@styleAfterTypeEquals"],
  207. [
  208. />/,
  209. {
  210. token: "delimiter.html",
  211. next: "@styleEmbedded.text/css",
  212. nextEmbedded: "text/css"
  213. }
  214. ],
  215. [/[ \t\r\n]+/],
  216. [/<\/style\s*>/, { token: "@rematch", next: "@pop" }]
  217. ],
  218. styleAfterTypeEquals: [
  219. [
  220. /<\?((php)|=)?/,
  221. {
  222. token: "@rematch",
  223. switchTo: "@phpInSimpleState.styleAfterTypeEquals"
  224. }
  225. ],
  226. [
  227. /"([^"]*)"/,
  228. {
  229. token: "attribute.value",
  230. switchTo: "@styleWithCustomType.$1"
  231. }
  232. ],
  233. [
  234. /'([^']*)'/,
  235. {
  236. token: "attribute.value",
  237. switchTo: "@styleWithCustomType.$1"
  238. }
  239. ],
  240. [
  241. />/,
  242. {
  243. token: "delimiter.html",
  244. next: "@styleEmbedded.text/css",
  245. nextEmbedded: "text/css"
  246. }
  247. ],
  248. [/[ \t\r\n]+/],
  249. [/<\/style\s*>/, { token: "@rematch", next: "@pop" }]
  250. ],
  251. styleWithCustomType: [
  252. [
  253. /<\?((php)|=)?/,
  254. {
  255. token: "@rematch",
  256. switchTo: "@phpInSimpleState.styleWithCustomType.$S2"
  257. }
  258. ],
  259. [
  260. />/,
  261. {
  262. token: "delimiter.html",
  263. next: "@styleEmbedded.$S2",
  264. nextEmbedded: "$S2"
  265. }
  266. ],
  267. [/"([^"]*)"/, "attribute.value"],
  268. [/'([^']*)'/, "attribute.value"],
  269. [/[\w\-]+/, "attribute.name"],
  270. [/=/, "delimiter"],
  271. [/[ \t\r\n]+/],
  272. [/<\/style\s*>/, { token: "@rematch", next: "@pop" }]
  273. ],
  274. styleEmbedded: [
  275. [
  276. /<\?((php)|=)?/,
  277. {
  278. token: "@rematch",
  279. switchTo: "@phpInEmbeddedState.styleEmbedded.$S2",
  280. nextEmbedded: "@pop"
  281. }
  282. ],
  283. [/<\/style/, { token: "@rematch", next: "@pop", nextEmbedded: "@pop" }]
  284. ],
  285. phpInSimpleState: [
  286. [/<\?((php)|=)?/, "metatag.php"],
  287. [/\?>/, { token: "metatag.php", switchTo: "@$S2.$S3" }],
  288. { include: "phpRoot" }
  289. ],
  290. phpInEmbeddedState: [
  291. [/<\?((php)|=)?/, "metatag.php"],
  292. [
  293. /\?>/,
  294. {
  295. token: "metatag.php",
  296. switchTo: "@$S2.$S3",
  297. nextEmbedded: "$S3"
  298. }
  299. ],
  300. { include: "phpRoot" }
  301. ],
  302. phpRoot: [
  303. [
  304. /[a-zA-Z_]\w*/,
  305. {
  306. cases: {
  307. "@phpKeywords": { token: "keyword.php" },
  308. "@phpCompileTimeConstants": { token: "constant.php" },
  309. "@default": "identifier.php"
  310. }
  311. }
  312. ],
  313. [
  314. /[$a-zA-Z_]\w*/,
  315. {
  316. cases: {
  317. "@phpPreDefinedVariables": {
  318. token: "variable.predefined.php"
  319. },
  320. "@default": "variable.php"
  321. }
  322. }
  323. ],
  324. [/[{}]/, "delimiter.bracket.php"],
  325. [/[\[\]]/, "delimiter.array.php"],
  326. [/[()]/, "delimiter.parenthesis.php"],
  327. [/[ \t\r\n]+/],
  328. [/(#|\/\/)$/, "comment.php"],
  329. [/(#|\/\/)/, "comment.php", "@phpLineComment"],
  330. [/\/\*/, "comment.php", "@phpComment"],
  331. [/"/, "string.php", "@phpDoubleQuoteString"],
  332. [/'/, "string.php", "@phpSingleQuoteString"],
  333. [/[\+\-\*\%\&\|\^\~\!\=\<\>\/\?\;\:\.\,\@]/, "delimiter.php"],
  334. [/\d*\d+[eE]([\-+]?\d+)?/, "number.float.php"],
  335. [/\d*\.\d+([eE][\-+]?\d+)?/, "number.float.php"],
  336. [/0[xX][0-9a-fA-F']*[0-9a-fA-F]/, "number.hex.php"],
  337. [/0[0-7']*[0-7]/, "number.octal.php"],
  338. [/0[bB][0-1']*[0-1]/, "number.binary.php"],
  339. [/\d[\d']*/, "number.php"],
  340. [/\d/, "number.php"]
  341. ],
  342. phpComment: [
  343. [/\*\//, "comment.php", "@pop"],
  344. [/[^*]+/, "comment.php"],
  345. [/./, "comment.php"]
  346. ],
  347. phpLineComment: [
  348. [/\?>/, { token: "@rematch", next: "@pop" }],
  349. [/.$/, "comment.php", "@pop"],
  350. [/[^?]+$/, "comment.php", "@pop"],
  351. [/[^?]+/, "comment.php"],
  352. [/./, "comment.php"]
  353. ],
  354. phpDoubleQuoteString: [
  355. [/[^\\"]+/, "string.php"],
  356. [/@escapes/, "string.escape.php"],
  357. [/\\./, "string.escape.invalid.php"],
  358. [/"/, "string.php", "@pop"]
  359. ],
  360. phpSingleQuoteString: [
  361. [/[^\\']+/, "string.php"],
  362. [/@escapes/, "string.escape.php"],
  363. [/\\./, "string.escape.invalid.php"],
  364. [/'/, "string.php", "@pop"]
  365. ]
  366. },
  367. phpKeywords: [
  368. "abstract",
  369. "and",
  370. "array",
  371. "as",
  372. "break",
  373. "callable",
  374. "case",
  375. "catch",
  376. "cfunction",
  377. "class",
  378. "clone",
  379. "const",
  380. "continue",
  381. "declare",
  382. "default",
  383. "do",
  384. "else",
  385. "elseif",
  386. "enddeclare",
  387. "endfor",
  388. "endforeach",
  389. "endif",
  390. "endswitch",
  391. "endwhile",
  392. "extends",
  393. "false",
  394. "final",
  395. "for",
  396. "foreach",
  397. "function",
  398. "global",
  399. "goto",
  400. "if",
  401. "implements",
  402. "interface",
  403. "instanceof",
  404. "insteadof",
  405. "namespace",
  406. "new",
  407. "null",
  408. "object",
  409. "old_function",
  410. "or",
  411. "private",
  412. "protected",
  413. "public",
  414. "resource",
  415. "static",
  416. "switch",
  417. "throw",
  418. "trait",
  419. "try",
  420. "true",
  421. "use",
  422. "var",
  423. "while",
  424. "xor",
  425. "die",
  426. "echo",
  427. "empty",
  428. "exit",
  429. "eval",
  430. "include",
  431. "include_once",
  432. "isset",
  433. "list",
  434. "require",
  435. "require_once",
  436. "return",
  437. "print",
  438. "unset",
  439. "yield",
  440. "__construct"
  441. ],
  442. phpCompileTimeConstants: [
  443. "__CLASS__",
  444. "__DIR__",
  445. "__FILE__",
  446. "__LINE__",
  447. "__NAMESPACE__",
  448. "__METHOD__",
  449. "__FUNCTION__",
  450. "__TRAIT__"
  451. ],
  452. phpPreDefinedVariables: [
  453. "$GLOBALS",
  454. "$_SERVER",
  455. "$_GET",
  456. "$_POST",
  457. "$_FILES",
  458. "$_REQUEST",
  459. "$_SESSION",
  460. "$_ENV",
  461. "$_COOKIE",
  462. "$php_errormsg",
  463. "$HTTP_RAW_POST_DATA",
  464. "$http_response_header",
  465. "$argc",
  466. "$argv"
  467. ],
  468. escapes: /\\(?:[abfnrtv\\"']|x[0-9A-Fa-f]{1,4}|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})/
  469. };
  470. export {
  471. conf,
  472. language
  473. };