twig.js 9.7 KB

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