pug.js 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396
  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/pug/pug.ts
  8. var conf = {
  9. comments: {
  10. lineComment: "//"
  11. },
  12. brackets: [
  13. ["{", "}"],
  14. ["[", "]"],
  15. ["(", ")"]
  16. ],
  17. autoClosingPairs: [
  18. { open: '"', close: '"', notIn: ["string", "comment"] },
  19. { open: "'", close: "'", notIn: ["string", "comment"] },
  20. { open: "{", close: "}", notIn: ["string", "comment"] },
  21. { open: "[", close: "]", notIn: ["string", "comment"] },
  22. { open: "(", close: ")", notIn: ["string", "comment"] }
  23. ],
  24. folding: {
  25. offSide: true
  26. }
  27. };
  28. var language = {
  29. defaultToken: "",
  30. tokenPostfix: ".pug",
  31. ignoreCase: true,
  32. brackets: [
  33. { token: "delimiter.curly", open: "{", close: "}" },
  34. { token: "delimiter.array", open: "[", close: "]" },
  35. { token: "delimiter.parenthesis", open: "(", close: ")" }
  36. ],
  37. keywords: [
  38. "append",
  39. "block",
  40. "case",
  41. "default",
  42. "doctype",
  43. "each",
  44. "else",
  45. "extends",
  46. "for",
  47. "if",
  48. "in",
  49. "include",
  50. "mixin",
  51. "typeof",
  52. "unless",
  53. "var",
  54. "when"
  55. ],
  56. tags: [
  57. "a",
  58. "abbr",
  59. "acronym",
  60. "address",
  61. "area",
  62. "article",
  63. "aside",
  64. "audio",
  65. "b",
  66. "base",
  67. "basefont",
  68. "bdi",
  69. "bdo",
  70. "blockquote",
  71. "body",
  72. "br",
  73. "button",
  74. "canvas",
  75. "caption",
  76. "center",
  77. "cite",
  78. "code",
  79. "col",
  80. "colgroup",
  81. "command",
  82. "datalist",
  83. "dd",
  84. "del",
  85. "details",
  86. "dfn",
  87. "div",
  88. "dl",
  89. "dt",
  90. "em",
  91. "embed",
  92. "fieldset",
  93. "figcaption",
  94. "figure",
  95. "font",
  96. "footer",
  97. "form",
  98. "frame",
  99. "frameset",
  100. "h1",
  101. "h2",
  102. "h3",
  103. "h4",
  104. "h5",
  105. "h6",
  106. "head",
  107. "header",
  108. "hgroup",
  109. "hr",
  110. "html",
  111. "i",
  112. "iframe",
  113. "img",
  114. "input",
  115. "ins",
  116. "keygen",
  117. "kbd",
  118. "label",
  119. "li",
  120. "link",
  121. "map",
  122. "mark",
  123. "menu",
  124. "meta",
  125. "meter",
  126. "nav",
  127. "noframes",
  128. "noscript",
  129. "object",
  130. "ol",
  131. "optgroup",
  132. "option",
  133. "output",
  134. "p",
  135. "param",
  136. "pre",
  137. "progress",
  138. "q",
  139. "rp",
  140. "rt",
  141. "ruby",
  142. "s",
  143. "samp",
  144. "script",
  145. "section",
  146. "select",
  147. "small",
  148. "source",
  149. "span",
  150. "strike",
  151. "strong",
  152. "style",
  153. "sub",
  154. "summary",
  155. "sup",
  156. "table",
  157. "tbody",
  158. "td",
  159. "textarea",
  160. "tfoot",
  161. "th",
  162. "thead",
  163. "time",
  164. "title",
  165. "tr",
  166. "tracks",
  167. "tt",
  168. "u",
  169. "ul",
  170. "video",
  171. "wbr"
  172. ],
  173. symbols: /[\+\-\*\%\&\|\!\=\/\.\,\:]+/,
  174. escapes: /\\(?:[abfnrtv\\"']|x[0-9A-Fa-f]{1,4}|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})/,
  175. tokenizer: {
  176. root: [
  177. [
  178. /^(\s*)([a-zA-Z_-][\w-]*)/,
  179. {
  180. cases: {
  181. "$2@tags": {
  182. cases: {
  183. "@eos": ["", "tag"],
  184. "@default": ["", { token: "tag", next: "@tag.$1" }]
  185. }
  186. },
  187. "$2@keywords": ["", { token: "keyword.$2" }],
  188. "@default": ["", ""]
  189. }
  190. }
  191. ],
  192. [
  193. /^(\s*)(#[a-zA-Z_-][\w-]*)/,
  194. {
  195. cases: {
  196. "@eos": ["", "tag.id"],
  197. "@default": ["", { token: "tag.id", next: "@tag.$1" }]
  198. }
  199. }
  200. ],
  201. [
  202. /^(\s*)(\.[a-zA-Z_-][\w-]*)/,
  203. {
  204. cases: {
  205. "@eos": ["", "tag.class"],
  206. "@default": ["", { token: "tag.class", next: "@tag.$1" }]
  207. }
  208. }
  209. ],
  210. [/^(\s*)(\|.*)$/, ""],
  211. { include: "@whitespace" },
  212. [
  213. /[a-zA-Z_$][\w$]*/,
  214. {
  215. cases: {
  216. "@keywords": { token: "keyword.$0" },
  217. "@default": ""
  218. }
  219. }
  220. ],
  221. [/[{}()\[\]]/, "@brackets"],
  222. [/@symbols/, "delimiter"],
  223. [/\d+\.\d+([eE][\-+]?\d+)?/, "number.float"],
  224. [/\d+/, "number"],
  225. [/"/, "string", '@string."'],
  226. [/'/, "string", "@string.'"]
  227. ],
  228. tag: [
  229. [/(\.)(\s*$)/, [{ token: "delimiter", next: "@blockText.$S2." }, ""]],
  230. [/\s+/, { token: "", next: "@simpleText" }],
  231. [
  232. /#[a-zA-Z_-][\w-]*/,
  233. {
  234. cases: {
  235. "@eos": { token: "tag.id", next: "@pop" },
  236. "@default": "tag.id"
  237. }
  238. }
  239. ],
  240. [
  241. /\.[a-zA-Z_-][\w-]*/,
  242. {
  243. cases: {
  244. "@eos": { token: "tag.class", next: "@pop" },
  245. "@default": "tag.class"
  246. }
  247. }
  248. ],
  249. [/\(/, { token: "delimiter.parenthesis", next: "@attributeList" }]
  250. ],
  251. simpleText: [
  252. [/[^#]+$/, { token: "", next: "@popall" }],
  253. [/[^#]+/, { token: "" }],
  254. [
  255. /(#{)([^}]*)(})/,
  256. {
  257. cases: {
  258. "@eos": [
  259. "interpolation.delimiter",
  260. "interpolation",
  261. {
  262. token: "interpolation.delimiter",
  263. next: "@popall"
  264. }
  265. ],
  266. "@default": ["interpolation.delimiter", "interpolation", "interpolation.delimiter"]
  267. }
  268. }
  269. ],
  270. [/#$/, { token: "", next: "@popall" }],
  271. [/#/, ""]
  272. ],
  273. attributeList: [
  274. [/\s+/, ""],
  275. [
  276. /(\w+)(\s*=\s*)("|')/,
  277. ["attribute.name", "delimiter", { token: "attribute.value", next: "@value.$3" }]
  278. ],
  279. [/\w+/, "attribute.name"],
  280. [
  281. /,/,
  282. {
  283. cases: {
  284. "@eos": {
  285. token: "attribute.delimiter",
  286. next: "@popall"
  287. },
  288. "@default": "attribute.delimiter"
  289. }
  290. }
  291. ],
  292. [/\)$/, { token: "delimiter.parenthesis", next: "@popall" }],
  293. [/\)/, { token: "delimiter.parenthesis", next: "@pop" }]
  294. ],
  295. whitespace: [
  296. [/^(\s*)(\/\/.*)$/, { token: "comment", next: "@blockText.$1.comment" }],
  297. [/[ \t\r\n]+/, ""],
  298. [/<!--/, { token: "comment", next: "@comment" }]
  299. ],
  300. blockText: [
  301. [
  302. /^\s+.*$/,
  303. {
  304. cases: {
  305. "($S2\\s+.*$)": { token: "$S3" },
  306. "@default": { token: "@rematch", next: "@popall" }
  307. }
  308. }
  309. ],
  310. [/./, { token: "@rematch", next: "@popall" }]
  311. ],
  312. comment: [
  313. [/[^<\-]+/, "comment.content"],
  314. [/-->/, { token: "comment", next: "@pop" }],
  315. [/<!--/, "comment.content.invalid"],
  316. [/[<\-]/, "comment.content"]
  317. ],
  318. string: [
  319. [
  320. /[^\\"'#]+/,
  321. {
  322. cases: {
  323. "@eos": { token: "string", next: "@popall" },
  324. "@default": "string"
  325. }
  326. }
  327. ],
  328. [
  329. /@escapes/,
  330. {
  331. cases: {
  332. "@eos": { token: "string.escape", next: "@popall" },
  333. "@default": "string.escape"
  334. }
  335. }
  336. ],
  337. [
  338. /\\./,
  339. {
  340. cases: {
  341. "@eos": {
  342. token: "string.escape.invalid",
  343. next: "@popall"
  344. },
  345. "@default": "string.escape.invalid"
  346. }
  347. }
  348. ],
  349. [/(#{)([^}]*)(})/, ["interpolation.delimiter", "interpolation", "interpolation.delimiter"]],
  350. [/#/, "string"],
  351. [
  352. /["']/,
  353. {
  354. cases: {
  355. "$#==$S2": { token: "string", next: "@pop" },
  356. "@default": { token: "string" }
  357. }
  358. }
  359. ]
  360. ],
  361. value: [
  362. [
  363. /[^\\"']+/,
  364. {
  365. cases: {
  366. "@eos": { token: "attribute.value", next: "@popall" },
  367. "@default": "attribute.value"
  368. }
  369. }
  370. ],
  371. [
  372. /\\./,
  373. {
  374. cases: {
  375. "@eos": { token: "attribute.value", next: "@popall" },
  376. "@default": "attribute.value"
  377. }
  378. }
  379. ],
  380. [
  381. /["']/,
  382. {
  383. cases: {
  384. "$#==$S2": { token: "attribute.value", next: "@pop" },
  385. "@default": { token: "attribute.value" }
  386. }
  387. }
  388. ]
  389. ]
  390. }
  391. };
  392. export {
  393. conf,
  394. language
  395. };