mode-scss-uncompressed.js 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679
  1. /* ***** BEGIN LICENSE BLOCK *****
  2. * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  3. *
  4. * The contents of this file are subject to the Mozilla Public License Version
  5. * 1.1 (the "License"); you may not use this file except in compliance with
  6. * the License. You may obtain a copy of the License at
  7. * http://www.mozilla.org/MPL/
  8. *
  9. * Software distributed under the License is distributed on an "AS IS" basis,
  10. * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  11. * for the specific language governing rights and limitations under the
  12. * License.
  13. *
  14. * The Original Code is Ajax.org Code Editor (ACE).
  15. *
  16. * The Initial Developer of the Original Code is
  17. * Ajax.org B.V.
  18. * Portions created by the Initial Developer are Copyright (C) 2010
  19. * the Initial Developer. All Rights Reserved.
  20. *
  21. * Contributor(s):
  22. * Fabian Jakobs <fabian AT ajax DOT org>
  23. *
  24. * Alternatively, the contents of this file may be used under the terms of
  25. * either the GNU General Public License Version 2 or later (the "GPL"), or
  26. * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  27. * in which case the provisions of the GPL or the LGPL are applicable instead
  28. * of those above. If you wish to allow use of your version of this file only
  29. * under the terms of either the GPL or the LGPL, and not to allow others to
  30. * use your version of this file under the terms of the MPL, indicate your
  31. * decision by deleting the provisions above and replace them with the notice
  32. * and other provisions required by the GPL or the LGPL. If you do not delete
  33. * the provisions above, a recipient may use your version of this file under
  34. * the terms of any one of the MPL, the GPL or the LGPL.
  35. *
  36. * ***** END LICENSE BLOCK ***** */
  37. define('ace/mode/scss', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/text', 'ace/tokenizer', 'ace/mode/scss_highlight_rules', 'ace/mode/matching_brace_outdent', 'ace/mode/folding/cstyle'], function(require, exports, module) {
  38. "use strict";
  39. var oop = require("../lib/oop");
  40. var TextMode = require("./text").Mode;
  41. var Tokenizer = require("../tokenizer").Tokenizer;
  42. var ScssHighlightRules = require("./scss_highlight_rules").ScssHighlightRules;
  43. var MatchingBraceOutdent = require("./matching_brace_outdent").MatchingBraceOutdent;
  44. var CStyleFoldMode = require("./folding/cstyle").FoldMode;
  45. var Mode = function() {
  46. this.$tokenizer = new Tokenizer(new ScssHighlightRules().getRules(), "i");
  47. this.$outdent = new MatchingBraceOutdent();
  48. this.foldingRules = new CStyleFoldMode();
  49. };
  50. oop.inherits(Mode, TextMode);
  51. (function() {
  52. this.getNextLineIndent = function(state, line, tab) {
  53. var indent = this.$getIndent(line);
  54. // ignore braces in comments
  55. var tokens = this.$tokenizer.getLineTokens(line, state).tokens;
  56. if (tokens.length && tokens[tokens.length-1].type == "comment") {
  57. return indent;
  58. }
  59. var match = line.match(/^.*\{\s*$/);
  60. if (match) {
  61. indent += tab;
  62. }
  63. return indent;
  64. };
  65. this.checkOutdent = function(state, line, input) {
  66. return this.$outdent.checkOutdent(line, input);
  67. };
  68. this.autoOutdent = function(state, doc, row) {
  69. this.$outdent.autoOutdent(doc, row);
  70. };
  71. }).call(Mode.prototype);
  72. exports.Mode = Mode;
  73. });
  74. /* ***** BEGIN LICENSE BLOCK *****
  75. * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  76. *
  77. * The contents of this file are subject to the Mozilla Public License Version
  78. * 1.1 (the "License"); you may not use this file except in compliance with
  79. * the License. You may obtain a copy of the License at
  80. * http://www.mozilla.org/MPL/
  81. *
  82. * Software distributed under the License is distributed on an "AS IS" basis,
  83. * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  84. * for the specific language governing rights and limitations under the
  85. * License.
  86. *
  87. * The Original Code is Ajax.org Code Editor (ACE).
  88. *
  89. * The Initial Developer of the Original Code is
  90. * Ajax.org B.V.
  91. * Portions created by the Initial Developer are Copyright (C) 2010
  92. * the Initial Developer. All Rights Reserved.
  93. *
  94. * Contributor(s):
  95. * Fabian Jakobs <fabian AT ajax DOT org>
  96. *
  97. * Alternatively, the contents of this file may be used under the terms of
  98. * either the GNU General Public License Version 2 or later (the "GPL"), or
  99. * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  100. * in which case the provisions of the GPL or the LGPL are applicable instead
  101. * of those above. If you wish to allow use of your version of this file only
  102. * under the terms of either the GPL or the LGPL, and not to allow others to
  103. * use your version of this file under the terms of the MPL, indicate your
  104. * decision by deleting the provisions above and replace them with the notice
  105. * and other provisions required by the GPL or the LGPL. If you do not delete
  106. * the provisions above, a recipient may use your version of this file under
  107. * the terms of any one of the MPL, the GPL or the LGPL.
  108. *
  109. * ***** END LICENSE BLOCK ***** */
  110. define('ace/mode/scss_highlight_rules', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/lib/lang', 'ace/mode/text_highlight_rules'], function(require, exports, module) {
  111. "use strict";
  112. var oop = require("../lib/oop");
  113. var lang = require("../lib/lang");
  114. var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
  115. var ScssHighlightRules = function() {
  116. var properties = lang.arrayToMap( (function () {
  117. var browserPrefix = ("-webkit-|-moz-|-o-|-ms-|-svg-|-pie-|-khtml-").split("|");
  118. var prefixProperties = ("appearance|background-clip|background-inline-policy|background-origin|" +
  119. "background-size|binding|border-bottom-colors|border-left-colors|" +
  120. "border-right-colors|border-top-colors|border-end|border-end-color|" +
  121. "border-end-style|border-end-width|border-image|border-start|" +
  122. "border-start-color|border-start-style|border-start-width|box-align|" +
  123. "box-direction|box-flex|box-flexgroup|box-ordinal-group|box-orient|" +
  124. "box-pack|box-sizing|column-count|column-gap|column-width|column-rule|" +
  125. "column-rule-width|column-rule-style|column-rule-color|float-edge|" +
  126. "font-feature-settings|font-language-override|force-broken-image-icon|" +
  127. "image-region|margin-end|margin-start|opacity|outline|outline-color|" +
  128. "outline-offset|outline-radius|outline-radius-bottomleft|" +
  129. "outline-radius-bottomright|outline-radius-topleft|outline-radius-topright|" +
  130. "outline-style|outline-width|padding-end|padding-start|stack-sizing|" +
  131. "tab-size|text-blink|text-decoration-color|text-decoration-line|" +
  132. "text-decoration-style|transform|transform-origin|transition|" +
  133. "transition-delay|transition-duration|transition-property|" +
  134. "transition-timing-function|user-focus|user-input|user-modify|user-select|" +
  135. "window-shadow|border-radius").split("|");
  136. var properties = ("azimuth|background-attachment|background-color|background-image|" +
  137. "background-position|background-repeat|background|border-bottom-color|" +
  138. "border-bottom-style|border-bottom-width|border-bottom|border-collapse|" +
  139. "border-color|border-left-color|border-left-style|border-left-width|" +
  140. "border-left|border-right-color|border-right-style|border-right-width|" +
  141. "border-right|border-spacing|border-style|border-top-color|" +
  142. "border-top-style|border-top-width|border-top|border-width|border|" +
  143. "bottom|box-sizing|caption-side|clear|clip|color|content|counter-increment|" +
  144. "counter-reset|cue-after|cue-before|cue|cursor|direction|display|" +
  145. "elevation|empty-cells|float|font-family|font-size-adjust|font-size|" +
  146. "font-stretch|font-style|font-variant|font-weight|font|height|left|" +
  147. "letter-spacing|line-height|list-style-image|list-style-position|" +
  148. "list-style-type|list-style|margin-bottom|margin-left|margin-right|" +
  149. "margin-top|marker-offset|margin|marks|max-height|max-width|min-height|" +
  150. "min-width|opacity|orphans|outline-color|" +
  151. "outline-style|outline-width|outline|overflow|overflow-x|overflow-y|padding-bottom|" +
  152. "padding-left|padding-right|padding-top|padding|page-break-after|" +
  153. "page-break-before|page-break-inside|page|pause-after|pause-before|" +
  154. "pause|pitch-range|pitch|play-during|position|quotes|richness|right|" +
  155. "size|speak-header|speak-numeral|speak-punctuation|speech-rate|speak|" +
  156. "stress|table-layout|text-align|text-decoration|text-indent|" +
  157. "text-shadow|text-transform|top|unicode-bidi|vertical-align|" +
  158. "visibility|voice-family|volume|white-space|widows|width|word-spacing|" +
  159. "z-index").split("|");
  160. //The return array
  161. var ret = [];
  162. //All prefixProperties will get the browserPrefix in
  163. //the begning by join the prefixProperties array with the value of browserPrefix
  164. for (var i=0, ln=browserPrefix.length; i<ln; i++) {
  165. Array.prototype.push.apply(
  166. ret,
  167. (( browserPrefix[i] + prefixProperties.join("|" + browserPrefix[i]) ).split("|"))
  168. );
  169. }
  170. //Add also prefixProperties and properties without any browser prefix
  171. Array.prototype.push.apply(ret, prefixProperties);
  172. Array.prototype.push.apply(ret, properties);
  173. return ret;
  174. })() );
  175. var functions = lang.arrayToMap(
  176. ("hsl|hsla|rgb|rgba|url|attr|counter|counters|abs|adjust_color|adjust_hue|" +
  177. "alpha|join|blue|ceil|change_color|comparable|complement|darken|desaturate|" +
  178. "floor|grayscale|green|hue|if|invert|join|length|lighten|lightness|mix|" +
  179. "nth|opacify|opacity|percentage|quote|red|round|saturate|saturation|" +
  180. "scale_color|transparentize|type_of|unit|unitless|unqoute").split("|")
  181. );
  182. var constants = lang.arrayToMap(
  183. ("absolute|all-scroll|always|armenian|auto|baseline|below|bidi-override|" +
  184. "block|bold|bolder|border-box|both|bottom|break-all|break-word|capitalize|center|" +
  185. "char|circle|cjk-ideographic|col-resize|collapse|content-box|crosshair|dashed|" +
  186. "decimal-leading-zero|decimal|default|disabled|disc|" +
  187. "distribute-all-lines|distribute-letter|distribute-space|" +
  188. "distribute|dotted|double|e-resize|ellipsis|fixed|georgian|groove|" +
  189. "hand|hebrew|help|hidden|hiragana-iroha|hiragana|horizontal|" +
  190. "ideograph-alpha|ideograph-numeric|ideograph-parenthesis|" +
  191. "ideograph-space|inactive|inherit|inline-block|inline|inset|inside|" +
  192. "inter-ideograph|inter-word|italic|justify|katakana-iroha|katakana|" +
  193. "keep-all|left|lighter|line-edge|line-through|line|list-item|loose|" +
  194. "lower-alpha|lower-greek|lower-latin|lower-roman|lowercase|lr-tb|ltr|" +
  195. "medium|middle|move|n-resize|ne-resize|newspaper|no-drop|no-repeat|" +
  196. "nw-resize|none|normal|not-allowed|nowrap|oblique|outset|outside|" +
  197. "overline|pointer|progress|relative|repeat-x|repeat-y|repeat|right|" +
  198. "ridge|row-resize|rtl|s-resize|scroll|se-resize|separate|small-caps|" +
  199. "solid|square|static|strict|super|sw-resize|table-footer-group|" +
  200. "table-header-group|tb-rl|text-bottom|text-top|text|thick|thin|top|" +
  201. "transparent|underline|upper-alpha|upper-latin|upper-roman|uppercase|" +
  202. "vertical-ideographic|vertical-text|visible|w-resize|wait|whitespace|" +
  203. "zero").split("|")
  204. );
  205. var colors = lang.arrayToMap(
  206. ("aqua|black|blue|fuchsia|gray|green|lime|maroon|navy|olive|orange|" +
  207. "purple|red|silver|teal|white|yellow").split("|")
  208. );
  209. var keywords = lang.arrayToMap(
  210. ("@mixin|@extend|@include|@import|@media|@debug|@warn|@if|@for|@each|@while|@else|@font-face|@-webkit-keyframes|if|and|!default|module|def|end|declare").split("|")
  211. )
  212. var tags = lang.arrayToMap(
  213. ("a|abbr|acronym|address|applet|area|article|aside|audio|b|base|basefont|bdo|" +
  214. "big|blockquote|body|br|button|canvas|caption|center|cite|code|col|colgroup|" +
  215. "command|datalist|dd|del|details|dfn|dir|div|dl|dt|em|embed|fieldset|" +
  216. "figcaption|figure|font|footer|form|frame|frameset|h1|h2|h3|h4|h5|h6|head|" +
  217. "header|hgroup|hr|html|i|iframe|img|input|ins|keygen|kbd|label|legend|li|" +
  218. "link|map|mark|menu|meta|meter|nav|noframes|noscript|object|ol|optgroup|" +
  219. "option|output|p|param|pre|progress|q|rp|rt|ruby|s|samp|script|section|select|" +
  220. "small|source|span|strike|strong|style|sub|summary|sup|table|tbody|td|" +
  221. "textarea|tfoot|th|thead|time|title|tr|tt|u|ul|var|video|wbr|xmp").split("|")
  222. );
  223. // regexp must not have capturing parentheses. Use (?:) instead.
  224. // regexps are ordered -> the first match is used
  225. var numRe = "\\-?(?:(?:[0-9]+)|(?:[0-9]*\\.[0-9]+))";
  226. // regexp must not have capturing parentheses. Use (?:) instead.
  227. // regexps are ordered -> the first match is used
  228. this.$rules = {
  229. "start" : [
  230. {
  231. token : "comment",
  232. regex : "\\/\\/.*$"
  233. },
  234. {
  235. token : "comment", // multi line comment
  236. merge : true,
  237. regex : "\\/\\*",
  238. next : "comment"
  239. }, {
  240. token : "string", // single line
  241. regex : '["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]'
  242. }, {
  243. token : "string", // multi line string start
  244. merge : true,
  245. regex : '["].*\\\\$',
  246. next : "qqstring"
  247. }, {
  248. token : "string", // single line
  249. regex : "['](?:(?:\\\\.)|(?:[^'\\\\]))*?[']"
  250. }, {
  251. token : "string", // multi line string start
  252. merge : true,
  253. regex : "['].*\\\\$",
  254. next : "qstring"
  255. }, {
  256. token : "constant.numeric",
  257. regex : numRe + "(?:em|ex|px|cm|mm|in|pt|pc|deg|rad|grad|ms|s|hz|khz|%)"
  258. }, {
  259. token : "constant.numeric", // hex6 color
  260. regex : "#[a-f0-9]{6}"
  261. }, {
  262. token : "constant.numeric", // hex3 color
  263. regex : "#[a-f0-9]{3}"
  264. }, {
  265. token : "constant.numeric",
  266. regex : numRe
  267. }, {
  268. token : function(value) {
  269. if (properties.hasOwnProperty(value.toLowerCase()))
  270. return "support.type";
  271. if (keywords.hasOwnProperty(value))
  272. return "keyword";
  273. else if (constants.hasOwnProperty(value))
  274. return "constant.language";
  275. else if (functions.hasOwnProperty(value))
  276. return "support.function";
  277. else if (colors.hasOwnProperty(value.toLowerCase()))
  278. return "support.constant.color";
  279. else if (tags.hasOwnProperty(value.toLowerCase()))
  280. return "variable.language";
  281. else
  282. return "text";
  283. },
  284. regex : "\\-?[@a-z_][@a-z0-9_\\-]*"
  285. }, {
  286. token : "variable",
  287. regex : "[a-z_\\-$][a-z0-9_\\-$]*\\b"
  288. }, {
  289. token: "variable.language",
  290. regex: "#[a-z0-9-_]+"
  291. }, {
  292. token: "variable.language",
  293. regex: "\\.[a-z0-9-_]+"
  294. }, {
  295. token: "variable.language",
  296. regex: ":[a-z0-9-_]+"
  297. }, {
  298. token: "constant",
  299. regex: "[a-z0-9-_]+"
  300. }, {
  301. token : "keyword.operator",
  302. regex : "<|>|<=|>=|==|!=|-|%|#|\\+|\\$|\\+|\\*"
  303. }, {
  304. token : "paren.lparen",
  305. regex : "[[({]"
  306. }, {
  307. token : "paren.rparen",
  308. regex : "[\\])}]"
  309. }, {
  310. token : "text",
  311. regex : "\\s+"
  312. }
  313. ],
  314. "comment" : [
  315. {
  316. token : "comment", // closing comment
  317. regex : ".*?\\*\\/",
  318. next : "start"
  319. }, {
  320. token : "comment", // comment spanning whole line
  321. merge : true,
  322. regex : ".+"
  323. }
  324. ],
  325. "qqstring" : [
  326. {
  327. token : "string",
  328. regex : '(?:(?:\\\\.)|(?:[^"\\\\]))*?"',
  329. next : "start"
  330. }, {
  331. token : "string",
  332. merge : true,
  333. regex : '.+'
  334. }
  335. ],
  336. "qstring" : [
  337. {
  338. token : "string",
  339. regex : "(?:(?:\\\\.)|(?:[^'\\\\]))*?'",
  340. next : "start"
  341. }, {
  342. token : "string",
  343. merge : true,
  344. regex : '.+'
  345. }
  346. ]
  347. };
  348. };
  349. oop.inherits(ScssHighlightRules, TextHighlightRules);
  350. exports.ScssHighlightRules = ScssHighlightRules;
  351. });
  352. /* ***** BEGIN LICENSE BLOCK *****
  353. * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  354. *
  355. * The contents of this file are subject to the Mozilla Public License Version
  356. * 1.1 (the "License"); you may not use this file except in compliance with
  357. * the License. You may obtain a copy of the License at
  358. * http://www.mozilla.org/MPL/
  359. *
  360. * Software distributed under the License is distributed on an "AS IS" basis,
  361. * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  362. * for the specific language governing rights and limitations under the
  363. * License.
  364. *
  365. * The Original Code is Ajax.org Code Editor (ACE).
  366. *
  367. * The Initial Developer of the Original Code is
  368. * Ajax.org B.V.
  369. * Portions created by the Initial Developer are Copyright (C) 2010
  370. * the Initial Developer. All Rights Reserved.
  371. *
  372. * Contributor(s):
  373. * Fabian Jakobs <fabian AT ajax DOT org>
  374. *
  375. * Alternatively, the contents of this file may be used under the terms of
  376. * either the GNU General Public License Version 2 or later (the "GPL"), or
  377. * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  378. * in which case the provisions of the GPL or the LGPL are applicable instead
  379. * of those above. If you wish to allow use of your version of this file only
  380. * under the terms of either the GPL or the LGPL, and not to allow others to
  381. * use your version of this file under the terms of the MPL, indicate your
  382. * decision by deleting the provisions above and replace them with the notice
  383. * and other provisions required by the GPL or the LGPL. If you do not delete
  384. * the provisions above, a recipient may use your version of this file under
  385. * the terms of any one of the MPL, the GPL or the LGPL.
  386. *
  387. * ***** END LICENSE BLOCK ***** */
  388. define('ace/mode/matching_brace_outdent', ['require', 'exports', 'module' , 'ace/range'], function(require, exports, module) {
  389. "use strict";
  390. var Range = require("../range").Range;
  391. var MatchingBraceOutdent = function() {};
  392. (function() {
  393. this.checkOutdent = function(line, input) {
  394. if (! /^\s+$/.test(line))
  395. return false;
  396. return /^\s*\}/.test(input);
  397. };
  398. this.autoOutdent = function(doc, row) {
  399. var line = doc.getLine(row);
  400. var match = line.match(/^(\s*\})/);
  401. if (!match) return 0;
  402. var column = match[1].length;
  403. var openBracePos = doc.findMatchingBracket({row: row, column: column});
  404. if (!openBracePos || openBracePos.row == row) return 0;
  405. var indent = this.$getIndent(doc.getLine(openBracePos.row));
  406. doc.replace(new Range(row, 0, row, column-1), indent);
  407. };
  408. this.$getIndent = function(line) {
  409. var match = line.match(/^(\s+)/);
  410. if (match) {
  411. return match[1];
  412. }
  413. return "";
  414. };
  415. }).call(MatchingBraceOutdent.prototype);
  416. exports.MatchingBraceOutdent = MatchingBraceOutdent;
  417. });
  418. /* ***** BEGIN LICENSE BLOCK *****
  419. * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  420. *
  421. * The contents of this file are subject to the Mozilla Public License Version
  422. * 1.1 (the "License"); you may not use this file except in compliance with
  423. * the License. You may obtain a copy of the License at
  424. * http://www.mozilla.org/MPL/
  425. *
  426. * Software distributed under the License is distributed on an "AS IS" basis,
  427. * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  428. * for the specific language governing rights and limitations under the
  429. * License.
  430. *
  431. * The Original Code is Ajax.org Code Editor (ACE).
  432. *
  433. * The Initial Developer of the Original Code is
  434. * Ajax.org B.V.
  435. * Portions created by the Initial Developer are Copyright (C) 2010
  436. * the Initial Developer. All Rights Reserved.
  437. *
  438. * Contributor(s):
  439. * Fabian Jakobs <fabian AT ajax DOT org>
  440. *
  441. * Alternatively, the contents of this file may be used under the terms of
  442. * either the GNU General Public License Version 2 or later (the "GPL"), or
  443. * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  444. * in which case the provisions of the GPL or the LGPL are applicable instead
  445. * of those above. If you wish to allow use of your version of this file only
  446. * under the terms of either the GPL or the LGPL, and not to allow others to
  447. * use your version of this file under the terms of the MPL, indicate your
  448. * decision by deleting the provisions above and replace them with the notice
  449. * and other provisions required by the GPL or the LGPL. If you do not delete
  450. * the provisions above, a recipient may use your version of this file under
  451. * the terms of any one of the MPL, the GPL or the LGPL.
  452. *
  453. * ***** END LICENSE BLOCK ***** */
  454. define('ace/mode/folding/cstyle', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/range', 'ace/mode/folding/fold_mode'], function(require, exports, module) {
  455. "use strict";
  456. var oop = require("../../lib/oop");
  457. var Range = require("../../range").Range;
  458. var BaseFoldMode = require("./fold_mode").FoldMode;
  459. var FoldMode = exports.FoldMode = function() {};
  460. oop.inherits(FoldMode, BaseFoldMode);
  461. (function() {
  462. this.foldingStartMarker = /(\{|\[)[^\}\]]*$|^\s*(\/\*)/;
  463. this.foldingStopMarker = /^[^\[\{]*(\}|\])|^[\s\*]*(\*\/)/;
  464. this.getFoldWidgetRange = function(session, foldStyle, row) {
  465. var line = session.getLine(row);
  466. var match = line.match(this.foldingStartMarker);
  467. if (match) {
  468. var i = match.index;
  469. if (match[1])
  470. return this.openingBracketBlock(session, match[1], row, i);
  471. var range = session.getCommentFoldRange(row, i + match[0].length);
  472. range.end.column -= 2;
  473. return range;
  474. }
  475. if (foldStyle !== "markbeginend")
  476. return;
  477. var match = line.match(this.foldingStopMarker);
  478. if (match) {
  479. var i = match.index + match[0].length;
  480. if (match[2]) {
  481. var range = session.getCommentFoldRange(row, i);
  482. range.end.column -= 2;
  483. return range;
  484. }
  485. var end = {row: row, column: i};
  486. var start = session.$findOpeningBracket(match[1], end);
  487. if (!start)
  488. return;
  489. start.column++;
  490. end.column--;
  491. return Range.fromPoints(start, end);
  492. }
  493. };
  494. }).call(FoldMode.prototype);
  495. });/* ***** BEGIN LICENSE BLOCK *****
  496. * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  497. *
  498. * The contents of this file are subject to the Mozilla Public License Version
  499. * 1.1 (the "License"); you may not use this file except in compliance with
  500. * the License. You may obtain a copy of the License at
  501. * http://www.mozilla.org/MPL/
  502. *
  503. * Software distributed under the License is distributed on an "AS IS" basis,
  504. * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  505. * for the specific language governing rights and limitations under the
  506. * License.
  507. *
  508. * The Original Code is Ajax.org Code Editor (ACE).
  509. *
  510. * The Initial Developer of the Original Code is
  511. * Ajax.org B.V.
  512. * Portions created by the Initial Developer are Copyright (C) 2010
  513. * the Initial Developer. All Rights Reserved.
  514. *
  515. * Contributor(s):
  516. * Fabian Jakobs <fabian AT ajax DOT org>
  517. *
  518. * Alternatively, the contents of this file may be used under the terms of
  519. * either the GNU General Public License Version 2 or later (the "GPL"), or
  520. * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  521. * in which case the provisions of the GPL or the LGPL are applicable instead
  522. * of those above. If you wish to allow use of your version of this file only
  523. * under the terms of either the GPL or the LGPL, and not to allow others to
  524. * use your version of this file under the terms of the MPL, indicate your
  525. * decision by deleting the provisions above and replace them with the notice
  526. * and other provisions required by the GPL or the LGPL. If you do not delete
  527. * the provisions above, a recipient may use your version of this file under
  528. * the terms of any one of the MPL, the GPL or the LGPL.
  529. *
  530. * ***** END LICENSE BLOCK ***** */
  531. define('ace/mode/folding/fold_mode', ['require', 'exports', 'module' , 'ace/range'], function(require, exports, module) {
  532. "use strict";
  533. var Range = require("../../range").Range;
  534. var FoldMode = exports.FoldMode = function() {};
  535. (function() {
  536. this.foldingStartMarker = null;
  537. this.foldingStopMarker = null;
  538. // must return "" if there's no fold, to enable caching
  539. this.getFoldWidget = function(session, foldStyle, row) {
  540. var line = session.getLine(row);
  541. if (this.foldingStartMarker.test(line))
  542. return "start";
  543. if (foldStyle == "markbeginend"
  544. && this.foldingStopMarker
  545. && this.foldingStopMarker.test(line))
  546. return "end";
  547. return "";
  548. };
  549. this.getFoldWidgetRange = function(session, foldStyle, row) {
  550. return null;
  551. };
  552. this.indentationBlock = function(session, row, column) {
  553. var re = /^\s*/;
  554. var startRow = row;
  555. var endRow = row;
  556. var line = session.getLine(row);
  557. var startColumn = column || line.length;
  558. var startLevel = line.match(re)[0].length;
  559. var maxRow = session.getLength()
  560. while (++row < maxRow) {
  561. line = session.getLine(row);
  562. var level = line.match(re)[0].length;
  563. if (level == line.length)
  564. continue;
  565. if (level <= startLevel)
  566. break;
  567. endRow = row;
  568. }
  569. if (endRow > startRow) {
  570. var endColumn = session.getLine(endRow).length;
  571. return new Range(startRow, startColumn, endRow, endColumn);
  572. }
  573. };
  574. this.openingBracketBlock = function(session, bracket, row, column) {
  575. var start = {row: row, column: column + 1};
  576. var end = session.$findClosingBracket(bracket, start);
  577. if (!end)
  578. return;
  579. var fw = session.foldWidgets[end.row];
  580. if (fw == null)
  581. fw = this.getFoldWidget(session, end.row);
  582. if (fw == "start") {
  583. end.row --;
  584. end.column = session.getLine(end.row).length;
  585. }
  586. return Range.fromPoints(start, end);
  587. };
  588. }).call(FoldMode.prototype);
  589. });