jade_highlight_rules.js 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  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",
  226. regex: "\\b[a-zA-Z\\-:]+"
  227. },
  228. {
  229. token: ["entity.other.attribute-name.jade", "punctuation"],
  230. regex: "\\b([a-zA-Z:\\.-]+)(=)",
  231. next: "attribute_strings"
  232. },
  233. {
  234. token: "punctuation",
  235. regex: "\\)",
  236. next: "start"
  237. }
  238. ],
  239. "attribute_strings": [
  240. {
  241. token : "string",
  242. regex : "'(?=.)",
  243. next : "qstring"
  244. },
  245. {
  246. token : "string",
  247. regex : '"(?=.)',
  248. next : "qqstring"
  249. }
  250. ],
  251. "qqstring" : [
  252. {
  253. token : "constant.language.escape",
  254. regex : escapedRe
  255. }, {
  256. token : "string",
  257. regex : '[^"\\\\]+'
  258. }, {
  259. token : "string",
  260. regex : "\\\\$",
  261. next : "qqstring"
  262. }, {
  263. token : "string",
  264. regex : '"|$',
  265. next : "tag_attributes"
  266. }
  267. ],
  268. "qstring" : [
  269. {
  270. token : "constant.language.escape",
  271. regex : escapedRe
  272. }, {
  273. token : "string",
  274. regex : "[^'\\\\]+"
  275. }, {
  276. token : "string",
  277. regex : "\\\\$",
  278. next : "qstring"
  279. }, {
  280. token : "string",
  281. regex : "'|$",
  282. next : "tag_attributes"
  283. }
  284. ]
  285. };
  286. this.embedRules(JavaScriptHighlightRules, "js-", [{
  287. token: "text",
  288. regex: ".$",
  289. next: "start"
  290. }]);
  291. /*
  292. this.embedRules(MarkdownHighlightRules, "markdown-", [{
  293. token : "support.function",
  294. regex : "^\\1\\s+",
  295. captures: "1",
  296. next : "start"
  297. }]);
  298. this.embedRules(SassHighlightRules, "sass-", [{
  299. token : "support.function",
  300. regex : "^(?!\\1\\s+)",
  301. captures: "1",
  302. next : "start"
  303. }]);
  304. this.embedRules(LessHighlightRules, "less-", [{
  305. token : "support.function",
  306. regex : "^(?!\\1\\s+)",
  307. captures: "1",
  308. next : "start"
  309. }]);
  310. this.embedRules(CoffeeHighlightRules, "coffee-", [{
  311. token : "support.function",
  312. regex : "^(?!\\1\\s+)",
  313. captures: "1",
  314. next : "start"
  315. }]);
  316. this.embedRules(JavaScriptHighlightRules, "js-", [{
  317. token : "support.function",
  318. regex : "$",
  319. captures: "1",
  320. next : "start"
  321. }]); */
  322. };
  323. oop.inherits(JadeHighlightRules, TextHighlightRules);
  324. exports.JadeHighlightRules = JadeHighlightRules;
  325. });