You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

mode-less.js 20KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510
  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. * John Roepke <john AT justjohn DOT us>
  24. *
  25. * Alternatively, the contents of this file may be used under the terms of
  26. * either the GNU General Public License Version 2 or later (the "GPL"), or
  27. * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  28. * in which case the provisions of the GPL or the LGPL are applicable instead
  29. * of those above. If you wish to allow use of your version of this file only
  30. * under the terms of either the GPL or the LGPL, and not to allow others to
  31. * use your version of this file under the terms of the MPL, indicate your
  32. * decision by deleting the provisions above and replace them with the notice
  33. * and other provisions required by the GPL or the LGPL. If you do not delete
  34. * the provisions above, a recipient may use your version of this file under
  35. * the terms of any one of the MPL, the GPL or the LGPL.
  36. *
  37. * ***** END LICENSE BLOCK ***** */
  38. ace.define('ace/mode/less', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/text', 'ace/tokenizer', 'ace/mode/less_highlight_rules', 'ace/mode/matching_brace_outdent', 'ace/mode/folding/cstyle'], function(require, exports, module) {
  39. var oop = require("../lib/oop");
  40. var TextMode = require("./text").Mode;
  41. var Tokenizer = require("../tokenizer").Tokenizer;
  42. var LessHighlightRules = require("./less_highlight_rules").LessHighlightRules;
  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 LessHighlightRules().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. ace.define('ace/mode/less_highlight_rules', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/lib/lang', 'ace/mode/text_highlight_rules'], function(require, exports, module) {
  75. var oop = require("../lib/oop");
  76. var lang = require("../lib/lang");
  77. var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
  78. var LessHighlightRules = function() {
  79. var properties = lang.arrayToMap( (function () {
  80. var browserPrefix = ("-webkit-|-moz-|-o-|-ms-|-svg-|-pie-|-khtml-").split("|");
  81. var prefixProperties = ("appearance|background-clip|background-inline-policy|background-origin|" +
  82. "background-size|binding|border-bottom-colors|border-left-colors|" +
  83. "border-right-colors|border-top-colors|border-end|border-end-color|" +
  84. "border-end-style|border-end-width|border-image|border-start|" +
  85. "border-start-color|border-start-style|border-start-width|box-align|" +
  86. "box-direction|box-flex|box-flexgroup|box-ordinal-group|box-orient|" +
  87. "box-pack|box-sizing|column-count|column-gap|column-width|column-rule|" +
  88. "column-rule-width|column-rule-style|column-rule-color|float-edge|" +
  89. "font-feature-settings|font-language-override|force-broken-image-icon|" +
  90. "image-region|margin-end|margin-start|opacity|outline|outline-color|" +
  91. "outline-offset|outline-radius|outline-radius-bottomleft|" +
  92. "outline-radius-bottomright|outline-radius-topleft|outline-radius-topright|" +
  93. "outline-style|outline-width|padding-end|padding-start|stack-sizing|" +
  94. "tab-size|text-blink|text-decoration-color|text-decoration-line|" +
  95. "text-decoration-style|transform|transform-origin|transition|" +
  96. "transition-delay|transition-duration|transition-property|" +
  97. "transition-timing-function|user-focus|user-input|user-modify|user-select|" +
  98. "window-shadow|border-radius").split("|");
  99. var properties = ("azimuth|background-attachment|background-color|background-image|" +
  100. "background-position|background-repeat|background|border-bottom-color|" +
  101. "border-bottom-style|border-bottom-width|border-bottom|border-collapse|" +
  102. "border-color|border-left-color|border-left-style|border-left-width|" +
  103. "border-left|border-right-color|border-right-style|border-right-width|" +
  104. "border-right|border-spacing|border-style|border-top-color|" +
  105. "border-top-style|border-top-width|border-top|border-width|border|" +
  106. "bottom|box-sizing|caption-side|clear|clip|color|content|counter-increment|" +
  107. "counter-reset|cue-after|cue-before|cue|cursor|direction|display|" +
  108. "elevation|empty-cells|float|font-family|font-size-adjust|font-size|" +
  109. "font-stretch|font-style|font-variant|font-weight|font|height|left|" +
  110. "letter-spacing|line-height|list-style-image|list-style-position|" +
  111. "list-style-type|list-style|margin-bottom|margin-left|margin-right|" +
  112. "margin-top|marker-offset|margin|marks|max-height|max-width|min-height|" +
  113. "min-width|opacity|orphans|outline-color|" +
  114. "outline-style|outline-width|outline|overflow|overflow-x|overflow-y|padding-bottom|" +
  115. "padding-left|padding-right|padding-top|padding|page-break-after|" +
  116. "page-break-before|page-break-inside|page|pause-after|pause-before|" +
  117. "pause|pitch-range|pitch|play-during|position|quotes|richness|right|" +
  118. "size|speak-header|speak-numeral|speak-punctuation|speech-rate|speak|" +
  119. "stress|table-layout|text-align|text-decoration|text-indent|" +
  120. "text-shadow|text-transform|top|unicode-bidi|vertical-align|" +
  121. "visibility|voice-family|volume|white-space|widows|width|word-spacing|" +
  122. "z-index").split("|");
  123. //The return array
  124. var ret = [];
  125. //All prefixProperties will get the browserPrefix in
  126. //the begning by join the prefixProperties array with the value of browserPrefix
  127. for (var i=0, ln=browserPrefix.length; i<ln; i++) {
  128. Array.prototype.push.apply(
  129. ret,
  130. (( browserPrefix[i] + prefixProperties.join("|" + browserPrefix[i]) ).split("|"))
  131. );
  132. }
  133. //Add also prefixProperties and properties without any browser prefix
  134. Array.prototype.push.apply(ret, prefixProperties);
  135. Array.prototype.push.apply(ret, properties);
  136. return ret;
  137. })() );
  138. var functions = lang.arrayToMap(
  139. ("hsl|hsla|rgb|rgba|url|attr|counter|counters|lighten|darken|saturate|" +
  140. "desaturate|fadein|fadeout|fade|spin|mix|hue|saturation|lightness|" +
  141. "alpha|round|ceil|floor|percentage|color|iscolor|isnumber|isstring|" +
  142. "iskeyword|isurl|ispixel|ispercentage|isem").split("|")
  143. );
  144. var constants = lang.arrayToMap(
  145. ("absolute|all-scroll|always|armenian|auto|baseline|below|bidi-override|" +
  146. "block|bold|bolder|border-box|both|bottom|break-all|break-word|capitalize|center|" +
  147. "char|circle|cjk-ideographic|col-resize|collapse|content-box|crosshair|dashed|" +
  148. "decimal-leading-zero|decimal|default|disabled|disc|" +
  149. "distribute-all-lines|distribute-letter|distribute-space|" +
  150. "distribute|dotted|double|e-resize|ellipsis|fixed|georgian|groove|" +
  151. "hand|hebrew|help|hidden|hiragana-iroha|hiragana|horizontal|" +
  152. "ideograph-alpha|ideograph-numeric|ideograph-parenthesis|" +
  153. "ideograph-space|inactive|inherit|inline-block|inline|inset|inside|" +
  154. "inter-ideograph|inter-word|italic|justify|katakana-iroha|katakana|" +
  155. "keep-all|left|lighter|line-edge|line-through|line|list-item|loose|" +
  156. "lower-alpha|lower-greek|lower-latin|lower-roman|lowercase|lr-tb|ltr|" +
  157. "medium|middle|move|n-resize|ne-resize|newspaper|no-drop|no-repeat|" +
  158. "nw-resize|none|normal|not-allowed|nowrap|oblique|outset|outside|" +
  159. "overline|pointer|progress|relative|repeat-x|repeat-y|repeat|right|" +
  160. "ridge|row-resize|rtl|s-resize|scroll|se-resize|separate|small-caps|" +
  161. "solid|square|static|strict|super|sw-resize|table-footer-group|" +
  162. "table-header-group|tb-rl|text-bottom|text-top|text|thick|thin|top|" +
  163. "transparent|underline|upper-alpha|upper-latin|upper-roman|uppercase|" +
  164. "vertical-ideographic|vertical-text|visible|w-resize|wait|whitespace|" +
  165. "zero").split("|")
  166. );
  167. var colors = lang.arrayToMap(
  168. ("aqua|black|blue|fuchsia|gray|green|lime|maroon|navy|olive|orange|" +
  169. "purple|red|silver|teal|white|yellow").split("|")
  170. );
  171. var keywords = lang.arrayToMap(
  172. ("@mixin|@extend|@include|@import|@media|@debug|@warn|@if|@for|@each|" +
  173. "@while|@else|@font-face|@-webkit-keyframes|if|and|!default|module|" +
  174. "def|end|declare|when|not|and").split("|")
  175. );
  176. var tags = lang.arrayToMap(
  177. ("a|abbr|acronym|address|applet|area|article|aside|audio|b|base|basefont|bdo|" +
  178. "big|blockquote|body|br|button|canvas|caption|center|cite|code|col|colgroup|" +
  179. "command|datalist|dd|del|details|dfn|dir|div|dl|dt|em|embed|fieldset|" +
  180. "figcaption|figure|font|footer|form|frame|frameset|h1|h2|h3|h4|h5|h6|head|" +
  181. "header|hgroup|hr|html|i|iframe|img|input|ins|keygen|kbd|label|legend|li|" +
  182. "link|map|mark|menu|meta|meter|nav|noframes|noscript|object|ol|optgroup|" +
  183. "option|output|p|param|pre|progress|q|rp|rt|ruby|s|samp|script|section|select|" +
  184. "small|source|span|strike|strong|style|sub|summary|sup|table|tbody|td|" +
  185. "textarea|tfoot|th|thead|time|title|tr|tt|u|ul|var|video|wbr|xmp").split("|")
  186. );
  187. // regexp must not have capturing parentheses. Use (?:) instead.
  188. // regexps are ordered -> the first match is used
  189. var numRe = "\\-?(?:(?:[0-9]+)|(?:[0-9]*\\.[0-9]+))";
  190. // regexp must not have capturing parentheses. Use (?:) instead.
  191. // regexps are ordered -> the first match is used
  192. this.$rules = {
  193. "start" : [
  194. {
  195. token : "comment",
  196. regex : "\\/\\/.*$"
  197. },
  198. {
  199. token : "comment", // multi line comment
  200. merge : true,
  201. regex : "\\/\\*",
  202. next : "comment"
  203. }, {
  204. token : "string", // single line
  205. regex : '["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]'
  206. }, {
  207. token : "string", // single line
  208. regex : "['](?:(?:\\\\.)|(?:[^'\\\\]))*?[']"
  209. }, {
  210. token : "constant.numeric",
  211. regex : numRe + "(?:em|ex|px|cm|mm|in|pt|pc|deg|rad|grad|ms|s|hz|khz|%)"
  212. }, {
  213. token : "constant.numeric", // hex6 color
  214. regex : "#[a-f0-9]{6}"
  215. }, {
  216. token : "constant.numeric", // hex3 color
  217. regex : "#[a-f0-9]{3}"
  218. }, {
  219. token : "constant.numeric",
  220. regex : numRe
  221. }, {
  222. token : function(value) {
  223. if (keywords.hasOwnProperty(value))
  224. return "keyword";
  225. else
  226. return "variable";
  227. },
  228. regex : "@[a-z0-9_\\-@]*\\b"
  229. }, {
  230. token : function(value) {
  231. if (properties.hasOwnProperty(value.toLowerCase()))
  232. return "support.type";
  233. else if (keywords.hasOwnProperty(value))
  234. return "keyword";
  235. else if (constants.hasOwnProperty(value))
  236. return "constant.language";
  237. else if (functions.hasOwnProperty(value))
  238. return "support.function";
  239. else if (colors.hasOwnProperty(value.toLowerCase()))
  240. return "support.constant.color";
  241. else if (tags.hasOwnProperty(value.toLowerCase()))
  242. return "variable.language";
  243. else
  244. return "text";
  245. },
  246. regex : "\\-?[@a-z_][@a-z0-9_\\-]*"
  247. }, {
  248. token: "variable.language",
  249. regex: "#[a-z0-9-_]+"
  250. }, {
  251. token: "variable.language",
  252. regex: "\\.[a-z0-9-_]+"
  253. }, {
  254. token: "variable.language",
  255. regex: ":[a-z0-9-_]+"
  256. }, {
  257. token: "constant",
  258. regex: "[a-z0-9-_]+"
  259. }, {
  260. token : "keyword.operator",
  261. regex : "<|>|<=|>=|==|!=|-|%|#|\\+|\\$|\\+|\\*"
  262. }, {
  263. token : "paren.lparen",
  264. regex : "[[({]"
  265. }, {
  266. token : "paren.rparen",
  267. regex : "[\\])}]"
  268. }, {
  269. token : "text",
  270. regex : "\\s+"
  271. }
  272. ],
  273. "comment" : [
  274. {
  275. token : "comment", // closing comment
  276. regex : ".*?\\*\\/",
  277. next : "start"
  278. }, {
  279. token : "comment", // comment spanning whole line
  280. merge : true,
  281. regex : ".+"
  282. }
  283. ]
  284. };
  285. };
  286. oop.inherits(LessHighlightRules, TextHighlightRules);
  287. exports.LessHighlightRules = LessHighlightRules;
  288. });
  289. ace.define('ace/mode/matching_brace_outdent', ['require', 'exports', 'module' , 'ace/range'], function(require, exports, module) {
  290. var Range = require("../range").Range;
  291. var MatchingBraceOutdent = function() {};
  292. (function() {
  293. this.checkOutdent = function(line, input) {
  294. if (! /^\s+$/.test(line))
  295. return false;
  296. return /^\s*\}/.test(input);
  297. };
  298. this.autoOutdent = function(doc, row) {
  299. var line = doc.getLine(row);
  300. var match = line.match(/^(\s*\})/);
  301. if (!match) return 0;
  302. var column = match[1].length;
  303. var openBracePos = doc.findMatchingBracket({row: row, column: column});
  304. if (!openBracePos || openBracePos.row == row) return 0;
  305. var indent = this.$getIndent(doc.getLine(openBracePos.row));
  306. doc.replace(new Range(row, 0, row, column-1), indent);
  307. };
  308. this.$getIndent = function(line) {
  309. var match = line.match(/^(\s+)/);
  310. if (match) {
  311. return match[1];
  312. }
  313. return "";
  314. };
  315. }).call(MatchingBraceOutdent.prototype);
  316. exports.MatchingBraceOutdent = MatchingBraceOutdent;
  317. });
  318. ace.define('ace/mode/folding/cstyle', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/range', 'ace/mode/folding/fold_mode'], function(require, exports, module) {
  319. var oop = require("../../lib/oop");
  320. var Range = require("../../range").Range;
  321. var BaseFoldMode = require("./fold_mode").FoldMode;
  322. var FoldMode = exports.FoldMode = function() {};
  323. oop.inherits(FoldMode, BaseFoldMode);
  324. (function() {
  325. this.foldingStartMarker = /(\{|\[)[^\}\]]*$|^\s*(\/\*)/;
  326. this.foldingStopMarker = /^[^\[\{]*(\}|\])|^[\s\*]*(\*\/)/;
  327. this.getFoldWidgetRange = function(session, foldStyle, row) {
  328. var line = session.getLine(row);
  329. var match = line.match(this.foldingStartMarker);
  330. if (match) {
  331. var i = match.index;
  332. if (match[1])
  333. return this.openingBracketBlock(session, match[1], row, i);
  334. var range = session.getCommentFoldRange(row, i + match[0].length);
  335. range.end.column -= 2;
  336. return range;
  337. }
  338. if (foldStyle !== "markbeginend")
  339. return;
  340. var match = line.match(this.foldingStopMarker);
  341. if (match) {
  342. var i = match.index + match[0].length;
  343. if (match[2]) {
  344. var range = session.getCommentFoldRange(row, i);
  345. range.end.column -= 2;
  346. return range;
  347. }
  348. var end = {row: row, column: i};
  349. var start = session.$findOpeningBracket(match[1], end);
  350. if (!start)
  351. return;
  352. start.column++;
  353. end.column--;
  354. return Range.fromPoints(start, end);
  355. }
  356. };
  357. }).call(FoldMode.prototype);
  358. });
  359. ace.define('ace/mode/folding/fold_mode', ['require', 'exports', 'module' , 'ace/range'], function(require, exports, module) {
  360. var Range = require("../../range").Range;
  361. var FoldMode = exports.FoldMode = function() {};
  362. (function() {
  363. this.foldingStartMarker = null;
  364. this.foldingStopMarker = null;
  365. // must return "" if there's no fold, to enable caching
  366. this.getFoldWidget = function(session, foldStyle, row) {
  367. var line = session.getLine(row);
  368. if (this.foldingStartMarker.test(line))
  369. return "start";
  370. if (foldStyle == "markbeginend"
  371. && this.foldingStopMarker
  372. && this.foldingStopMarker.test(line))
  373. return "end";
  374. return "";
  375. };
  376. this.getFoldWidgetRange = function(session, foldStyle, row) {
  377. return null;
  378. };
  379. this.indentationBlock = function(session, row, column) {
  380. var re = /^\s*/;
  381. var startRow = row;
  382. var endRow = row;
  383. var line = session.getLine(row);
  384. var startColumn = column || line.length;
  385. var startLevel = line.match(re)[0].length;
  386. var maxRow = session.getLength()
  387. while (++row < maxRow) {
  388. line = session.getLine(row);
  389. var level = line.match(re)[0].length;
  390. if (level == line.length)
  391. continue;
  392. if (level <= startLevel)
  393. break;
  394. endRow = row;
  395. }
  396. if (endRow > startRow) {
  397. var endColumn = session.getLine(endRow).length;
  398. return new Range(startRow, startColumn, endRow, endColumn);
  399. }
  400. };
  401. this.openingBracketBlock = function(session, bracket, row, column, typeRe, allowBlankLine) {
  402. var start = {row: row, column: column + 1};
  403. var end = session.$findClosingBracket(bracket, start, typeRe, allowBlankLine);
  404. if (!end)
  405. return;
  406. var fw = session.foldWidgets[end.row];
  407. if (fw == null)
  408. fw = this.getFoldWidget(session, end.row);
  409. if (fw == "start") {
  410. end.row --;
  411. end.column = session.getLine(end.row).length;
  412. }
  413. return Range.fromPoints(start, end);
  414. };
  415. }).call(FoldMode.prototype);
  416. });