soy_template_highlight_rules.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  1. /* ***** BEGIN LICENSE BLOCK *****
  2. * Distributed under the BSD license:
  3. *
  4. * Copyright (c) 2012, Ajax.org B.V.
  5. * All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions are met:
  9. * * Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. * * Redistributions in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in the
  13. * documentation and/or other materials provided with the distribution.
  14. * * Neither the name of Ajax.org B.V. nor the
  15. * names of its contributors may be used to endorse or promote products
  16. * derived from this software without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  19. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  20. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  21. * DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY
  22. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  23. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  24. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  25. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  26. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  27. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. *
  29. * ***** END LICENSE BLOCK ***** */
  30. /* This file was autogenerated from tm bundles\SoyTemplate\Syntaxes\SoyTemplate.tmLanguage (uuid: ) */
  31. /****************************************************************************************
  32. * IT MIGHT NOT BE PERFECT ...But it's a good start from an existing *.tmlanguage file. *
  33. * fileTypes *
  34. ****************************************************************************************/
  35. define(function(require, exports, module) {
  36. "use strict";
  37. var oop = require("../lib/oop");
  38. var HtmlHighlightRules = require("./html_highlight_rules").HtmlHighlightRules;
  39. var SoyTemplateHighlightRules = function() {
  40. HtmlHighlightRules.call(this);
  41. // regexp must not have capturing parentheses. Use (?:) instead.
  42. // regexps are ordered -> the first match is used
  43. var soyRules = { start:
  44. [ { include: '#template' },
  45. { include: '#if' },
  46. { include: '#comment-line' },
  47. { include: '#comment-block' },
  48. { include: '#comment-doc' },
  49. { include: '#call' },
  50. { include: '#css' },
  51. { include: '#param' },
  52. { include: '#print' },
  53. { include: '#msg' },
  54. { include: '#for' },
  55. { include: '#foreach' },
  56. { include: '#switch' },
  57. { include: '#tag' },
  58. { include: 'text.html.basic' } ],
  59. '#call':
  60. [ { token:
  61. [ 'punctuation.definition.tag.begin.soy',
  62. 'meta.tag.call.soy' ],
  63. regex: '(\\{/?)(\\s*)(?=call|delcall)',
  64. push:
  65. [ { token: 'punctuation.definition.tag.end.soy',
  66. regex: '\\}',
  67. next: 'pop' },
  68. { include: '#string-quoted-single' },
  69. { include: '#string-quoted-double' },
  70. { token: ['entity.name.tag.soy', 'variable.parameter.soy'],
  71. regex: '(call|delcall)(\\s+[\\.\\w]+)'},
  72. { token:
  73. [ 'entity.other.attribute-name.soy',
  74. 'text',
  75. 'keyword.operator.soy' ],
  76. regex: '\\b(data)(\\s*)(=)' },
  77. { defaultToken: 'meta.tag.call.soy' } ] } ],
  78. '#comment-line':
  79. [ { token:
  80. [ 'comment.line.double-slash.soy',
  81. 'punctuation.definition.comment.soy',
  82. 'comment.line.double-slash.soy' ],
  83. regex: '(\\s+)(//)(.*$)' } ],
  84. '#comment-block':
  85. [ { token: 'punctuation.definition.comment.begin.soy',
  86. regex: '/\\*(?!\\*)',
  87. push:
  88. [ { token: 'punctuation.definition.comment.end.soy',
  89. regex: '\\*/',
  90. next: 'pop' },
  91. { defaultToken: 'comment.block.soy' } ] } ],
  92. '#comment-doc':
  93. [ { token: 'punctuation.definition.comment.begin.soy',
  94. regex: '/\\*\\*(?!/)',
  95. push:
  96. [ { token: 'punctuation.definition.comment.end.soy',
  97. regex: '\\*/',
  98. next: 'pop' },
  99. { token: [ 'support.type.soy', 'text', 'variable.parameter.soy' ],
  100. regex: '(@param|@param\\?)(\\s+)(\\w+)' },
  101. { defaultToken: 'comment.block.documentation.soy' } ] } ],
  102. '#css':
  103. [ { token:
  104. [ 'punctuation.definition.tag.begin.soy',
  105. 'meta.tag.css.soy',
  106. 'entity.name.tag.soy' ],
  107. regex: '(\\{/?)(\\s*)(css)\\b',
  108. push:
  109. [ { token: 'punctuation.definition.tag.end.soy',
  110. regex: '\\}',
  111. next: 'pop' },
  112. { token: 'support.constant.soy',
  113. regex: '\\b(?:LITERAL|REFERENCE|BACKEND_SPECIFIC|GOOG)\\b' },
  114. { defaultToken: 'meta.tag.css.soy' } ] } ],
  115. '#for':
  116. [ { token:
  117. [ 'punctuation.definition.tag.begin.soy',
  118. 'meta.tag.for.soy',
  119. 'entity.name.tag.soy' ],
  120. regex: '(\\{/?)(\\s*)(for)\\b',
  121. push:
  122. [ { token: 'punctuation.definition.tag.end.soy',
  123. regex: '\\}',
  124. next: 'pop' },
  125. { token: 'keyword.operator.soy', regex: '\\bin\\b' },
  126. { token: 'support.function.soy', regex: '\\brange\\b' },
  127. { include: '#variable' },
  128. { include: '#number' },
  129. { include: '#primitive' },
  130. { defaultToken: 'meta.tag.for.soy' } ] } ],
  131. '#foreach':
  132. [ { token:
  133. [ 'punctuation.definition.tag.begin.soy',
  134. 'meta.tag.foreach.soy',
  135. 'entity.name.tag.soy' ],
  136. regex: '(\\{/?)(\\s*)(foreach)\\b',
  137. push:
  138. [ { token: 'punctuation.definition.tag.end.soy',
  139. regex: '\\}',
  140. next: 'pop' },
  141. { token: 'keyword.operator.soy', regex: '\\bin\\b' },
  142. { include: '#variable' },
  143. { defaultToken: 'meta.tag.foreach.soy' } ] } ],
  144. '#function':
  145. [ { token: 'support.function.soy',
  146. regex: '\\b(?:isFirst|isLast|index|hasData|length|keys|round|floor|ceiling|min|max|randomInt)\\b' } ],
  147. '#if':
  148. [ { token:
  149. [ 'punctuation.definition.tag.begin.soy',
  150. 'meta.tag.if.soy',
  151. 'entity.name.tag.soy' ],
  152. regex: '(\\{/?)(\\s*)(if|elseif)\\b',
  153. push:
  154. [ { token: 'punctuation.definition.tag.end.soy',
  155. regex: '\\}',
  156. next: 'pop' },
  157. { include: '#variable' },
  158. { include: '#operator' },
  159. { include: '#function' },
  160. { include: '#string-quoted-single' },
  161. { include: '#string-quoted-double' },
  162. { defaultToken: 'meta.tag.if.soy' } ] } ],
  163. '#namespace':
  164. [ { token: [ 'entity.name.tag.soy', 'text', 'variable.parameter.soy' ],
  165. regex: '(namespace|delpackage)(\\s+)([\\w\\.]+)' } ],
  166. '#number': [ { token: 'constant.numeric', regex: '[\\d]+' } ],
  167. '#operator':
  168. [ { token: 'keyword.operator.soy',
  169. regex: '==|!=|\\band\\b|\\bor\\b|\\bnot\\b|-|\\+|/|\\?:' } ],
  170. '#param':
  171. [ { token:
  172. [ 'punctuation.definition.tag.begin.soy',
  173. 'meta.tag.param.soy',
  174. 'entity.name.tag.soy' ],
  175. regex: '(\\{/?)(\\s*)(param)',
  176. push:
  177. [ { token: 'punctuation.definition.tag.end.soy',
  178. regex: '\\}',
  179. next: 'pop' },
  180. { include: '#variable' },
  181. { token:
  182. [ 'entity.other.attribute-name.soy',
  183. 'text',
  184. 'keyword.operator.soy' ],
  185. regex: '\\b([\\w]*)(\\s*)((?::)?)' },
  186. { defaultToken: 'meta.tag.param.soy' } ] } ],
  187. '#primitive':
  188. [ { token: 'constant.language.soy',
  189. regex: '\\b(?:null|false|true)\\b' } ],
  190. '#msg':
  191. [ { token:
  192. [ 'punctuation.definition.tag.begin.soy',
  193. 'meta.tag.msg.soy',
  194. 'entity.name.tag.soy' ],
  195. regex: '(\\{/?)(\\s*)(msg)\\b',
  196. push:
  197. [ { token: 'punctuation.definition.tag.end.soy',
  198. regex: '\\}',
  199. next: 'pop' },
  200. { include: '#string-quoted-single' },
  201. { include: '#string-quoted-double' },
  202. { token:
  203. [ 'entity.other.attribute-name.soy',
  204. 'text',
  205. 'keyword.operator.soy' ],
  206. regex: '\\b(meaning|desc)(\\s*)(=)' },
  207. { defaultToken: 'meta.tag.msg.soy' } ] } ],
  208. '#print':
  209. [ { token:
  210. [ 'punctuation.definition.tag.begin.soy',
  211. 'meta.tag.print.soy',
  212. 'entity.name.tag.soy' ],
  213. regex: '(\\{/?)(\\s*)(print)\\b',
  214. push:
  215. [ { token: 'punctuation.definition.tag.end.soy',
  216. regex: '\\}',
  217. next: 'pop' },
  218. { include: '#variable' },
  219. { include: '#print-parameter' },
  220. { include: '#number' },
  221. { include: '#primitive' },
  222. { include: '#attribute-lookup' },
  223. { defaultToken: 'meta.tag.print.soy' } ] } ],
  224. '#print-parameter':
  225. [ { token: 'keyword.operator.soy', regex: '\\|' },
  226. { token: 'variable.parameter.soy',
  227. regex: 'noAutoescape|id|escapeHtml|escapeJs|insertWorkBreaks|truncate' } ],
  228. '#special-character':
  229. [ { token: 'support.constant.soy',
  230. regex: '\\bsp\\b|\\bnil\\b|\\\\r|\\\\n|\\\\t|\\blb\\b|\\brb\\b' } ],
  231. '#string-quoted-double': [ { token: 'string.quoted.double', regex: '"[^"]*"' } ],
  232. '#string-quoted-single': [ { token: 'string.quoted.single', regex: '\'[^\']*\'' } ],
  233. '#switch':
  234. [ { token:
  235. [ 'punctuation.definition.tag.begin.soy',
  236. 'meta.tag.switch.soy',
  237. 'entity.name.tag.soy' ],
  238. regex: '(\\{/?)(\\s*)(switch|case)\\b',
  239. push:
  240. [ { token: 'punctuation.definition.tag.end.soy',
  241. regex: '\\}',
  242. next: 'pop' },
  243. { include: '#variable' },
  244. { include: '#function' },
  245. { include: '#number' },
  246. { include: '#string-quoted-single' },
  247. { include: '#string-quoted-double' },
  248. { defaultToken: 'meta.tag.switch.soy' } ] } ],
  249. '#attribute-lookup':
  250. [ { token: 'punctuation.definition.attribute-lookup.begin.soy',
  251. regex: '\\[',
  252. push:
  253. [ { token: 'punctuation.definition.attribute-lookup.end.soy',
  254. regex: '\\]',
  255. next: 'pop' },
  256. { include: '#variable' },
  257. { include: '#function' },
  258. { include: '#operator' },
  259. { include: '#number' },
  260. { include: '#primitive' },
  261. { include: '#string-quoted-single' },
  262. { include: '#string-quoted-double' } ] } ],
  263. '#tag':
  264. [ { token: 'punctuation.definition.tag.begin.soy',
  265. regex: '\\{',
  266. push:
  267. [ { token: 'punctuation.definition.tag.end.soy',
  268. regex: '\\}',
  269. next: 'pop' },
  270. { include: '#namespace' },
  271. { include: '#variable' },
  272. { include: '#special-character' },
  273. { include: '#tag-simple' },
  274. { include: '#function' },
  275. { include: '#operator' },
  276. { include: '#attribute-lookup' },
  277. { include: '#number' },
  278. { include: '#primitive' },
  279. { include: '#print-parameter' } ] } ],
  280. '#tag-simple':
  281. [ { token: 'entity.name.tag.soy',
  282. regex: '{{\\s*(?:literal|else|ifempty|default)\\s*(?=\\})'} ],
  283. '#template':
  284. [ { token:
  285. [ 'punctuation.definition.tag.begin.soy',
  286. 'meta.tag.template.soy' ],
  287. regex: '(\\{/?)(\\s*)(?=template|deltemplate)',
  288. push:
  289. [ { token: 'punctuation.definition.tag.end.soy',
  290. regex: '\\}',
  291. next: 'pop' },
  292. { token: ['entity.name.tag.soy', 'text', 'entity.name.function.soy' ],
  293. regex: '(template|deltemplate)(\\s+)([\\.\\w]+)',
  294. originalRegex: '(?<=template|deltemplate)\\s+([\\.\\w]+)' },
  295. { token:
  296. [ 'entity.other.attribute-name.soy',
  297. 'text',
  298. 'keyword.operator.soy',
  299. 'text',
  300. 'string.quoted.double.soy' ],
  301. regex: '\\b(private)(\\s*)(=)(\\s*)("true"|"false")' },
  302. { token:
  303. [ 'entity.other.attribute-name.soy',
  304. 'text',
  305. 'keyword.operator.soy',
  306. 'text',
  307. 'string.quoted.single.soy' ],
  308. regex: '\\b(private)(\\s*)(=)(\\s*)(\'true\'|\'false\')' },
  309. { token:
  310. [ 'entity.other.attribute-name.soy',
  311. 'text',
  312. 'keyword.operator.soy',
  313. 'text',
  314. 'string.quoted.double.soy' ],
  315. regex: '\\b(autoescape)(\\s*)(=)(\\s*)("true"|"false"|"contextual")' },
  316. { token:
  317. [ 'entity.other.attribute-name.soy',
  318. 'text',
  319. 'keyword.operator.soy',
  320. 'text',
  321. 'string.quoted.single.soy' ],
  322. regex: '\\b(autoescape)(\\s*)(=)(\\s*)(\'true\'|\'false\'|\'contextual\')' },
  323. { defaultToken: 'meta.tag.template.soy' } ] } ],
  324. '#variable': [ { token: 'variable.other.soy', regex: '\\$[\\w\\.]+' } ] }
  325. for (var i in soyRules) {
  326. if (this.$rules[i]) {
  327. this.$rules[i].unshift.call(this.$rules[i], soyRules[i]);
  328. } else {
  329. this.$rules[i] = soyRules[i];
  330. }
  331. }
  332. this.normalizeRules();
  333. };
  334. SoyTemplateHighlightRules.metaData = { comment: 'SoyTemplate',
  335. fileTypes: [ 'soy' ],
  336. firstLineMatch: '\\{\\s*namespace\\b',
  337. foldingStartMarker: '\\{\\s*template\\s+[^\\}]*\\}',
  338. foldingStopMarker: '\\{\\s*/\\s*template\\s*\\}',
  339. name: 'SoyTemplate',
  340. scopeName: 'source.soy' }
  341. oop.inherits(SoyTemplateHighlightRules, HtmlHighlightRules);
  342. exports.SoyTemplateHighlightRules = SoyTemplateHighlightRules;
  343. });