liquid.js 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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/liquid/liquid',["require", "exports", "../fillers/monaco-editor-core"], function (require, exports, monaco_editor_core_1) {
  6. "use strict";
  7. Object.defineProperty(exports, "__esModule", { value: true });
  8. exports.language = exports.conf = void 0;
  9. var EMPTY_ELEMENTS = [
  10. 'area',
  11. 'base',
  12. 'br',
  13. 'col',
  14. 'embed',
  15. 'hr',
  16. 'img',
  17. 'input',
  18. 'keygen',
  19. 'link',
  20. 'menuitem',
  21. 'meta',
  22. 'param',
  23. 'source',
  24. 'track',
  25. 'wbr'
  26. ];
  27. exports.conf = {
  28. wordPattern: /(-?\d*\.\d\w*)|([^\`\~\!\@\$\^\&\*\(\)\=\+\[\{\]\}\\\|\;\:\'\"\,\.\<\>\/\s]+)/g,
  29. brackets: [
  30. ['<!--', '-->'],
  31. ['<', '>'],
  32. ['{{', '}}'],
  33. ['{%', '%}'],
  34. ['{', '}'],
  35. ['(', ')']
  36. ],
  37. autoClosingPairs: [
  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. onEnterRules: [
  51. {
  52. beforeText: new RegExp("<(?!(?:" + EMPTY_ELEMENTS.join('|') + "))(\\w[\\w\\d]*)([^/>]*(?!/)>)[^<]*$", 'i'),
  53. afterText: /^<\/(\w[\w\d]*)\s*>$/i,
  54. action: {
  55. indentAction: monaco_editor_core_1.languages.IndentAction.IndentOutdent
  56. }
  57. },
  58. {
  59. beforeText: new RegExp("<(?!(?:" + EMPTY_ELEMENTS.join('|') + "))(\\w[\\w\\d]*)([^/>]*(?!/)>)[^<]*$", 'i'),
  60. action: { indentAction: monaco_editor_core_1.languages.IndentAction.Indent }
  61. }
  62. ]
  63. };
  64. exports.language = {
  65. defaultToken: '',
  66. tokenPostfix: '',
  67. builtinTags: [
  68. 'if',
  69. 'else',
  70. 'elseif',
  71. 'endif',
  72. 'render',
  73. 'assign',
  74. 'capture',
  75. 'endcapture',
  76. 'case',
  77. 'endcase',
  78. 'comment',
  79. 'endcomment',
  80. 'cycle',
  81. 'decrement',
  82. 'for',
  83. 'endfor',
  84. 'include',
  85. 'increment',
  86. 'layout',
  87. 'raw',
  88. 'endraw',
  89. 'render',
  90. 'tablerow',
  91. 'endtablerow',
  92. 'unless',
  93. 'endunless'
  94. ],
  95. builtinFilters: [
  96. 'abs',
  97. 'append',
  98. 'at_least',
  99. 'at_most',
  100. 'capitalize',
  101. 'ceil',
  102. 'compact',
  103. 'date',
  104. 'default',
  105. 'divided_by',
  106. 'downcase',
  107. 'escape',
  108. 'escape_once',
  109. 'first',
  110. 'floor',
  111. 'join',
  112. 'json',
  113. 'last',
  114. 'lstrip',
  115. 'map',
  116. 'minus',
  117. 'modulo',
  118. 'newline_to_br',
  119. 'plus',
  120. 'prepend',
  121. 'remove',
  122. 'remove_first',
  123. 'replace',
  124. 'replace_first',
  125. 'reverse',
  126. 'round',
  127. 'rstrip',
  128. 'size',
  129. 'slice',
  130. 'sort',
  131. 'sort_natural',
  132. 'split',
  133. 'strip',
  134. 'strip_html',
  135. 'strip_newlines',
  136. 'times',
  137. 'truncate',
  138. 'truncatewords',
  139. 'uniq',
  140. 'upcase',
  141. 'url_decode',
  142. 'url_encode',
  143. 'where'
  144. ],
  145. constants: ['true', 'false'],
  146. operators: ['==', '!=', '>', '<', '>=', '<='],
  147. symbol: /[=><!]+/,
  148. identifier: /[a-zA-Z_][\w]*/,
  149. tokenizer: {
  150. root: [
  151. [/\{\%\s*comment\s*\%\}/, 'comment.start.liquid', '@comment'],
  152. [/\{\{/, { token: '@rematch', switchTo: '@liquidState.root' }],
  153. [/\{\%/, { token: '@rematch', switchTo: '@liquidState.root' }],
  154. [/(<)([\w\-]+)(\/>)/, ['delimiter.html', 'tag.html', 'delimiter.html']],
  155. [/(<)([:\w]+)/, ['delimiter.html', { token: 'tag.html', next: '@otherTag' }]],
  156. [/(<\/)([\w\-]+)/, ['delimiter.html', { token: 'tag.html', next: '@otherTag' }]],
  157. [/</, 'delimiter.html'],
  158. [/\{/, 'delimiter.html'],
  159. [/[^<{]+/] // text
  160. ],
  161. comment: [
  162. [/\{\%\s*endcomment\s*\%\}/, 'comment.end.liquid', '@pop'],
  163. [/./, 'comment.content.liquid']
  164. ],
  165. otherTag: [
  166. [
  167. /\{\{/,
  168. {
  169. token: '@rematch',
  170. switchTo: '@liquidState.otherTag'
  171. }
  172. ],
  173. [
  174. /\{\%/,
  175. {
  176. token: '@rematch',
  177. switchTo: '@liquidState.otherTag'
  178. }
  179. ],
  180. [/\/?>/, 'delimiter.html', '@pop'],
  181. [/"([^"]*)"/, 'attribute.value'],
  182. [/'([^']*)'/, 'attribute.value'],
  183. [/[\w\-]+/, 'attribute.name'],
  184. [/=/, 'delimiter'],
  185. [/[ \t\r\n]+/] // whitespace
  186. ],
  187. liquidState: [
  188. [/\{\{/, 'delimiter.output.liquid'],
  189. [/\}\}/, { token: 'delimiter.output.liquid', switchTo: '@$S2.$S3' }],
  190. [/\{\%/, 'delimiter.tag.liquid'],
  191. [/raw\s*\%\}/, 'delimiter.tag.liquid', '@liquidRaw'],
  192. [/\%\}/, { token: 'delimiter.tag.liquid', switchTo: '@$S2.$S3' }],
  193. { include: 'liquidRoot' }
  194. ],
  195. liquidRaw: [
  196. [/^(?!\{\%\s*endraw\s*\%\}).+/],
  197. [/\{\%/, 'delimiter.tag.liquid'],
  198. [/@identifier/],
  199. [/\%\}/, { token: 'delimiter.tag.liquid', next: '@root' }],
  200. ],
  201. liquidRoot: [
  202. [/\d+(\.\d+)?/, 'number.liquid'],
  203. [/"[^"]*"/, 'string.liquid'],
  204. [/'[^']*'/, 'string.liquid'],
  205. [/\s+/],
  206. [
  207. /@symbol/,
  208. {
  209. cases: {
  210. '@operators': 'operator.liquid',
  211. '@default': ''
  212. }
  213. }
  214. ],
  215. [/\./],
  216. [
  217. /@identifier/,
  218. {
  219. cases: {
  220. '@constants': 'keyword.liquid',
  221. '@builtinFilters': 'predefined.liquid',
  222. '@builtinTags': 'predefined.liquid',
  223. '@default': 'variable.liquid'
  224. }
  225. }
  226. ],
  227. [/[^}|%]/, 'variable.liquid']
  228. ]
  229. }
  230. };
  231. });