mode-stylus.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  1. ace.define("ace/mode/css_highlight_rules",["require","exports","module","ace/lib/oop","ace/lib/lang","ace/mode/text_highlight_rules"], function(require, exports, module) {
  2. "use strict";
  3. var oop = require("../lib/oop");
  4. var lang = require("../lib/lang");
  5. var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
  6. var supportType = exports.supportType = "align-content|align-items|align-self|all|animation|animation-delay|animation-direction|animation-duration|animation-fill-mode|animation-iteration-count|animation-name|animation-play-state|animation-timing-function|backface-visibility|background|background-attachment|background-blend-mode|background-clip|background-color|background-image|background-origin|background-position|background-repeat|background-size|border|border-bottom|border-bottom-color|border-bottom-left-radius|border-bottom-right-radius|border-bottom-style|border-bottom-width|border-collapse|border-color|border-image|border-image-outset|border-image-repeat|border-image-slice|border-image-source|border-image-width|border-left|border-left-color|border-left-style|border-left-width|border-radius|border-right|border-right-color|border-right-style|border-right-width|border-spacing|border-style|border-top|border-top-color|border-top-left-radius|border-top-right-radius|border-top-style|border-top-width|border-width|bottom|box-shadow|box-sizing|caption-side|clear|clip|color|column-count|column-fill|column-gap|column-rule|column-rule-color|column-rule-style|column-rule-width|column-span|column-width|columns|content|counter-increment|counter-reset|cursor|direction|display|empty-cells|filter|flex|flex-basis|flex-direction|flex-flow|flex-grow|flex-shrink|flex-wrap|float|font|font-family|font-size|font-size-adjust|font-stretch|font-style|font-variant|font-weight|hanging-punctuation|height|justify-content|left|letter-spacing|line-height|list-style|list-style-image|list-style-position|list-style-type|margin|margin-bottom|margin-left|margin-right|margin-top|max-height|max-width|min-height|min-width|nav-down|nav-index|nav-left|nav-right|nav-up|opacity|order|outline|outline-color|outline-offset|outline-style|outline-width|overflow|overflow-x|overflow-y|padding|padding-bottom|padding-left|padding-right|padding-top|page-break-after|page-break-before|page-break-inside|perspective|perspective-origin|position|quotes|resize|right|tab-size|table-layout|text-align|text-align-last|text-decoration|text-decoration-color|text-decoration-line|text-decoration-style|text-indent|text-justify|text-overflow|text-shadow|text-transform|top|transform|transform-origin|transform-style|transition|transition-delay|transition-duration|transition-property|transition-timing-function|unicode-bidi|vertical-align|visibility|white-space|width|word-break|word-spacing|word-wrap|z-index";
  7. var supportFunction = exports.supportFunction = "rgb|rgba|url|attr|counter|counters";
  8. var supportConstant = exports.supportConstant = "absolute|after-edge|after|all-scroll|all|alphabetic|always|antialiased|armenian|auto|avoid-column|avoid-page|avoid|balance|baseline|before-edge|before|below|bidi-override|block-line-height|block|bold|bolder|border-box|both|bottom|box|break-all|break-word|capitalize|caps-height|caption|center|central|char|circle|cjk-ideographic|clone|close-quote|col-resize|collapse|column|consider-shifts|contain|content-box|cover|crosshair|cubic-bezier|dashed|decimal-leading-zero|decimal|default|disabled|disc|disregard-shifts|distribute-all-lines|distribute-letter|distribute-space|distribute|dotted|double|e-resize|ease-in|ease-in-out|ease-out|ease|ellipsis|end|exclude-ruby|fill|fixed|georgian|glyphs|grid-height|groove|hand|hanging|hebrew|help|hidden|hiragana-iroha|hiragana|horizontal|icon|ideograph-alpha|ideograph-numeric|ideograph-parenthesis|ideograph-space|ideographic|inactive|include-ruby|inherit|initial|inline-block|inline-box|inline-line-height|inline-table|inline|inset|inside|inter-ideograph|inter-word|invert|italic|justify|katakana-iroha|katakana|keep-all|last|left|lighter|line-edge|line-through|line|linear|list-item|local|loose|lower-alpha|lower-greek|lower-latin|lower-roman|lowercase|lr-tb|ltr|mathematical|max-height|max-size|medium|menu|message-box|middle|move|n-resize|ne-resize|newspaper|no-change|no-close-quote|no-drop|no-open-quote|no-repeat|none|normal|not-allowed|nowrap|nw-resize|oblique|open-quote|outset|outside|overline|padding-box|page|pointer|pre-line|pre-wrap|pre|preserve-3d|progress|relative|repeat-x|repeat-y|repeat|replaced|reset-size|ridge|right|round|row-resize|rtl|s-resize|scroll|se-resize|separate|slice|small-caps|small-caption|solid|space|square|start|static|status-bar|step-end|step-start|steps|stretch|strict|sub|super|sw-resize|table-caption|table-cell|table-column-group|table-column|table-footer-group|table-header-group|table-row-group|table-row|table|tb-rl|text-after-edge|text-before-edge|text-bottom|text-size|text-top|text|thick|thin|transparent|underline|upper-alpha|upper-latin|upper-roman|uppercase|use-script|vertical-ideographic|vertical-text|visible|w-resize|wait|whitespace|z-index|zero";
  9. var supportConstantColor = exports.supportConstantColor = "aqua|black|blue|fuchsia|gray|green|lime|maroon|navy|olive|orange|purple|red|silver|teal|white|yellow";
  10. var supportConstantFonts = exports.supportConstantFonts = "arial|century|comic|courier|cursive|fantasy|garamond|georgia|helvetica|impact|lucida|symbol|system|tahoma|times|trebuchet|utopia|verdana|webdings|sans-serif|serif|monospace";
  11. var numRe = exports.numRe = "\\-?(?:(?:[0-9]+)|(?:[0-9]*\\.[0-9]+))";
  12. var pseudoElements = exports.pseudoElements = "(\\:+)\\b(after|before|first-letter|first-line|moz-selection|selection)\\b";
  13. var pseudoClasses = exports.pseudoClasses = "(:)\\b(active|checked|disabled|empty|enabled|first-child|first-of-type|focus|hover|indeterminate|invalid|last-child|last-of-type|link|not|nth-child|nth-last-child|nth-last-of-type|nth-of-type|only-child|only-of-type|required|root|target|valid|visited)\\b";
  14. var CssHighlightRules = function() {
  15. var keywordMapper = this.createKeywordMapper({
  16. "support.function": supportFunction,
  17. "support.constant": supportConstant,
  18. "support.type": supportType,
  19. "support.constant.color": supportConstantColor,
  20. "support.constant.fonts": supportConstantFonts
  21. }, "text", true);
  22. this.$rules = {
  23. "start" : [{
  24. token : "comment", // multi line comment
  25. regex : "\\/\\*",
  26. push : "comment"
  27. }, {
  28. token: "paren.lparen",
  29. regex: "\\{",
  30. push: "ruleset"
  31. }, {
  32. token: "string",
  33. regex: "@.*?{",
  34. push: "media"
  35. }, {
  36. token: "keyword",
  37. regex: "#[a-z0-9-_]+"
  38. }, {
  39. token: "variable",
  40. regex: "\\.[a-z0-9-_]+"
  41. }, {
  42. token: "string",
  43. regex: ":[a-z0-9-_]+"
  44. }, {
  45. token: "constant",
  46. regex: "[a-z0-9-_]+"
  47. }, {
  48. caseInsensitive: true
  49. }],
  50. "media" : [{
  51. token : "comment", // multi line comment
  52. regex : "\\/\\*",
  53. push : "comment"
  54. }, {
  55. token: "paren.lparen",
  56. regex: "\\{",
  57. push: "ruleset"
  58. }, {
  59. token: "string",
  60. regex: "\\}",
  61. next: "pop"
  62. }, {
  63. token: "keyword",
  64. regex: "#[a-z0-9-_]+"
  65. }, {
  66. token: "variable",
  67. regex: "\\.[a-z0-9-_]+"
  68. }, {
  69. token: "string",
  70. regex: ":[a-z0-9-_]+"
  71. }, {
  72. token: "constant",
  73. regex: "[a-z0-9-_]+"
  74. }, {
  75. caseInsensitive: true
  76. }],
  77. "comment" : [{
  78. token : "comment",
  79. regex : "\\*\\/",
  80. next : "pop"
  81. }, {
  82. defaultToken : "comment"
  83. }],
  84. "ruleset" : [
  85. {
  86. token : "paren.rparen",
  87. regex : "\\}",
  88. next: "pop"
  89. }, {
  90. token : "comment", // multi line comment
  91. regex : "\\/\\*",
  92. push : "comment"
  93. }, {
  94. token : "string", // single line
  95. regex : '["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]'
  96. }, {
  97. token : "string", // single line
  98. regex : "['](?:(?:\\\\.)|(?:[^'\\\\]))*?[']"
  99. }, {
  100. token : ["constant.numeric", "keyword"],
  101. regex : "(" + numRe + ")(ch|cm|deg|em|ex|fr|gd|grad|Hz|in|kHz|mm|ms|pc|pt|px|rad|rem|s|turn|vh|vm|vw|%)"
  102. }, {
  103. token : "constant.numeric",
  104. regex : numRe
  105. }, {
  106. token : "constant.numeric", // hex6 color
  107. regex : "#[a-f0-9]{6}"
  108. }, {
  109. token : "constant.numeric", // hex3 color
  110. regex : "#[a-f0-9]{3}"
  111. }, {
  112. token : ["punctuation", "entity.other.attribute-name.pseudo-element.css"],
  113. regex : pseudoElements
  114. }, {
  115. token : ["punctuation", "entity.other.attribute-name.pseudo-class.css"],
  116. regex : pseudoClasses
  117. }, {
  118. token : ["support.function", "string", "support.function"],
  119. regex : "(url\\()(.*)(\\))"
  120. }, {
  121. token : keywordMapper,
  122. regex : "\\-?[a-zA-Z_][a-zA-Z0-9_\\-]*"
  123. }, {
  124. caseInsensitive: true
  125. }]
  126. };
  127. this.normalizeRules();
  128. };
  129. oop.inherits(CssHighlightRules, TextHighlightRules);
  130. exports.CssHighlightRules = CssHighlightRules;
  131. });
  132. ace.define("ace/mode/stylus_highlight_rules",["require","exports","module","ace/lib/oop","ace/mode/text_highlight_rules","ace/mode/css_highlight_rules"], function(require, exports, module) {
  133. "use strict";
  134. var oop = require("../lib/oop");
  135. var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
  136. var CssHighlightRules = require("./css_highlight_rules");
  137. var StylusHighlightRules = function() {
  138. var keywordMapper = this.createKeywordMapper({
  139. "support.type": CssHighlightRules.supportType,
  140. "support.function": CssHighlightRules.supportFunction,
  141. "support.constant": CssHighlightRules.supportConstant,
  142. "support.constant.color": CssHighlightRules.supportConstantColor,
  143. "support.constant.fonts": CssHighlightRules.supportConstantFonts
  144. }, "text", true);
  145. this.$rules = {
  146. start: [
  147. {
  148. token : "comment",
  149. regex : /\/\/.*$/
  150. },
  151. {
  152. token : "comment", // multi line comment
  153. regex : /\/\*/,
  154. next : "comment"
  155. },
  156. {
  157. token: ["entity.name.function.stylus", "text"],
  158. regex: "^([-a-zA-Z_][-\\w]*)?(\\()"
  159. },
  160. {
  161. token: ["entity.other.attribute-name.class.stylus"],
  162. regex: "\\.-?[_a-zA-Z]+[_a-zA-Z0-9-]*"
  163. },
  164. {
  165. token: ["entity.language.stylus"],
  166. regex: "^ *&"
  167. },
  168. {
  169. token: ["variable.language.stylus"],
  170. regex: "(arguments)"
  171. },
  172. {
  173. token: ["keyword.stylus"],
  174. regex: "@[-\\w]+"
  175. },
  176. {
  177. token : ["punctuation", "entity.other.attribute-name.pseudo-element.css"],
  178. regex : CssHighlightRules.pseudoElements
  179. }, {
  180. token : ["punctuation", "entity.other.attribute-name.pseudo-class.css"],
  181. regex : CssHighlightRules.pseudoClasses
  182. },
  183. {
  184. token: ["entity.name.tag.stylus"],
  185. regex: "(?:\\b)(a|abbr|acronym|address|area|article|aside|audio|b|base|big|blockquote|body|br|button|canvas|caption|cite|code|col|colgroup|datalist|dd|del|details|dfn|dialog|div|dl|dt|em|eventsource|fieldset|figure|figcaption|footer|form|frame|frameset|(?:h[1-6])|head|header|hgroup|hr|html|i|iframe|img|input|ins|kbd|label|legend|li|link|map|mark|menu|meta|meter|nav|noframes|noscript|object|ol|optgroup|option|output|p|param|pre|progress|q|samp|script|section|select|small|span|strike|strong|style|sub|summary|sup|table|tbody|td|textarea|tfoot|th|thead|time|title|tr|tt|ul|var|video)(?:\\b)"
  186. },
  187. {
  188. token : "constant.numeric", // hex6 color
  189. regex : "#[a-f0-9]{6}"
  190. },
  191. {
  192. token : "constant.numeric", // hex3 color
  193. regex : "#[a-f0-9]{3}"
  194. },
  195. {
  196. token: ["punctuation.definition.entity.stylus", "entity.other.attribute-name.id.stylus"],
  197. regex: "(#)([a-zA-Z][a-zA-Z0-9_-]*)"
  198. },
  199. {
  200. token: "meta.vendor-prefix.stylus",
  201. regex: "-webkit-|-moz\\-|-ms-|-o-"
  202. },
  203. {
  204. token: "keyword.control.stylus",
  205. regex: "(?:!important|for|in|return|true|false|null|if|else|unless|return)\\b"
  206. },
  207. {
  208. token: "keyword.operator.stylus",
  209. regex: "!|~|\\+|-|(?:\\*)?\\*|\\/|%|(?:\\.)\\.\\.|<|>|(?:=|:|\\?|\\+|-|\\*|\\/|%|<|>)?=|!="
  210. },
  211. {
  212. token: "keyword.operator.stylus",
  213. regex: "(?:in|is(?:nt)?|not)\\b"
  214. },
  215. {
  216. token : "string",
  217. regex : "'(?=.)",
  218. next : "qstring"
  219. }, {
  220. token : "string",
  221. regex : '"(?=.)',
  222. next : "qqstring"
  223. },
  224. {
  225. token : "constant.numeric",
  226. regex : CssHighlightRules.numRe
  227. },
  228. {
  229. token : "keyword",
  230. regex : "(?:ch|cm|deg|em|ex|fr|gd|grad|Hz|in|kHz|mm|ms|pc|pt|px|rad|rem|s|turn|vh|vm|vw|%)\\b"
  231. },
  232. {
  233. token : keywordMapper,
  234. regex : "\\-?[a-zA-Z_][a-zA-Z0-9_\\-]*"
  235. }
  236. ],
  237. "comment" : [
  238. {
  239. token : "comment", // closing comment
  240. regex : ".*?\\*\\/",
  241. next : "start"
  242. }, {
  243. token : "comment", // comment spanning whole line
  244. regex : ".+"
  245. }
  246. ],
  247. "qqstring" : [
  248. {
  249. token : "string",
  250. regex : '[^"\\\\]+'
  251. },
  252. {
  253. token : "string",
  254. regex : "\\\\$",
  255. next : "qqstring"
  256. },
  257. {
  258. token : "string",
  259. regex : '"|$',
  260. next : "start"
  261. }
  262. ],
  263. "qstring" : [
  264. {
  265. token : "string",
  266. regex : "[^'\\\\]+"
  267. },
  268. {
  269. token : "string",
  270. regex : "\\\\$",
  271. next : "qstring"
  272. },
  273. {
  274. token : "string",
  275. regex : "'|$",
  276. next : "start"
  277. }
  278. ]
  279. }
  280. };
  281. oop.inherits(StylusHighlightRules, TextHighlightRules);
  282. exports.StylusHighlightRules = StylusHighlightRules;
  283. });
  284. ace.define("ace/mode/folding/coffee",["require","exports","module","ace/lib/oop","ace/mode/folding/fold_mode","ace/range"], function(require, exports, module) {
  285. "use strict";
  286. var oop = require("../../lib/oop");
  287. var BaseFoldMode = require("./fold_mode").FoldMode;
  288. var Range = require("../../range").Range;
  289. var FoldMode = exports.FoldMode = function() {};
  290. oop.inherits(FoldMode, BaseFoldMode);
  291. (function() {
  292. this.getFoldWidgetRange = function(session, foldStyle, row) {
  293. var range = this.indentationBlock(session, row);
  294. if (range)
  295. return range;
  296. var re = /\S/;
  297. var line = session.getLine(row);
  298. var startLevel = line.search(re);
  299. if (startLevel == -1 || line[startLevel] != "#")
  300. return;
  301. var startColumn = line.length;
  302. var maxRow = session.getLength();
  303. var startRow = row;
  304. var endRow = row;
  305. while (++row < maxRow) {
  306. line = session.getLine(row);
  307. var level = line.search(re);
  308. if (level == -1)
  309. continue;
  310. if (line[level] != "#")
  311. break;
  312. endRow = row;
  313. }
  314. if (endRow > startRow) {
  315. var endColumn = session.getLine(endRow).length;
  316. return new Range(startRow, startColumn, endRow, endColumn);
  317. }
  318. };
  319. this.getFoldWidget = function(session, foldStyle, row) {
  320. var line = session.getLine(row);
  321. var indent = line.search(/\S/);
  322. var next = session.getLine(row + 1);
  323. var prev = session.getLine(row - 1);
  324. var prevIndent = prev.search(/\S/);
  325. var nextIndent = next.search(/\S/);
  326. if (indent == -1) {
  327. session.foldWidgets[row - 1] = prevIndent!= -1 && prevIndent < nextIndent ? "start" : "";
  328. return "";
  329. }
  330. if (prevIndent == -1) {
  331. if (indent == nextIndent && line[indent] == "#" && next[indent] == "#") {
  332. session.foldWidgets[row - 1] = "";
  333. session.foldWidgets[row + 1] = "";
  334. return "start";
  335. }
  336. } else if (prevIndent == indent && line[indent] == "#" && prev[indent] == "#") {
  337. if (session.getLine(row - 2).search(/\S/) == -1) {
  338. session.foldWidgets[row - 1] = "start";
  339. session.foldWidgets[row + 1] = "";
  340. return "";
  341. }
  342. }
  343. if (prevIndent!= -1 && prevIndent < indent)
  344. session.foldWidgets[row - 1] = "start";
  345. else
  346. session.foldWidgets[row - 1] = "";
  347. if (indent < nextIndent)
  348. return "start";
  349. else
  350. return "";
  351. };
  352. }).call(FoldMode.prototype);
  353. });
  354. ace.define("ace/mode/stylus",["require","exports","module","ace/lib/oop","ace/mode/text","ace/mode/stylus_highlight_rules","ace/mode/folding/coffee"], function(require, exports, module) {
  355. "use strict";
  356. var oop = require("../lib/oop");
  357. var TextMode = require("./text").Mode;
  358. var StylusHighlightRules = require("./stylus_highlight_rules").StylusHighlightRules;
  359. var FoldMode = require("./folding/coffee").FoldMode;
  360. var Mode = function() {
  361. this.HighlightRules = StylusHighlightRules;
  362. this.foldingRules = new FoldMode();
  363. this.$behaviour = this.$defaultBehaviour;
  364. };
  365. oop.inherits(Mode, TextMode);
  366. (function() {
  367. this.lineCommentStart = "//";
  368. this.blockComment = {start: "/*", end: "*/"};
  369. this.$id = "ace/mode/stylus";
  370. }).call(Mode.prototype);
  371. exports.Mode = Mode;
  372. });