mode-haxe.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386
  1. ace.define("ace/mode/doc_comment_highlight_rules",[], function(require, exports, module) {
  2. "use strict";
  3. var oop = require("../lib/oop");
  4. var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
  5. var DocCommentHighlightRules = function() {
  6. this.$rules = {
  7. "start" : [ {
  8. token : "comment.doc.tag",
  9. regex : "@[\\w\\d_]+" // TODO: fix email addresses
  10. },
  11. DocCommentHighlightRules.getTagRule(),
  12. {
  13. defaultToken : "comment.doc",
  14. caseInsensitive: true
  15. }]
  16. };
  17. };
  18. oop.inherits(DocCommentHighlightRules, TextHighlightRules);
  19. DocCommentHighlightRules.getTagRule = function(start) {
  20. return {
  21. token : "comment.doc.tag.storage.type",
  22. regex : "\\b(?:TODO|FIXME|XXX|HACK)\\b"
  23. };
  24. };
  25. DocCommentHighlightRules.getStartRule = function(start) {
  26. return {
  27. token : "comment.doc", // doc comment
  28. regex : "\\/\\*(?=\\*)",
  29. next : start
  30. };
  31. };
  32. DocCommentHighlightRules.getEndRule = function (start) {
  33. return {
  34. token : "comment.doc", // closing comment
  35. regex : "\\*\\/",
  36. next : start
  37. };
  38. };
  39. exports.DocCommentHighlightRules = DocCommentHighlightRules;
  40. });
  41. ace.define("ace/mode/haxe_highlight_rules",[], function(require, exports, module) {
  42. "use strict";
  43. var oop = require("../lib/oop");
  44. var DocCommentHighlightRules = require("./doc_comment_highlight_rules").DocCommentHighlightRules;
  45. var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
  46. var HaxeHighlightRules = function() {
  47. var keywords = (
  48. "break|case|cast|catch|class|continue|default|else|enum|extends|for|function|if|implements|import|in|inline|interface|new|override|package|private|public|return|static|super|switch|this|throw|trace|try|typedef|untyped|var|while|Array|Void|Bool|Int|UInt|Float|Dynamic|String|List|Hash|IntHash|Error|Unknown|Type|Std"
  49. );
  50. var buildinConstants = (
  51. "null|true|false"
  52. );
  53. var keywordMapper = this.createKeywordMapper({
  54. "variable.language": "this",
  55. "keyword": keywords,
  56. "constant.language": buildinConstants
  57. }, "identifier");
  58. this.$rules = {
  59. "start" : [
  60. {
  61. token : "comment",
  62. regex : "\\/\\/.*$"
  63. },
  64. DocCommentHighlightRules.getStartRule("doc-start"),
  65. {
  66. token : "comment", // multi line comment
  67. regex : "\\/\\*",
  68. next : "comment"
  69. }, {
  70. token : "string.regexp",
  71. regex : "[/](?:(?:\\[(?:\\\\]|[^\\]])+\\])|(?:\\\\/|[^\\]/]))*[/]\\w*\\s*(?=[).,;]|$)"
  72. }, {
  73. token : "string", // single line
  74. regex : '["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]'
  75. }, {
  76. token : "string", // single line
  77. regex : "['](?:(?:\\\\.)|(?:[^'\\\\]))*?[']"
  78. }, {
  79. token : "constant.numeric", // hex
  80. regex : "0[xX][0-9a-fA-F]+\\b"
  81. }, {
  82. token : "constant.numeric", // float
  83. regex : "[+-]?\\d+(?:(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)?\\b"
  84. }, {
  85. token : "constant.language.boolean",
  86. regex : "(?:true|false)\\b"
  87. }, {
  88. token : keywordMapper,
  89. regex : "[a-zA-Z_$][a-zA-Z0-9_$]*\\b"
  90. }, {
  91. token : "keyword.operator",
  92. regex : "!|\\$|%|&|\\*|\\-\\-|\\-|\\+\\+|\\+|~|===|==|=|!=|!==|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\\|\\||\\?\\:|\\*=|%=|\\+=|\\-=|&=|\\^=|\\b(?:in|instanceof|new|delete|typeof|void)"
  93. }, {
  94. token : "punctuation.operator",
  95. regex : "\\?|\\:|\\,|\\;|\\."
  96. }, {
  97. token : "paren.lparen",
  98. regex : "[[({<]"
  99. }, {
  100. token : "paren.rparen",
  101. regex : "[\\])}>]"
  102. }, {
  103. token : "text",
  104. regex : "\\s+"
  105. }
  106. ],
  107. "comment" : [
  108. {
  109. token : "comment", // closing comment
  110. regex : "\\*\\/",
  111. next : "start"
  112. }, {
  113. defaultToken : "comment"
  114. }
  115. ]
  116. };
  117. this.embedRules(DocCommentHighlightRules, "doc-",
  118. [ DocCommentHighlightRules.getEndRule("start") ]);
  119. };
  120. oop.inherits(HaxeHighlightRules, TextHighlightRules);
  121. exports.HaxeHighlightRules = HaxeHighlightRules;
  122. });
  123. ace.define("ace/mode/matching_brace_outdent",[], function(require, exports, module) {
  124. "use strict";
  125. var Range = require("../range").Range;
  126. var MatchingBraceOutdent = function() {};
  127. (function() {
  128. this.checkOutdent = function(line, input) {
  129. if (! /^\s+$/.test(line))
  130. return false;
  131. return /^\s*\}/.test(input);
  132. };
  133. this.autoOutdent = function(doc, row) {
  134. var line = doc.getLine(row);
  135. var match = line.match(/^(\s*\})/);
  136. if (!match) return 0;
  137. var column = match[1].length;
  138. var openBracePos = doc.findMatchingBracket({row: row, column: column});
  139. if (!openBracePos || openBracePos.row == row) return 0;
  140. var indent = this.$getIndent(doc.getLine(openBracePos.row));
  141. doc.replace(new Range(row, 0, row, column-1), indent);
  142. };
  143. this.$getIndent = function(line) {
  144. return line.match(/^\s*/)[0];
  145. };
  146. }).call(MatchingBraceOutdent.prototype);
  147. exports.MatchingBraceOutdent = MatchingBraceOutdent;
  148. });
  149. ace.define("ace/mode/folding/cstyle",[], function(require, exports, module) {
  150. "use strict";
  151. var oop = require("../../lib/oop");
  152. var Range = require("../../range").Range;
  153. var BaseFoldMode = require("./fold_mode").FoldMode;
  154. var FoldMode = exports.FoldMode = function(commentRegex) {
  155. if (commentRegex) {
  156. this.foldingStartMarker = new RegExp(
  157. this.foldingStartMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.start)
  158. );
  159. this.foldingStopMarker = new RegExp(
  160. this.foldingStopMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.end)
  161. );
  162. }
  163. };
  164. oop.inherits(FoldMode, BaseFoldMode);
  165. (function() {
  166. this.foldingStartMarker = /([\{\[\(])[^\}\]\)]*$|^\s*(\/\*)/;
  167. this.foldingStopMarker = /^[^\[\{\(]*([\}\]\)])|^[\s\*]*(\*\/)/;
  168. this.singleLineBlockCommentRe= /^\s*(\/\*).*\*\/\s*$/;
  169. this.tripleStarBlockCommentRe = /^\s*(\/\*\*\*).*\*\/\s*$/;
  170. this.startRegionRe = /^\s*(\/\*|\/\/)#?region\b/;
  171. this._getFoldWidgetBase = this.getFoldWidget;
  172. this.getFoldWidget = function(session, foldStyle, row) {
  173. var line = session.getLine(row);
  174. if (this.singleLineBlockCommentRe.test(line)) {
  175. if (!this.startRegionRe.test(line) && !this.tripleStarBlockCommentRe.test(line))
  176. return "";
  177. }
  178. var fw = this._getFoldWidgetBase(session, foldStyle, row);
  179. if (!fw && this.startRegionRe.test(line))
  180. return "start"; // lineCommentRegionStart
  181. return fw;
  182. };
  183. this.getFoldWidgetRange = function(session, foldStyle, row, forceMultiline) {
  184. var line = session.getLine(row);
  185. if (this.startRegionRe.test(line))
  186. return this.getCommentRegionBlock(session, line, row);
  187. var match = line.match(this.foldingStartMarker);
  188. if (match) {
  189. var i = match.index;
  190. if (match[1])
  191. return this.openingBracketBlock(session, match[1], row, i);
  192. var range = session.getCommentFoldRange(row, i + match[0].length, 1);
  193. if (range && !range.isMultiLine()) {
  194. if (forceMultiline) {
  195. range = this.getSectionRange(session, row);
  196. } else if (foldStyle != "all")
  197. range = null;
  198. }
  199. return range;
  200. }
  201. if (foldStyle === "markbegin")
  202. return;
  203. var match = line.match(this.foldingStopMarker);
  204. if (match) {
  205. var i = match.index + match[0].length;
  206. if (match[1])
  207. return this.closingBracketBlock(session, match[1], row, i);
  208. return session.getCommentFoldRange(row, i, -1);
  209. }
  210. };
  211. this.getSectionRange = function(session, row) {
  212. var line = session.getLine(row);
  213. var startIndent = line.search(/\S/);
  214. var startRow = row;
  215. var startColumn = line.length;
  216. row = row + 1;
  217. var endRow = row;
  218. var maxRow = session.getLength();
  219. while (++row < maxRow) {
  220. line = session.getLine(row);
  221. var indent = line.search(/\S/);
  222. if (indent === -1)
  223. continue;
  224. if (startIndent > indent)
  225. break;
  226. var subRange = this.getFoldWidgetRange(session, "all", row);
  227. if (subRange) {
  228. if (subRange.start.row <= startRow) {
  229. break;
  230. } else if (subRange.isMultiLine()) {
  231. row = subRange.end.row;
  232. } else if (startIndent == indent) {
  233. break;
  234. }
  235. }
  236. endRow = row;
  237. }
  238. return new Range(startRow, startColumn, endRow, session.getLine(endRow).length);
  239. };
  240. this.getCommentRegionBlock = function(session, line, row) {
  241. var startColumn = line.search(/\s*$/);
  242. var maxRow = session.getLength();
  243. var startRow = row;
  244. var re = /^\s*(?:\/\*|\/\/|--)#?(end)?region\b/;
  245. var depth = 1;
  246. while (++row < maxRow) {
  247. line = session.getLine(row);
  248. var m = re.exec(line);
  249. if (!m) continue;
  250. if (m[1]) depth--;
  251. else depth++;
  252. if (!depth) break;
  253. }
  254. var endRow = row;
  255. if (endRow > startRow) {
  256. return new Range(startRow, startColumn, endRow, line.length);
  257. }
  258. };
  259. }).call(FoldMode.prototype);
  260. });
  261. ace.define("ace/mode/haxe",[], function(require, exports, module) {
  262. "use strict";
  263. var oop = require("../lib/oop");
  264. var TextMode = require("./text").Mode;
  265. var HaxeHighlightRules = require("./haxe_highlight_rules").HaxeHighlightRules;
  266. var MatchingBraceOutdent = require("./matching_brace_outdent").MatchingBraceOutdent;
  267. var CstyleBehaviour = require("./behaviour/cstyle").CstyleBehaviour;
  268. var CStyleFoldMode = require("./folding/cstyle").FoldMode;
  269. var Mode = function() {
  270. this.HighlightRules = HaxeHighlightRules;
  271. this.$outdent = new MatchingBraceOutdent();
  272. this.$behaviour = new CstyleBehaviour();
  273. this.foldingRules = new CStyleFoldMode();
  274. };
  275. oop.inherits(Mode, TextMode);
  276. (function() {
  277. this.lineCommentStart = "//";
  278. this.blockComment = {start: "/*", end: "*/"};
  279. this.getNextLineIndent = function(state, line, tab) {
  280. var indent = this.$getIndent(line);
  281. var tokenizedLine = this.getTokenizer().getLineTokens(line, state);
  282. var tokens = tokenizedLine.tokens;
  283. if (tokens.length && tokens[tokens.length-1].type == "comment") {
  284. return indent;
  285. }
  286. if (state == "start") {
  287. var match = line.match(/^.*[\{\(\[]\s*$/);
  288. if (match) {
  289. indent += tab;
  290. }
  291. }
  292. return indent;
  293. };
  294. this.checkOutdent = function(state, line, input) {
  295. return this.$outdent.checkOutdent(line, input);
  296. };
  297. this.autoOutdent = function(state, doc, row) {
  298. this.$outdent.autoOutdent(doc, row);
  299. };
  300. this.$id = "ace/mode/haxe";
  301. }).call(Mode.prototype);
  302. exports.Mode = Mode;
  303. });
  304. (function() {
  305. ace.require(["ace/mode/haxe"], function(m) {
  306. if (typeof module == "object" && typeof exports == "object" && module) {
  307. module.exports = m;
  308. }
  309. });
  310. })();