mode-fsharp.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. ace.define("ace/mode/fsharp_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 FSharpHighlightRules = function () {
  6. var keywordMapper = this.createKeywordMapper({
  7. "variable": "this",
  8. "keyword": 'abstract|assert|base|begin|class|default|delegate|done|downcast|downto|elif\
  9. |else|exception|extern|false|finally|function|global|inherit|inline|interface|internal|lazy|match\
  10. |member|module|mutable|namespace|open|or|override|private|public|rec|return|return!|select|static\
  11. |struct|then|to|true|try|typeof|upcast|use|use!|val|void|when|while|with|yield|yield!|__SOURCE_DIRECTORY__\
  12. |as|asr|land|lor|lsl|lsr|lxor|mod|sig|atomic|break|checked|component|const|constraint|constructor|continue\
  13. |eager|event|external|fixed|functor|include|method|mixin|object|parallel|process|protected|pure|sealed|tailcall\
  14. |trait|virtual|volatile|and|do|end|for|fun|if|in|let|let!|new|not|null|of|endif',
  15. "constant": "true|false"
  16. }, "identifier");
  17. var floatNumber = "(?:(?:(?:(?:(?:(?:\\d+)?(?:\\.\\d+))|(?:(?:\\d+)\\.))|(?:\\d+))(?:[eE][+-]?\\d+))|(?:(?:(?:\\d+)?(?:\\.\\d+))|(?:(?:\\d+)\\.)))";
  18. this.$rules = {
  19. "start": [
  20. {
  21. token: "variable.classes",
  22. regex: '\\[\\<[.]*\\>\\]'
  23. },
  24. {
  25. token: "comment",
  26. regex: '//.*$'
  27. },
  28. {
  29. token: "comment.start",
  30. regex: /\(\*(?!\))/,
  31. push: "blockComment"
  32. },
  33. {
  34. token: "string",
  35. regex: "'.'"
  36. },
  37. {
  38. token: "string",
  39. regex: '"""',
  40. next : [{
  41. token : "constant.language.escape",
  42. regex : /\\./,
  43. next : "qqstring"
  44. }, {
  45. token : "string",
  46. regex : '"""',
  47. next : "start"
  48. }, {
  49. defaultToken: "string"
  50. }]
  51. },
  52. {
  53. token: "string",
  54. regex: '"',
  55. next : [{
  56. token : "constant.language.escape",
  57. regex : /\\./,
  58. next : "qqstring"
  59. }, {
  60. token : "string",
  61. regex : '"',
  62. next : "start"
  63. }, {
  64. defaultToken: "string"
  65. }]
  66. },
  67. {
  68. token: ["verbatim.string", "string"],
  69. regex: '(@?)(")',
  70. stateName : "qqstring",
  71. next : [{
  72. token : "constant.language.escape",
  73. regex : '""'
  74. }, {
  75. token : "string",
  76. regex : '"',
  77. next : "start"
  78. }, {
  79. defaultToken: "string"
  80. }]
  81. },
  82. {
  83. token: "constant.float",
  84. regex: "(?:" + floatNumber + "|\\d+)[jJ]\\b"
  85. },
  86. {
  87. token: "constant.float",
  88. regex: floatNumber
  89. },
  90. {
  91. token: "constant.integer",
  92. regex: "(?:(?:(?:[1-9]\\d*)|(?:0))|(?:0[oO]?[0-7]+)|(?:0[xX][\\dA-Fa-f]+)|(?:0[bB][01]+))\\b"
  93. },
  94. {
  95. token: ["keyword.type", "variable"],
  96. regex: "(type\\s)([a-zA-Z0-9_$\-]*\\b)"
  97. },
  98. {
  99. token: keywordMapper,
  100. regex: "[a-zA-Z_$][a-zA-Z0-9_$]*\\b"
  101. },
  102. {
  103. token: "keyword.operator",
  104. regex: "\\+\\.|\\-\\.|\\*\\.|\\/\\.|#|;;|\\+|\\-|\\*|\\*\\*\\/|\\/\\/|%|<<|>>|&|\\||\\^|~|<|>|<=|=>|==|!=|<>|<-|=|\\(\\*\\)"
  105. },
  106. {
  107. token: "paren.lparen",
  108. regex: "[[({]"
  109. },
  110. {
  111. token: "paren.rparen",
  112. regex: "[\\])}]"
  113. }
  114. ],
  115. blockComment: [{
  116. regex: /\(\*\)/,
  117. token: "comment"
  118. }, {
  119. regex: /\(\*(?!\))/,
  120. token: "comment.start",
  121. push: "blockComment"
  122. }, {
  123. regex: /\*\)/,
  124. token: "comment.end",
  125. next: "pop"
  126. }, {
  127. defaultToken: "comment"
  128. }]
  129. };
  130. this.normalizeRules();
  131. };
  132. oop.inherits(FSharpHighlightRules, TextHighlightRules);
  133. exports.FSharpHighlightRules = FSharpHighlightRules;
  134. });
  135. ace.define("ace/mode/folding/cstyle",["require","exports","module","ace/lib/oop","ace/range","ace/mode/folding/fold_mode"], function(require, exports, module) {
  136. "use strict";
  137. var oop = require("../../lib/oop");
  138. var Range = require("../../range").Range;
  139. var BaseFoldMode = require("./fold_mode").FoldMode;
  140. var FoldMode = exports.FoldMode = function(commentRegex) {
  141. if (commentRegex) {
  142. this.foldingStartMarker = new RegExp(
  143. this.foldingStartMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.start)
  144. );
  145. this.foldingStopMarker = new RegExp(
  146. this.foldingStopMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.end)
  147. );
  148. }
  149. };
  150. oop.inherits(FoldMode, BaseFoldMode);
  151. (function() {
  152. this.foldingStartMarker = /([\{\[\(])[^\}\]\)]*$|^\s*(\/\*)/;
  153. this.foldingStopMarker = /^[^\[\{\(]*([\}\]\)])|^[\s\*]*(\*\/)/;
  154. this.singleLineBlockCommentRe= /^\s*(\/\*).*\*\/\s*$/;
  155. this.tripleStarBlockCommentRe = /^\s*(\/\*\*\*).*\*\/\s*$/;
  156. this.startRegionRe = /^\s*(\/\*|\/\/)#?region\b/;
  157. this._getFoldWidgetBase = this.getFoldWidget;
  158. this.getFoldWidget = function(session, foldStyle, row) {
  159. var line = session.getLine(row);
  160. if (this.singleLineBlockCommentRe.test(line)) {
  161. if (!this.startRegionRe.test(line) && !this.tripleStarBlockCommentRe.test(line))
  162. return "";
  163. }
  164. var fw = this._getFoldWidgetBase(session, foldStyle, row);
  165. if (!fw && this.startRegionRe.test(line))
  166. return "start"; // lineCommentRegionStart
  167. return fw;
  168. };
  169. this.getFoldWidgetRange = function(session, foldStyle, row, forceMultiline) {
  170. var line = session.getLine(row);
  171. if (this.startRegionRe.test(line))
  172. return this.getCommentRegionBlock(session, line, row);
  173. var match = line.match(this.foldingStartMarker);
  174. if (match) {
  175. var i = match.index;
  176. if (match[1])
  177. return this.openingBracketBlock(session, match[1], row, i);
  178. var range = session.getCommentFoldRange(row, i + match[0].length, 1);
  179. if (range && !range.isMultiLine()) {
  180. if (forceMultiline) {
  181. range = this.getSectionRange(session, row);
  182. } else if (foldStyle != "all")
  183. range = null;
  184. }
  185. return range;
  186. }
  187. if (foldStyle === "markbegin")
  188. return;
  189. var match = line.match(this.foldingStopMarker);
  190. if (match) {
  191. var i = match.index + match[0].length;
  192. if (match[1])
  193. return this.closingBracketBlock(session, match[1], row, i);
  194. return session.getCommentFoldRange(row, i, -1);
  195. }
  196. };
  197. this.getSectionRange = function(session, row) {
  198. var line = session.getLine(row);
  199. var startIndent = line.search(/\S/);
  200. var startRow = row;
  201. var startColumn = line.length;
  202. row = row + 1;
  203. var endRow = row;
  204. var maxRow = session.getLength();
  205. while (++row < maxRow) {
  206. line = session.getLine(row);
  207. var indent = line.search(/\S/);
  208. if (indent === -1)
  209. continue;
  210. if (startIndent > indent)
  211. break;
  212. var subRange = this.getFoldWidgetRange(session, "all", row);
  213. if (subRange) {
  214. if (subRange.start.row <= startRow) {
  215. break;
  216. } else if (subRange.isMultiLine()) {
  217. row = subRange.end.row;
  218. } else if (startIndent == indent) {
  219. break;
  220. }
  221. }
  222. endRow = row;
  223. }
  224. return new Range(startRow, startColumn, endRow, session.getLine(endRow).length);
  225. };
  226. this.getCommentRegionBlock = function(session, line, row) {
  227. var startColumn = line.search(/\s*$/);
  228. var maxRow = session.getLength();
  229. var startRow = row;
  230. var re = /^\s*(?:\/\*|\/\/|--)#?(end)?region\b/;
  231. var depth = 1;
  232. while (++row < maxRow) {
  233. line = session.getLine(row);
  234. var m = re.exec(line);
  235. if (!m) continue;
  236. if (m[1]) depth--;
  237. else depth++;
  238. if (!depth) break;
  239. }
  240. var endRow = row;
  241. if (endRow > startRow) {
  242. return new Range(startRow, startColumn, endRow, line.length);
  243. }
  244. };
  245. }).call(FoldMode.prototype);
  246. });
  247. ace.define("ace/mode/fsharp",["require","exports","module","ace/lib/oop","ace/mode/text","ace/mode/fsharp_highlight_rules","ace/mode/folding/cstyle"], function (require, exports, module) {
  248. "use strict";
  249. var oop = require("../lib/oop");
  250. var TextMode = require("./text").Mode;
  251. var FSharpHighlightRules = require("./fsharp_highlight_rules").FSharpHighlightRules;
  252. var CStyleFoldMode = require("./folding/cstyle").FoldMode;
  253. var Mode = function () {
  254. TextMode.call(this);
  255. this.HighlightRules = FSharpHighlightRules;
  256. this.foldingRules = new CStyleFoldMode();
  257. };
  258. oop.inherits(Mode, TextMode);
  259. (function () {
  260. this.lineCommentStart = "//";
  261. this.blockComment = {start: "(*", end: "*)", nestable: true};
  262. this.$id = "ace/mode/fsharp";
  263. }).call(Mode.prototype);
  264. exports.Mode = Mode;
  265. }); (function() {
  266. ace.require(["ace/mode/fsharp"], function(m) {
  267. if (typeof module == "object" && typeof exports == "object" && module) {
  268. module.exports = m;
  269. }
  270. });
  271. })();