pug.js 13 KB

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