jade_highlight_rules.js 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  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. *
  30. * Contributor(s):
  31. *
  32. * Garen J. Torikian <gjtorikian @ gmail DOT com>
  33. *
  34. * ***** END LICENSE BLOCK ***** */
  35. /*
  36. THIS FILE WAS AUTOGENERATED BY mode_highlight_rules.tmpl.js (UUID: C5B73B98-5F2A-42E3-9F0E-028A74A9FE4B)
  37. */
  38. define(function(require, exports, module) {
  39. "use strict";
  40. var oop = require("../lib/oop");
  41. var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
  42. var MarkdownHighlightRules = require("./markdown_highlight_rules").MarkdownHighlightRules;
  43. var SassHighlightRules = require("./scss_highlight_rules").ScssHighlightRules;
  44. var LessHighlightRules = require("./less_highlight_rules").LessHighlightRules;
  45. var CoffeeHighlightRules = require("./coffee_highlight_rules").CoffeeHighlightRules;
  46. var JavaScriptHighlightRules = require("./javascript_highlight_rules").JavaScriptHighlightRules;
  47. function mixin_embed(tag, prefix) {
  48. return {
  49. token : "entity.name.function.jade",
  50. regex : "^\\s*\\:" + tag,
  51. next : prefix + "start"
  52. };
  53. }
  54. var JadeHighlightRules = function() {
  55. var escapedRe = "\\\\(?:x[0-9a-fA-F]{2}|" + // hex
  56. "u[0-9a-fA-F]{4}|" + // unicode
  57. "[0-2][0-7]{0,2}|" + // oct
  58. "3[0-6][0-7]?|" + // oct
  59. "37[0-7]?|" + // oct
  60. "[4-7][0-7]?|" + //oct
  61. ".)";
  62. // regexp must not have capturing parentheses. Use (?:) instead.
  63. // regexps are ordered -> the first match is used
  64. this.$rules =
  65. {
  66. "start": [
  67. {
  68. token: "keyword.control.import.include.jade",
  69. regex: "\\s*\\binclude\\b"
  70. },
  71. {
  72. token: "keyword.other.doctype.jade",
  73. regex: "^!!!\\s*(?:[a-zA-Z0-9-_]+)?"
  74. },
  75. {
  76. token : "punctuation.section.comment",
  77. regex : "^\\s*\/\/(?:\\s*[^-\\s]|\\s+\\S)(?:.*$)"
  78. },
  79. {
  80. onMatch: function(value, currentState, stack) {
  81. stack.unshift(this.next, value.length - 2, currentState);
  82. return "comment";
  83. },
  84. regex: /^\s*\/\//,
  85. next: "comment_block"
  86. },
  87. mixin_embed("markdown", "markdown-"),
  88. mixin_embed("sass", "sass-"),
  89. mixin_embed("less", "less-"),
  90. mixin_embed("coffee", "coffee-"),
  91. /*
  92. {
  93. token: {
  94. "2": {
  95. "name": "entity.name.function.jade"
  96. }
  97. },
  98. regex: "^(\\s*)(\\:cdata)",
  99. next: "state_9"
  100. },*/
  101. // match stuff like: mixin dialog-title-desc(title, desc)
  102. {
  103. token: [ "storage.type.function.jade",
  104. "entity.name.function.jade",
  105. "punctuation.definition.parameters.begin.jade",
  106. "variable.parameter.function.jade",
  107. "punctuation.definition.parameters.end.jade"
  108. ],
  109. regex: "^(\\s*mixin)( [\\w\\-]+)(\\s*\\()(.*?)(\\))"
  110. },
  111. // match stuff like: mixin dialog-title-desc
  112. {
  113. token: [ "storage.type.function.jade", "entity.name.function.jade"],
  114. regex: "^(\\s*mixin)( [\\w\\-]+)"
  115. },
  116. {
  117. token: "source.js.embedded.jade",
  118. regex: "^\\s*(?:-|=|!=)",
  119. next: "js-start"
  120. },
  121. /*{
  122. token: "entity.name.tag.script.jade",
  123. regex: "^\\s*script",
  124. next: "js_code_tag"
  125. },*/
  126. {
  127. token: "string.interpolated.jade",
  128. regex: "[#!]\\{[^\\}]+\\}"
  129. },
  130. // Match any tag, id or class. skip AST filters
  131. {
  132. token: "meta.tag.any.jade",
  133. regex: /^\s*(?!\w+\:)(?:[\w-]+|(?=\.|#)])/,
  134. next: "tag_single"
  135. },
  136. {
  137. token: "suport.type.attribute.id.jade",
  138. regex: "#\\w+"
  139. },
  140. {
  141. token: "suport.type.attribute.class.jade",
  142. regex: "\\.\\w+"
  143. },
  144. {
  145. token: "punctuation",
  146. regex: "\\s*(?:\\()",
  147. next: "tag_attributes"
  148. }
  149. ],
  150. "comment_block": [
  151. {regex: /^\s*/, onMatch: function(value, currentState, stack) {
  152. if (value.length <= stack[1]) {
  153. stack.shift();
  154. stack.shift();
  155. this.next = stack.shift();
  156. return "text";
  157. } else {
  158. this.next = "";
  159. return "comment";
  160. }
  161. }, next: "start"},
  162. {defaultToken: "comment"}
  163. ],
  164. /*
  165. "state_9": [
  166. {
  167. token: "TODO",
  168. regex: "^(?!\\1\\s+)",
  169. next: "start"
  170. },
  171. {
  172. token: "TODO",
  173. regex: ".+",
  174. next: "state_9"
  175. }
  176. ],*/
  177. /*"js_code": [
  178. {
  179. token: "keyword.control.js",
  180. regex: "\\beach\\b"
  181. },
  182. {
  183. token: "text",
  184. regex: "$",
  185. next: "start"
  186. }
  187. ],*/
  188. /*"js_code_tag": [
  189. {
  190. "include": "source.js"
  191. },
  192. {
  193. token: "TODO",
  194. regex: "^((?=(\\1)([\\w#\\.]|$\\n?))|^$\\n?)",
  195. next: "start"
  196. }
  197. ],*/
  198. "tag_single": [
  199. {
  200. token: "entity.other.attribute-name.class.jade",
  201. regex: "\\.[\\w-]+"
  202. },
  203. {
  204. token: "entity.other.attribute-name.id.jade",
  205. regex: "#[\\w-]+"
  206. },
  207. {
  208. token: ["text", "punctuation"],
  209. regex: "($)|((?!\\.|#|=|-))",
  210. next: "start"
  211. }
  212. ],
  213. "tag_attributes": [
  214. {
  215. token : "string",
  216. regex : "'(?=.)",
  217. next : "qstring"
  218. },
  219. {
  220. token : "string",
  221. regex : '"(?=.)',
  222. next : "qqstring"
  223. },
  224. {
  225. token: ["entity.other.attribute-name.jade", "punctuation"],
  226. regex: "([a-zA-Z:\\.-]+)(=)?",
  227. next: "attribute_strings"
  228. },
  229. {
  230. token: "punctuation",
  231. regex: "\\)",
  232. next: "start"
  233. }
  234. ],
  235. "attribute_strings": [
  236. {
  237. token : "string",
  238. regex : "'(?=.)",
  239. next : "qstring"
  240. },
  241. {
  242. token : "string",
  243. regex : '"(?=.)',
  244. next : "qqstring"
  245. },
  246. {
  247. token : "string",
  248. regex : '(?=\\S)',
  249. next : "tag_attributes"
  250. }
  251. ],
  252. "qqstring" : [
  253. {
  254. token : "constant.language.escape",
  255. regex : escapedRe
  256. }, {
  257. token : "string",
  258. regex : '[^"\\\\]+'
  259. }, {
  260. token : "string",
  261. regex : "\\\\$",
  262. next : "qqstring"
  263. }, {
  264. token : "string",
  265. regex : '"|$',
  266. next : "tag_attributes"
  267. }
  268. ],
  269. "qstring" : [
  270. {
  271. token : "constant.language.escape",
  272. regex : escapedRe
  273. }, {
  274. token : "string",
  275. regex : "[^'\\\\]+"
  276. }, {
  277. token : "string",
  278. regex : "\\\\$",
  279. next : "qstring"
  280. }, {
  281. token : "string",
  282. regex : "'|$",
  283. next : "tag_attributes"
  284. }
  285. ]
  286. };
  287. this.embedRules(JavaScriptHighlightRules, "js-", [{
  288. token: "text",
  289. regex: ".$",
  290. next: "start"
  291. }]);
  292. /*
  293. this.embedRules(MarkdownHighlightRules, "markdown-", [{
  294. token : "support.function",
  295. regex : "^\\1\\s+",
  296. captures: "1",
  297. next : "start"
  298. }]);
  299. this.embedRules(SassHighlightRules, "sass-", [{
  300. token : "support.function",
  301. regex : "^(?!\\1\\s+)",
  302. captures: "1",
  303. next : "start"
  304. }]);
  305. this.embedRules(LessHighlightRules, "less-", [{
  306. token : "support.function",
  307. regex : "^(?!\\1\\s+)",
  308. captures: "1",
  309. next : "start"
  310. }]);
  311. this.embedRules(CoffeeHighlightRules, "coffee-", [{
  312. token : "support.function",
  313. regex : "^(?!\\1\\s+)",
  314. captures: "1",
  315. next : "start"
  316. }]);
  317. this.embedRules(JavaScriptHighlightRules, "js-", [{
  318. token : "support.function",
  319. regex : "$",
  320. captures: "1",
  321. next : "start"
  322. }]); */
  323. };
  324. oop.inherits(JadeHighlightRules, TextHighlightRules);
  325. exports.JadeHighlightRules = JadeHighlightRules;
  326. });