mode-haxe.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  1. ace.define("ace/mode/doc_comment_highlight_rules",["require","exports","module","ace/lib/oop","ace/mode/text_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",["require","exports","module","ace/lib/oop","ace/mode/doc_comment_highlight_rules","ace/mode/text_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. token : "comment", // comment spanning whole line
  114. regex : ".+"
  115. }
  116. ]
  117. };
  118. this.embedRules(DocCommentHighlightRules, "doc-",
  119. [ DocCommentHighlightRules.getEndRule("start") ]);
  120. };
  121. oop.inherits(HaxeHighlightRules, TextHighlightRules);
  122. exports.HaxeHighlightRules = HaxeHighlightRules;
  123. });
  124. ace.define("ace/mode/matching_brace_outdent",["require","exports","module","ace/range"], function(require, exports, module) {
  125. "use strict";
  126. var Range = require("../range").Range;
  127. var MatchingBraceOutdent = function() {};
  128. (function() {
  129. this.checkOutdent = function(line, input) {
  130. if (! /^\s+$/.test(line))
  131. return false;
  132. return /^\s*\}/.test(input);
  133. };
  134. this.autoOutdent = function(doc, row) {
  135. var line = doc.getLine(row);
  136. var match = line.match(/^(\s*\})/);
  137. if (!match) return 0;
  138. var column = match[1].length;
  139. var openBracePos = doc.findMatchingBracket({row: row, column: column});
  140. if (!openBracePos || openBracePos.row == row) return 0;
  141. var indent = this.$getIndent(doc.getLine(openBracePos.row));
  142. doc.replace(new Range(row, 0, row, column-1), indent);
  143. };
  144. this.$getIndent = function(line) {
  145. return line.match(/^\s*/)[0];
  146. };
  147. }).call(MatchingBraceOutdent.prototype);
  148. exports.MatchingBraceOutdent = MatchingBraceOutdent;
  149. });
  150. ace.define("ace/mode/folding/cstyle",["require","exports","module","ace/lib/oop","ace/range","ace/mode/folding/fold_mode"], function(require, exports, module) {
  151. "use strict";
  152. var oop = require("../../lib/oop");
  153. var Range = require("../../range").Range;
  154. var BaseFoldMode = require("./fold_mode").FoldMode;
  155. var FoldMode = exports.FoldMode = function(commentRegex) {
  156. if (commentRegex) {
  157. this.foldingStartMarker = new RegExp(
  158. this.foldingStartMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.start)
  159. );
  160. this.foldingStopMarker = new RegExp(
  161. this.foldingStopMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.end)
  162. );
  163. }
  164. };
  165. oop.inherits(FoldMode, BaseFoldMode);
  166. (function() {
  167. this.foldingStartMarker = /(\{|\[)[^\}\]]*$|^\s*(\/\*)/;
  168. this.foldingStopMarker = /^[^\[\{]*(\}|\])|^[\s\*]*(\*\/)/;
  169. this.singleLineBlockCommentRe= /^\s*(\/\*).*\*\/\s*$/;
  170. this.tripleStarBlockCommentRe = /^\s*(\/\*\*\*).*\*\/\s*$/;
  171. this.startRegionRe = /^\s*(\/\*|\/\/)#?region\b/;
  172. this._getFoldWidgetBase = this.getFoldWidget;
  173. this.getFoldWidget = function(session, foldStyle, row) {
  174. var line = session.getLine(row);
  175. if (this.singleLineBlockCommentRe.test(line)) {
  176. if (!this.startRegionRe.test(line) && !this.tripleStarBlockCommentRe.test(line))
  177. return "";
  178. }
  179. var fw = this._getFoldWidgetBase(session, foldStyle, row);
  180. if (!fw && this.startRegionRe.test(line))
  181. return "start"; // lineCommentRegionStart
  182. return fw;
  183. };
  184. this.getFoldWidgetRange = function(session, foldStyle, row, forceMultiline) {
  185. var line = session.getLine(row);
  186. if (this.startRegionRe.test(line))
  187. return this.getCommentRegionBlock(session, line, row);
  188. var match = line.match(this.foldingStartMarker);
  189. if (match) {
  190. var i = match.index;
  191. if (match[1])
  192. return this.openingBracketBlock(session, match[1], row, i);
  193. var range = session.getCommentFoldRange(row, i + match[0].length, 1);
  194. if (range && !range.isMultiLine()) {
  195. if (forceMultiline) {
  196. range = this.getSectionRange(session, row);
  197. } else if (foldStyle != "all")
  198. range = null;
  199. }
  200. return range;
  201. }
  202. if (foldStyle === "markbegin")
  203. return;
  204. var match = line.match(this.foldingStopMarker);
  205. if (match) {
  206. var i = match.index + match[0].length;
  207. if (match[1])
  208. return this.closingBracketBlock(session, match[1], row, i);
  209. return session.getCommentFoldRange(row, i, -1);
  210. }
  211. };
  212. this.getSectionRange = function(session, row) {
  213. var line = session.getLine(row);
  214. var startIndent = line.search(/\S/);
  215. var startRow = row;
  216. var startColumn = line.length;
  217. row = row + 1;
  218. var endRow = row;
  219. var maxRow = session.getLength();
  220. while (++row < maxRow) {
  221. line = session.getLine(row);
  222. var indent = line.search(/\S/);
  223. if (indent === -1)
  224. continue;
  225. if (startIndent > indent)
  226. break;
  227. var subRange = this.getFoldWidgetRange(session, "all", row);
  228. if (subRange) {
  229. if (subRange.start.row <= startRow) {
  230. break;
  231. } else if (subRange.isMultiLine()) {
  232. row = subRange.end.row;
  233. } else if (startIndent == indent) {
  234. break;
  235. }
  236. }
  237. endRow = row;
  238. }
  239. return new Range(startRow, startColumn, endRow, session.getLine(endRow).length);
  240. };
  241. this.getCommentRegionBlock = function(session, line, row) {
  242. var startColumn = line.search(/\s*$/);
  243. var maxRow = session.getLength();
  244. var startRow = row;
  245. var re = /^\s*(?:\/\*|\/\/|--)#?(end)?region\b/;
  246. var depth = 1;
  247. while (++row < maxRow) {
  248. line = session.getLine(row);
  249. var m = re.exec(line);
  250. if (!m) continue;
  251. if (m[1]) depth--;
  252. else depth++;
  253. if (!depth) break;
  254. }
  255. var endRow = row;
  256. if (endRow > startRow) {
  257. return new Range(startRow, startColumn, endRow, line.length);
  258. }
  259. };
  260. }).call(FoldMode.prototype);
  261. });
  262. ace.define("ace/mode/haxe",["require","exports","module","ace/lib/oop","ace/mode/text","ace/mode/haxe_highlight_rules","ace/mode/matching_brace_outdent","ace/mode/behaviour/cstyle","ace/mode/folding/cstyle"], function(require, exports, module) {
  263. "use strict";
  264. var oop = require("../lib/oop");
  265. var TextMode = require("./text").Mode;
  266. var HaxeHighlightRules = require("./haxe_highlight_rules").HaxeHighlightRules;
  267. var MatchingBraceOutdent = require("./matching_brace_outdent").MatchingBraceOutdent;
  268. var CstyleBehaviour = require("./behaviour/cstyle").CstyleBehaviour;
  269. var CStyleFoldMode = require("./folding/cstyle").FoldMode;
  270. var Mode = function() {
  271. this.HighlightRules = HaxeHighlightRules;
  272. this.$outdent = new MatchingBraceOutdent();
  273. this.$behaviour = new CstyleBehaviour();
  274. this.foldingRules = new CStyleFoldMode();
  275. };
  276. oop.inherits(Mode, TextMode);
  277. (function() {
  278. this.lineCommentStart = "//";
  279. this.blockComment = {start: "/*", end: "*/"};
  280. this.getNextLineIndent = function(state, line, tab) {
  281. var indent = this.$getIndent(line);
  282. var tokenizedLine = this.getTokenizer().getLineTokens(line, state);
  283. var tokens = tokenizedLine.tokens;
  284. if (tokens.length && tokens[tokens.length-1].type == "comment") {
  285. return indent;
  286. }
  287. if (state == "start") {
  288. var match = line.match(/^.*[\{\(\[]\s*$/);
  289. if (match) {
  290. indent += tab;
  291. }
  292. }
  293. return indent;
  294. };
  295. this.checkOutdent = function(state, line, input) {
  296. return this.$outdent.checkOutdent(line, input);
  297. };
  298. this.autoOutdent = function(state, doc, row) {
  299. this.$outdent.autoOutdent(doc, row);
  300. };
  301. this.$id = "ace/mode/haxe";
  302. }).call(Mode.prototype);
  303. exports.Mode = Mode;
  304. });