twig.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  1. "use strict";
  2. /*!-----------------------------------------------------------------------------
  3. * Copyright (c) Microsoft Corporation. All rights reserved.
  4. * Version: 0.38.0(0e330ae453813de4e6cf272460fb79c7117073d0)
  5. * Released under the MIT license
  6. * https://github.com/microsoft/monaco-editor/blob/main/LICENSE.txt
  7. *-----------------------------------------------------------------------------*/
  8. define("vs/basic-languages/twig/twig", ["require"],(require)=>{
  9. var moduleExports = (() => {
  10. var __defProp = Object.defineProperty;
  11. var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
  12. var __getOwnPropNames = Object.getOwnPropertyNames;
  13. var __hasOwnProp = Object.prototype.hasOwnProperty;
  14. var __export = (target, all) => {
  15. for (var name in all)
  16. __defProp(target, name, { get: all[name], enumerable: true });
  17. };
  18. var __copyProps = (to, from, except, desc) => {
  19. if (from && typeof from === "object" || typeof from === "function") {
  20. for (let key of __getOwnPropNames(from))
  21. if (!__hasOwnProp.call(to, key) && key !== except)
  22. __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  23. }
  24. return to;
  25. };
  26. var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
  27. // src/basic-languages/twig/twig.ts
  28. var twig_exports = {};
  29. __export(twig_exports, {
  30. conf: () => conf,
  31. language: () => language
  32. });
  33. var conf = {
  34. wordPattern: /(-?\d*\.\d\w*)|([^\`\~\!\@\$\^\&\*\(\)\=\+\[\{\]\}\\\|\;\:\'\"\,\.\<\>\/\s]+)/g,
  35. comments: {
  36. blockComment: ["{#", "#}"]
  37. },
  38. brackets: [
  39. ["{#", "#}"],
  40. ["{%", "%}"],
  41. ["{{", "}}"],
  42. ["(", ")"],
  43. ["[", "]"],
  44. ["<!--", "-->"],
  45. ["<", ">"]
  46. ],
  47. autoClosingPairs: [
  48. { open: "{# ", close: " #}" },
  49. { open: "{% ", close: " %}" },
  50. { open: "{{ ", close: " }}" },
  51. { open: "[", close: "]" },
  52. { open: "(", close: ")" },
  53. { open: '"', close: '"' },
  54. { open: "'", close: "'" }
  55. ],
  56. surroundingPairs: [
  57. { open: '"', close: '"' },
  58. { open: "'", close: "'" },
  59. { open: "<", close: ">" }
  60. ]
  61. };
  62. var language = {
  63. defaultToken: "",
  64. tokenPostfix: "",
  65. ignoreCase: true,
  66. keywords: [
  67. "apply",
  68. "autoescape",
  69. "block",
  70. "deprecated",
  71. "do",
  72. "embed",
  73. "extends",
  74. "flush",
  75. "for",
  76. "from",
  77. "if",
  78. "import",
  79. "include",
  80. "macro",
  81. "sandbox",
  82. "set",
  83. "use",
  84. "verbatim",
  85. "with",
  86. "endapply",
  87. "endautoescape",
  88. "endblock",
  89. "endembed",
  90. "endfor",
  91. "endif",
  92. "endmacro",
  93. "endsandbox",
  94. "endset",
  95. "endwith",
  96. "true",
  97. "false"
  98. ],
  99. tokenizer: {
  100. root: [
  101. [/\s+/],
  102. [/{#/, "comment.twig", "@commentState"],
  103. [/{%[-~]?/, "delimiter.twig", "@blockState"],
  104. [/{{[-~]?/, "delimiter.twig", "@variableState"],
  105. [/<!DOCTYPE/, "metatag.html", "@doctype"],
  106. [/<!--/, "comment.html", "@comment"],
  107. [/(<)((?:[\w\-]+:)?[\w\-]+)(\s*)(\/>)/, ["delimiter.html", "tag.html", "", "delimiter.html"]],
  108. [/(<)(script)/, ["delimiter.html", { token: "tag.html", next: "@script" }]],
  109. [/(<)(style)/, ["delimiter.html", { token: "tag.html", next: "@style" }]],
  110. [/(<)((?:[\w\-]+:)?[\w\-]+)/, ["delimiter.html", { token: "tag.html", next: "@otherTag" }]],
  111. [/(<\/)((?:[\w\-]+:)?[\w\-]+)/, ["delimiter.html", { token: "tag.html", next: "@otherTag" }]],
  112. [/</, "delimiter.html"],
  113. [/[^<]+/]
  114. ],
  115. commentState: [
  116. [/#}/, "comment.twig", "@pop"],
  117. [/./, "comment.twig"]
  118. ],
  119. blockState: [
  120. [/[-~]?%}/, "delimiter.twig", "@pop"],
  121. [/\s+/],
  122. [
  123. /(verbatim)(\s*)([-~]?%})/,
  124. ["keyword.twig", "", { token: "delimiter.twig", next: "@rawDataState" }]
  125. ],
  126. { include: "expression" }
  127. ],
  128. rawDataState: [
  129. [
  130. /({%[-~]?)(\s*)(endverbatim)(\s*)([-~]?%})/,
  131. ["delimiter.twig", "", "keyword.twig", "", { token: "delimiter.twig", next: "@popall" }]
  132. ],
  133. [/./, "string.twig"]
  134. ],
  135. variableState: [[/[-~]?}}/, "delimiter.twig", "@pop"], { include: "expression" }],
  136. stringState: [
  137. [/"/, "string.twig", "@pop"],
  138. [/#{\s*/, "string.twig", "@interpolationState"],
  139. [/[^#"\\]*(?:(?:\\.|#(?!\{))[^#"\\]*)*/, "string.twig"]
  140. ],
  141. interpolationState: [
  142. [/}/, "string.twig", "@pop"],
  143. { include: "expression" }
  144. ],
  145. expression: [
  146. [/\s+/],
  147. [/\+|-|\/{1,2}|%|\*{1,2}/, "operators.twig"],
  148. [/(and|or|not|b-and|b-xor|b-or)(\s+)/, ["operators.twig", ""]],
  149. [/==|!=|<|>|>=|<=/, "operators.twig"],
  150. [/(starts with|ends with|matches)(\s+)/, ["operators.twig", ""]],
  151. [/(in)(\s+)/, ["operators.twig", ""]],
  152. [/(is)(\s+)/, ["operators.twig", ""]],
  153. [/\||~|:|\.{1,2}|\?{1,2}/, "operators.twig"],
  154. [
  155. /[^\W\d][\w]*/,
  156. {
  157. cases: {
  158. "@keywords": "keyword.twig",
  159. "@default": "variable.twig"
  160. }
  161. }
  162. ],
  163. [/\d+(\.\d+)?/, "number.twig"],
  164. [/\(|\)|\[|\]|{|}|,/, "delimiter.twig"],
  165. [/"([^#"\\]*(?:\\.[^#"\\]*)*)"|\'([^\'\\]*(?:\\.[^\'\\]*)*)\'/, "string.twig"],
  166. [/"/, "string.twig", "@stringState"],
  167. [/=>/, "operators.twig"],
  168. [/=/, "operators.twig"]
  169. ],
  170. doctype: [
  171. [/[^>]+/, "metatag.content.html"],
  172. [/>/, "metatag.html", "@pop"]
  173. ],
  174. comment: [
  175. [/-->/, "comment.html", "@pop"],
  176. [/[^-]+/, "comment.content.html"],
  177. [/./, "comment.content.html"]
  178. ],
  179. otherTag: [
  180. [/\/?>/, "delimiter.html", "@pop"],
  181. [/"([^"]*)"/, "attribute.value.html"],
  182. [/'([^']*)'/, "attribute.value.html"],
  183. [/[\w\-]+/, "attribute.name.html"],
  184. [/=/, "delimiter.html"],
  185. [/[ \t\r\n]+/]
  186. ],
  187. script: [
  188. [/type/, "attribute.name.html", "@scriptAfterType"],
  189. [/"([^"]*)"/, "attribute.value.html"],
  190. [/'([^']*)'/, "attribute.value.html"],
  191. [/[\w\-]+/, "attribute.name.html"],
  192. [/=/, "delimiter.html"],
  193. [
  194. />/,
  195. {
  196. token: "delimiter.html",
  197. next: "@scriptEmbedded",
  198. nextEmbedded: "text/javascript"
  199. }
  200. ],
  201. [/[ \t\r\n]+/],
  202. [
  203. /(<\/)(script\s*)(>)/,
  204. ["delimiter.html", "tag.html", { token: "delimiter.html", next: "@pop" }]
  205. ]
  206. ],
  207. scriptAfterType: [
  208. [/=/, "delimiter.html", "@scriptAfterTypeEquals"],
  209. [
  210. />/,
  211. {
  212. token: "delimiter.html",
  213. next: "@scriptEmbedded",
  214. nextEmbedded: "text/javascript"
  215. }
  216. ],
  217. [/[ \t\r\n]+/],
  218. [/<\/script\s*>/, { token: "@rematch", next: "@pop" }]
  219. ],
  220. scriptAfterTypeEquals: [
  221. [
  222. /"([^"]*)"/,
  223. {
  224. token: "attribute.value.html",
  225. switchTo: "@scriptWithCustomType.$1"
  226. }
  227. ],
  228. [
  229. /'([^']*)'/,
  230. {
  231. token: "attribute.value.html",
  232. switchTo: "@scriptWithCustomType.$1"
  233. }
  234. ],
  235. [
  236. />/,
  237. {
  238. token: "delimiter.html",
  239. next: "@scriptEmbedded",
  240. nextEmbedded: "text/javascript"
  241. }
  242. ],
  243. [/[ \t\r\n]+/],
  244. [/<\/script\s*>/, { token: "@rematch", next: "@pop" }]
  245. ],
  246. scriptWithCustomType: [
  247. [
  248. />/,
  249. {
  250. token: "delimiter.html",
  251. next: "@scriptEmbedded.$S2",
  252. nextEmbedded: "$S2"
  253. }
  254. ],
  255. [/"([^"]*)"/, "attribute.value.html"],
  256. [/'([^']*)'/, "attribute.value.html"],
  257. [/[\w\-]+/, "attribute.name.html"],
  258. [/=/, "delimiter.html"],
  259. [/[ \t\r\n]+/],
  260. [/<\/script\s*>/, { token: "@rematch", next: "@pop" }]
  261. ],
  262. scriptEmbedded: [
  263. [/<\/script/, { token: "@rematch", next: "@pop", nextEmbedded: "@pop" }],
  264. [/[^<]+/, ""]
  265. ],
  266. style: [
  267. [/type/, "attribute.name.html", "@styleAfterType"],
  268. [/"([^"]*)"/, "attribute.value.html"],
  269. [/'([^']*)'/, "attribute.value.html"],
  270. [/[\w\-]+/, "attribute.name.html"],
  271. [/=/, "delimiter.html"],
  272. [
  273. />/,
  274. {
  275. token: "delimiter.html",
  276. next: "@styleEmbedded",
  277. nextEmbedded: "text/css"
  278. }
  279. ],
  280. [/[ \t\r\n]+/],
  281. [
  282. /(<\/)(style\s*)(>)/,
  283. ["delimiter.html", "tag.html", { token: "delimiter.html", next: "@pop" }]
  284. ]
  285. ],
  286. styleAfterType: [
  287. [/=/, "delimiter.html", "@styleAfterTypeEquals"],
  288. [
  289. />/,
  290. {
  291. token: "delimiter.html",
  292. next: "@styleEmbedded",
  293. nextEmbedded: "text/css"
  294. }
  295. ],
  296. [/[ \t\r\n]+/],
  297. [/<\/style\s*>/, { token: "@rematch", next: "@pop" }]
  298. ],
  299. styleAfterTypeEquals: [
  300. [
  301. /"([^"]*)"/,
  302. {
  303. token: "attribute.value.html",
  304. switchTo: "@styleWithCustomType.$1"
  305. }
  306. ],
  307. [
  308. /'([^']*)'/,
  309. {
  310. token: "attribute.value.html",
  311. switchTo: "@styleWithCustomType.$1"
  312. }
  313. ],
  314. [
  315. />/,
  316. {
  317. token: "delimiter.html",
  318. next: "@styleEmbedded",
  319. nextEmbedded: "text/css"
  320. }
  321. ],
  322. [/[ \t\r\n]+/],
  323. [/<\/style\s*>/, { token: "@rematch", next: "@pop" }]
  324. ],
  325. styleWithCustomType: [
  326. [
  327. />/,
  328. {
  329. token: "delimiter.html",
  330. next: "@styleEmbedded.$S2",
  331. nextEmbedded: "$S2"
  332. }
  333. ],
  334. [/"([^"]*)"/, "attribute.value.html"],
  335. [/'([^']*)'/, "attribute.value.html"],
  336. [/[\w\-]+/, "attribute.name.html"],
  337. [/=/, "delimiter.html"],
  338. [/[ \t\r\n]+/],
  339. [/<\/style\s*>/, { token: "@rematch", next: "@pop" }]
  340. ],
  341. styleEmbedded: [
  342. [/<\/style/, { token: "@rematch", next: "@pop", nextEmbedded: "@pop" }],
  343. [/[^<]+/, ""]
  344. ]
  345. }
  346. };
  347. return __toCommonJS(twig_exports);
  348. })();
  349. return moduleExports;
  350. });