mode-elm.js 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. ace.define("ace/mode/elm_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 ElmHighlightRules = function() {
  6. var keywordMapper = this.createKeywordMapper({
  7. "keyword": "as|case|class|data|default|deriving|do|else|export|foreign|" +
  8. "hiding|jsevent|if|import|in|infix|infixl|infixr|instance|let|" +
  9. "module|newtype|of|open|then|type|where|_|port|\u03BB"
  10. }, "identifier");
  11. var escapeRe = /\\(\d+|['"\\&trnbvf])/;
  12. var smallRe = /[a-z_]/.source;
  13. var largeRe = /[A-Z]/.source;
  14. var idRe = /[a-z_A-Z0-9']/.source;
  15. this.$rules = {
  16. start: [{
  17. token: "string.start",
  18. regex: '"',
  19. next: "string"
  20. }, {
  21. token: "string.character",
  22. regex: "'(?:" + escapeRe.source + "|.)'?"
  23. }, {
  24. regex: /0(?:[xX][0-9A-Fa-f]+|[oO][0-7]+)|\d+(\.\d+)?([eE][-+]?\d*)?/,
  25. token: "constant.numeric"
  26. }, {
  27. token: "comment",
  28. regex: "--.*"
  29. }, {
  30. token : "keyword",
  31. regex : /\.\.|\||:|=|\\|"|->|<-|\u2192/
  32. }, {
  33. token : "keyword.operator",
  34. regex : /[-!#$%&*+.\/<=>?@\\^|~:\u03BB\u2192]+/
  35. }, {
  36. token : "operator.punctuation",
  37. regex : /[,;`]/
  38. }, {
  39. regex : largeRe + idRe + "+\\.?",
  40. token : function(value) {
  41. if (value[value.length - 1] == ".")
  42. return "entity.name.function";
  43. return "constant.language";
  44. }
  45. }, {
  46. regex : "^" + smallRe + idRe + "+",
  47. token : function(value) {
  48. return "constant.language";
  49. }
  50. }, {
  51. token : keywordMapper,
  52. regex : "[\\w\\xff-\\u218e\\u2455-\\uffff]+\\b"
  53. }, {
  54. regex: "{-#?",
  55. token: "comment.start",
  56. onMatch: function(value, currentState, stack) {
  57. this.next = value.length == 2 ? "blockComment" : "docComment";
  58. return this.token;
  59. }
  60. }, {
  61. token: "variable.language",
  62. regex: /\[markdown\|/,
  63. next: "markdown"
  64. }, {
  65. token: "paren.lparen",
  66. regex: /[\[({]/
  67. }, {
  68. token: "paren.rparen",
  69. regex: /[\])}]/
  70. } ],
  71. markdown: [{
  72. regex: /\|\]/,
  73. next: "start"
  74. }, {
  75. defaultToken : "string"
  76. }],
  77. blockComment: [{
  78. regex: "{-",
  79. token: "comment.start",
  80. push: "blockComment"
  81. }, {
  82. regex: "-}",
  83. token: "comment.end",
  84. next: "pop"
  85. }, {
  86. defaultToken: "comment"
  87. }],
  88. docComment: [{
  89. regex: "{-",
  90. token: "comment.start",
  91. push: "docComment"
  92. }, {
  93. regex: "-}",
  94. token: "comment.end",
  95. next: "pop"
  96. }, {
  97. defaultToken: "doc.comment"
  98. }],
  99. string: [{
  100. token: "constant.language.escape",
  101. regex: escapeRe
  102. }, {
  103. token: "text",
  104. regex: /\\(\s|$)/,
  105. next: "stringGap"
  106. }, {
  107. token: "string.end",
  108. regex: '"',
  109. next: "start"
  110. }, {
  111. defaultToken: "string"
  112. }],
  113. stringGap: [{
  114. token: "text",
  115. regex: /\\/,
  116. next: "string"
  117. }, {
  118. token: "error",
  119. regex: "",
  120. next: "start"
  121. }]
  122. };
  123. this.normalizeRules();
  124. };
  125. oop.inherits(ElmHighlightRules, TextHighlightRules);
  126. exports.ElmHighlightRules = ElmHighlightRules;
  127. });
  128. ace.define("ace/mode/folding/cstyle",["require","exports","module","ace/lib/oop","ace/range","ace/mode/folding/fold_mode"], function(require, exports, module) {
  129. "use strict";
  130. var oop = require("../../lib/oop");
  131. var Range = require("../../range").Range;
  132. var BaseFoldMode = require("./fold_mode").FoldMode;
  133. var FoldMode = exports.FoldMode = function(commentRegex) {
  134. if (commentRegex) {
  135. this.foldingStartMarker = new RegExp(
  136. this.foldingStartMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.start)
  137. );
  138. this.foldingStopMarker = new RegExp(
  139. this.foldingStopMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.end)
  140. );
  141. }
  142. };
  143. oop.inherits(FoldMode, BaseFoldMode);
  144. (function() {
  145. this.foldingStartMarker = /(\{|\[)[^\}\]]*$|^\s*(\/\*)/;
  146. this.foldingStopMarker = /^[^\[\{]*(\}|\])|^[\s\*]*(\*\/)/;
  147. this.singleLineBlockCommentRe= /^\s*(\/\*).*\*\/\s*$/;
  148. this.tripleStarBlockCommentRe = /^\s*(\/\*\*\*).*\*\/\s*$/;
  149. this.startRegionRe = /^\s*(\/\*|\/\/)#?region\b/;
  150. this._getFoldWidgetBase = this.getFoldWidget;
  151. this.getFoldWidget = function(session, foldStyle, row) {
  152. var line = session.getLine(row);
  153. if (this.singleLineBlockCommentRe.test(line)) {
  154. if (!this.startRegionRe.test(line) && !this.tripleStarBlockCommentRe.test(line))
  155. return "";
  156. }
  157. var fw = this._getFoldWidgetBase(session, foldStyle, row);
  158. if (!fw && this.startRegionRe.test(line))
  159. return "start"; // lineCommentRegionStart
  160. return fw;
  161. };
  162. this.getFoldWidgetRange = function(session, foldStyle, row, forceMultiline) {
  163. var line = session.getLine(row);
  164. if (this.startRegionRe.test(line))
  165. return this.getCommentRegionBlock(session, line, row);
  166. var match = line.match(this.foldingStartMarker);
  167. if (match) {
  168. var i = match.index;
  169. if (match[1])
  170. return this.openingBracketBlock(session, match[1], row, i);
  171. var range = session.getCommentFoldRange(row, i + match[0].length, 1);
  172. if (range && !range.isMultiLine()) {
  173. if (forceMultiline) {
  174. range = this.getSectionRange(session, row);
  175. } else if (foldStyle != "all")
  176. range = null;
  177. }
  178. return range;
  179. }
  180. if (foldStyle === "markbegin")
  181. return;
  182. var match = line.match(this.foldingStopMarker);
  183. if (match) {
  184. var i = match.index + match[0].length;
  185. if (match[1])
  186. return this.closingBracketBlock(session, match[1], row, i);
  187. return session.getCommentFoldRange(row, i, -1);
  188. }
  189. };
  190. this.getSectionRange = function(session, row) {
  191. var line = session.getLine(row);
  192. var startIndent = line.search(/\S/);
  193. var startRow = row;
  194. var startColumn = line.length;
  195. row = row + 1;
  196. var endRow = row;
  197. var maxRow = session.getLength();
  198. while (++row < maxRow) {
  199. line = session.getLine(row);
  200. var indent = line.search(/\S/);
  201. if (indent === -1)
  202. continue;
  203. if (startIndent > indent)
  204. break;
  205. var subRange = this.getFoldWidgetRange(session, "all", row);
  206. if (subRange) {
  207. if (subRange.start.row <= startRow) {
  208. break;
  209. } else if (subRange.isMultiLine()) {
  210. row = subRange.end.row;
  211. } else if (startIndent == indent) {
  212. break;
  213. }
  214. }
  215. endRow = row;
  216. }
  217. return new Range(startRow, startColumn, endRow, session.getLine(endRow).length);
  218. };
  219. this.getCommentRegionBlock = function(session, line, row) {
  220. var startColumn = line.search(/\s*$/);
  221. var maxRow = session.getLength();
  222. var startRow = row;
  223. var re = /^\s*(?:\/\*|\/\/|--)#?(end)?region\b/;
  224. var depth = 1;
  225. while (++row < maxRow) {
  226. line = session.getLine(row);
  227. var m = re.exec(line);
  228. if (!m) continue;
  229. if (m[1]) depth--;
  230. else depth++;
  231. if (!depth) break;
  232. }
  233. var endRow = row;
  234. if (endRow > startRow) {
  235. return new Range(startRow, startColumn, endRow, line.length);
  236. }
  237. };
  238. }).call(FoldMode.prototype);
  239. });
  240. ace.define("ace/mode/elm",["require","exports","module","ace/lib/oop","ace/mode/text","ace/mode/elm_highlight_rules","ace/mode/folding/cstyle"], function(require, exports, module) {
  241. "use strict";
  242. var oop = require("../lib/oop");
  243. var TextMode = require("./text").Mode;
  244. var HighlightRules = require("./elm_highlight_rules").ElmHighlightRules;
  245. var FoldMode = require("./folding/cstyle").FoldMode;
  246. var Mode = function() {
  247. this.HighlightRules = HighlightRules;
  248. this.foldingRules = new FoldMode();
  249. this.$behaviour = this.$defaultBehaviour;
  250. };
  251. oop.inherits(Mode, TextMode);
  252. (function() {
  253. this.lineCommentStart = "--";
  254. this.blockComment = {start: "{-", end: "-}", nestable: true};
  255. this.$id = "ace/mode/elm";
  256. }).call(Mode.prototype);
  257. exports.Mode = Mode;
  258. });