mode-stylus.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471
  1. ace.define("ace/mode/css_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|max-zoom|min-height|min-width|min-zoom|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|user-select|user-zoom|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|zoom";
  9. var supportConstantColor = exports.supportConstantColor = "aliceblue|antiquewhite|aqua|aquamarine|azure|beige|bisque|black|blanchedalmond|blue|blueviolet|brown|burlywood|cadetblue|chartreuse|chocolate|coral|cornflowerblue|cornsilk|crimson|cyan|darkblue|darkcyan|darkgoldenrod|darkgray|darkgreen|darkgrey|darkkhaki|darkmagenta|darkolivegreen|darkorange|darkorchid|darkred|darksalmon|darkseagreen|darkslateblue|darkslategray|darkslategrey|darkturquoise|darkviolet|deeppink|deepskyblue|dimgray|dimgrey|dodgerblue|firebrick|floralwhite|forestgreen|fuchsia|gainsboro|ghostwhite|gold|goldenrod|gray|green|greenyellow|grey|honeydew|hotpink|indianred|indigo|ivory|khaki|lavender|lavenderblush|lawngreen|lemonchiffon|lightblue|lightcoral|lightcyan|lightgoldenrodyellow|lightgray|lightgreen|lightgrey|lightpink|lightsalmon|lightseagreen|lightskyblue|lightslategray|lightslategrey|lightsteelblue|lightyellow|lime|limegreen|linen|magenta|maroon|mediumaquamarine|mediumblue|mediumorchid|mediumpurple|mediumseagreen|mediumslateblue|mediumspringgreen|mediumturquoise|mediumvioletred|midnightblue|mintcream|mistyrose|moccasin|navajowhite|navy|oldlace|olive|olivedrab|orange|orangered|orchid|palegoldenrod|palegreen|paleturquoise|palevioletred|papayawhip|peachpuff|peru|pink|plum|powderblue|purple|rebeccapurple|red|rosybrown|royalblue|saddlebrown|salmon|sandybrown|seagreen|seashell|sienna|silver|skyblue|slateblue|slategray|slategrey|snow|springgreen|steelblue|tan|teal|thistle|tomato|turquoise|violet|wheat|white|whitesmoke|yellow|yellowgreen";
  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. include : ["strings", "url", "comments"]
  25. }, {
  26. token: "paren.lparen",
  27. regex: "\\{",
  28. next: "ruleset"
  29. }, {
  30. token: "paren.rparen",
  31. regex: "\\}"
  32. }, {
  33. token: "string",
  34. regex: "@(?!viewport)",
  35. next: "media"
  36. }, {
  37. token: "keyword",
  38. regex: "#[a-z0-9-_]+"
  39. }, {
  40. token: "keyword",
  41. regex: "%"
  42. }, {
  43. token: "variable",
  44. regex: "\\.[a-z0-9-_]+"
  45. }, {
  46. token: "string",
  47. regex: ":[a-z0-9-_]+"
  48. }, {
  49. token : "constant.numeric",
  50. regex : numRe
  51. }, {
  52. token: "constant",
  53. regex: "[a-z0-9-_]+"
  54. }, {
  55. caseInsensitive: true
  56. }],
  57. "media": [{
  58. include : ["strings", "url", "comments"]
  59. }, {
  60. token: "paren.lparen",
  61. regex: "\\{",
  62. next: "start"
  63. }, {
  64. token: "paren.rparen",
  65. regex: "\\}",
  66. next: "start"
  67. }, {
  68. token: "string",
  69. regex: ";",
  70. next: "start"
  71. }, {
  72. token: "keyword",
  73. regex: "(?:media|supports|document|charset|import|namespace|media|supports|document"
  74. + "|page|font|keyframes|viewport|counter-style|font-feature-values"
  75. + "|swash|ornaments|annotation|stylistic|styleset|character-variant)"
  76. }],
  77. "comments" : [{
  78. token: "comment", // multi line comment
  79. regex: "\\/\\*",
  80. push: [{
  81. token : "comment",
  82. regex : "\\*\\/",
  83. next : "pop"
  84. }, {
  85. defaultToken : "comment"
  86. }]
  87. }],
  88. "ruleset" : [{
  89. regex : "-(webkit|ms|moz|o)-",
  90. token : "text"
  91. }, {
  92. token : "punctuation.operator",
  93. regex : "[:;]"
  94. }, {
  95. token : "paren.rparen",
  96. regex : "\\}",
  97. next : "start"
  98. }, {
  99. include : ["strings", "url", "comments"]
  100. }, {
  101. token : ["constant.numeric", "keyword"],
  102. regex : "(" + numRe + ")(ch|cm|deg|em|ex|fr|gd|grad|Hz|in|kHz|mm|ms|pc|pt|px|rad|rem|s|turn|vh|vmax|vmin|vm|vw|%)"
  103. }, {
  104. token : "constant.numeric",
  105. regex : numRe
  106. }, {
  107. token : "constant.numeric", // hex6 color
  108. regex : "#[a-f0-9]{6}"
  109. }, {
  110. token : "constant.numeric", // hex3 color
  111. regex : "#[a-f0-9]{3}"
  112. }, {
  113. token : ["punctuation", "entity.other.attribute-name.pseudo-element.css"],
  114. regex : pseudoElements
  115. }, {
  116. token : ["punctuation", "entity.other.attribute-name.pseudo-class.css"],
  117. regex : pseudoClasses
  118. }, {
  119. include: "url"
  120. }, {
  121. token : keywordMapper,
  122. regex : "\\-?[a-zA-Z_][a-zA-Z0-9_\\-]*"
  123. }, {
  124. caseInsensitive: true
  125. }],
  126. url: [{
  127. token : "support.function",
  128. regex : "(?:url(:?-prefix)?|domain|regexp)\\(",
  129. push: [{
  130. token : "support.function",
  131. regex : "\\)",
  132. next : "pop"
  133. }, {
  134. defaultToken: "string"
  135. }]
  136. }],
  137. strings: [{
  138. token : "string.start",
  139. regex : "'",
  140. push : [{
  141. token : "string.end",
  142. regex : "'|$",
  143. next: "pop"
  144. }, {
  145. include : "escapes"
  146. }, {
  147. token : "constant.language.escape",
  148. regex : /\\$/,
  149. consumeLineEnd: true
  150. }, {
  151. defaultToken: "string"
  152. }]
  153. }, {
  154. token : "string.start",
  155. regex : '"',
  156. push : [{
  157. token : "string.end",
  158. regex : '"|$',
  159. next: "pop"
  160. }, {
  161. include : "escapes"
  162. }, {
  163. token : "constant.language.escape",
  164. regex : /\\$/,
  165. consumeLineEnd: true
  166. }, {
  167. defaultToken: "string"
  168. }]
  169. }],
  170. escapes: [{
  171. token : "constant.language.escape",
  172. regex : /\\([a-fA-F\d]{1,6}|[^a-fA-F\d])/
  173. }]
  174. };
  175. this.normalizeRules();
  176. };
  177. oop.inherits(CssHighlightRules, TextHighlightRules);
  178. exports.CssHighlightRules = CssHighlightRules;
  179. });
  180. ace.define("ace/mode/stylus_highlight_rules",[], function(require, exports, module) {
  181. "use strict";
  182. var oop = require("../lib/oop");
  183. var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
  184. var CssHighlightRules = require("./css_highlight_rules");
  185. var StylusHighlightRules = function() {
  186. var keywordMapper = this.createKeywordMapper({
  187. "support.type": CssHighlightRules.supportType,
  188. "support.function": CssHighlightRules.supportFunction,
  189. "support.constant": CssHighlightRules.supportConstant,
  190. "support.constant.color": CssHighlightRules.supportConstantColor,
  191. "support.constant.fonts": CssHighlightRules.supportConstantFonts
  192. }, "text", true);
  193. this.$rules = {
  194. start: [
  195. {
  196. token : "comment",
  197. regex : /\/\/.*$/
  198. },
  199. {
  200. token : "comment", // multi line comment
  201. regex : /\/\*/,
  202. next : "comment"
  203. },
  204. {
  205. token: ["entity.name.function.stylus", "text"],
  206. regex: "^([-a-zA-Z_][-\\w]*)?(\\()"
  207. },
  208. {
  209. token: ["entity.other.attribute-name.class.stylus"],
  210. regex: "\\.-?[_a-zA-Z]+[_a-zA-Z0-9-]*"
  211. },
  212. {
  213. token: ["entity.language.stylus"],
  214. regex: "^ *&"
  215. },
  216. {
  217. token: ["variable.language.stylus"],
  218. regex: "(arguments)"
  219. },
  220. {
  221. token: ["keyword.stylus"],
  222. regex: "@[-\\w]+"
  223. },
  224. {
  225. token : ["punctuation", "entity.other.attribute-name.pseudo-element.css"],
  226. regex : CssHighlightRules.pseudoElements
  227. }, {
  228. token : ["punctuation", "entity.other.attribute-name.pseudo-class.css"],
  229. regex : CssHighlightRules.pseudoClasses
  230. },
  231. {
  232. token: ["entity.name.tag.stylus"],
  233. 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)"
  234. },
  235. {
  236. token : "constant.numeric", // hex6 color
  237. regex : "#[a-f0-9]{6}"
  238. },
  239. {
  240. token : "constant.numeric", // hex3 color
  241. regex : "#[a-f0-9]{3}"
  242. },
  243. {
  244. token: ["punctuation.definition.entity.stylus", "entity.other.attribute-name.id.stylus"],
  245. regex: "(#)([a-zA-Z][a-zA-Z0-9_-]*)"
  246. },
  247. {
  248. token: "meta.vendor-prefix.stylus",
  249. regex: "-webkit-|-moz\\-|-ms-|-o-"
  250. },
  251. {
  252. token: "keyword.control.stylus",
  253. regex: "(?:!important|for|in|return|true|false|null|if|else|unless|return)\\b"
  254. },
  255. {
  256. token: "keyword.operator.stylus",
  257. regex: "!|~|\\+|-|(?:\\*)?\\*|\\/|%|(?:\\.)\\.\\.|<|>|(?:=|:|\\?|\\+|-|\\*|\\/|%|<|>)?=|!="
  258. },
  259. {
  260. token: "keyword.operator.stylus",
  261. regex: "(?:in|is(?:nt)?|not)\\b"
  262. },
  263. {
  264. token : "string",
  265. regex : "'(?=.)",
  266. next : "qstring"
  267. }, {
  268. token : "string",
  269. regex : '"(?=.)',
  270. next : "qqstring"
  271. },
  272. {
  273. token : "constant.numeric",
  274. regex : CssHighlightRules.numRe
  275. },
  276. {
  277. token : "keyword",
  278. 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"
  279. },
  280. {
  281. token : keywordMapper,
  282. regex : "\\-?[a-zA-Z_][a-zA-Z0-9_\\-]*"
  283. }
  284. ],
  285. "comment" : [
  286. {
  287. token : "comment", // closing comment
  288. regex : "\\*\\/",
  289. next : "start"
  290. }, {
  291. defaultToken : "comment"
  292. }
  293. ],
  294. "qqstring" : [
  295. {
  296. token : "string",
  297. regex : '[^"\\\\]+'
  298. },
  299. {
  300. token : "string",
  301. regex : "\\\\$",
  302. next : "qqstring"
  303. },
  304. {
  305. token : "string",
  306. regex : '"|$',
  307. next : "start"
  308. }
  309. ],
  310. "qstring" : [
  311. {
  312. token : "string",
  313. regex : "[^'\\\\]+"
  314. },
  315. {
  316. token : "string",
  317. regex : "\\\\$",
  318. next : "qstring"
  319. },
  320. {
  321. token : "string",
  322. regex : "'|$",
  323. next : "start"
  324. }
  325. ]
  326. };
  327. };
  328. oop.inherits(StylusHighlightRules, TextHighlightRules);
  329. exports.StylusHighlightRules = StylusHighlightRules;
  330. });
  331. ace.define("ace/mode/folding/coffee",[], function(require, exports, module) {
  332. "use strict";
  333. var oop = require("../../lib/oop");
  334. var BaseFoldMode = require("./fold_mode").FoldMode;
  335. var Range = require("../../range").Range;
  336. var FoldMode = exports.FoldMode = function() {};
  337. oop.inherits(FoldMode, BaseFoldMode);
  338. (function() {
  339. this.getFoldWidgetRange = function(session, foldStyle, row) {
  340. var range = this.indentationBlock(session, row);
  341. if (range)
  342. return range;
  343. var re = /\S/;
  344. var line = session.getLine(row);
  345. var startLevel = line.search(re);
  346. if (startLevel == -1 || line[startLevel] != "#")
  347. return;
  348. var startColumn = line.length;
  349. var maxRow = session.getLength();
  350. var startRow = row;
  351. var endRow = row;
  352. while (++row < maxRow) {
  353. line = session.getLine(row);
  354. var level = line.search(re);
  355. if (level == -1)
  356. continue;
  357. if (line[level] != "#")
  358. break;
  359. endRow = row;
  360. }
  361. if (endRow > startRow) {
  362. var endColumn = session.getLine(endRow).length;
  363. return new Range(startRow, startColumn, endRow, endColumn);
  364. }
  365. };
  366. this.getFoldWidget = function(session, foldStyle, row) {
  367. var line = session.getLine(row);
  368. var indent = line.search(/\S/);
  369. var next = session.getLine(row + 1);
  370. var prev = session.getLine(row - 1);
  371. var prevIndent = prev.search(/\S/);
  372. var nextIndent = next.search(/\S/);
  373. if (indent == -1) {
  374. session.foldWidgets[row - 1] = prevIndent!= -1 && prevIndent < nextIndent ? "start" : "";
  375. return "";
  376. }
  377. if (prevIndent == -1) {
  378. if (indent == nextIndent && line[indent] == "#" && next[indent] == "#") {
  379. session.foldWidgets[row - 1] = "";
  380. session.foldWidgets[row + 1] = "";
  381. return "start";
  382. }
  383. } else if (prevIndent == indent && line[indent] == "#" && prev[indent] == "#") {
  384. if (session.getLine(row - 2).search(/\S/) == -1) {
  385. session.foldWidgets[row - 1] = "start";
  386. session.foldWidgets[row + 1] = "";
  387. return "";
  388. }
  389. }
  390. if (prevIndent!= -1 && prevIndent < indent)
  391. session.foldWidgets[row - 1] = "start";
  392. else
  393. session.foldWidgets[row - 1] = "";
  394. if (indent < nextIndent)
  395. return "start";
  396. else
  397. return "";
  398. };
  399. }).call(FoldMode.prototype);
  400. });
  401. ace.define("ace/mode/stylus",[], function(require, exports, module) {
  402. "use strict";
  403. var oop = require("../lib/oop");
  404. var TextMode = require("./text").Mode;
  405. var StylusHighlightRules = require("./stylus_highlight_rules").StylusHighlightRules;
  406. var FoldMode = require("./folding/coffee").FoldMode;
  407. var Mode = function() {
  408. this.HighlightRules = StylusHighlightRules;
  409. this.foldingRules = new FoldMode();
  410. this.$behaviour = this.$defaultBehaviour;
  411. };
  412. oop.inherits(Mode, TextMode);
  413. (function() {
  414. this.lineCommentStart = "//";
  415. this.blockComment = {start: "/*", end: "*/"};
  416. this.$id = "ace/mode/stylus";
  417. }).call(Mode.prototype);
  418. exports.Mode = Mode;
  419. });
  420. (function() {
  421. ace.require(["ace/mode/stylus"], function(m) {
  422. if (typeof module == "object" && typeof exports == "object" && module) {
  423. module.exports = m;
  424. }
  425. });
  426. })();