mode-haskell_cabal.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. ace.define("ace/mode/haskell_cabal_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 CabalHighlightRules = function() {
  6. this.$rules = {
  7. "start" : [
  8. {
  9. token : "comment",
  10. regex : "^\\s*--.*$"
  11. }, {
  12. token: ["keyword"],
  13. regex: /^(\s*\w.*?)(:(?:\s+|$))/
  14. }, {
  15. token : "constant.numeric", // float
  16. regex : /[\d_]+(?:(?:[\.\d_]*)?)/
  17. }, {
  18. token : "constant.language.boolean",
  19. regex : "(?:true|false|TRUE|FALSE|True|False|yes|no)\\b"
  20. }, {
  21. token : "markup.heading",
  22. regex : /^(\w.*)$/
  23. }
  24. ]};
  25. };
  26. oop.inherits(CabalHighlightRules, TextHighlightRules);
  27. exports.CabalHighlightRules = CabalHighlightRules;
  28. });
  29. ace.define("ace/mode/folding/haskell_cabal",["require","exports","module","ace/lib/oop","ace/mode/folding/fold_mode","ace/range"], function(require, exports, module) {
  30. "use strict";
  31. var oop = require("../../lib/oop");
  32. var BaseFoldMode = require("./fold_mode").FoldMode;
  33. var Range = require("../../range").Range;
  34. var FoldMode = exports.FoldMode = function() {};
  35. oop.inherits(FoldMode, BaseFoldMode);
  36. (function() {
  37. this.isHeading = function (session,row) {
  38. var heading = "markup.heading";
  39. var token = session.getTokens(row)[0];
  40. return row==0 || (token && token.type.lastIndexOf(heading, 0) === 0);
  41. };
  42. this.getFoldWidget = function(session, foldStyle, row) {
  43. if (this.isHeading(session,row)){
  44. return "start";
  45. } else if (foldStyle === "markbeginend" && !(/^\s*$/.test(session.getLine(row)))){
  46. var maxRow = session.getLength();
  47. while (++row < maxRow) {
  48. if (!(/^\s*$/.test(session.getLine(row)))){
  49. break;
  50. }
  51. }
  52. if (row==maxRow || this.isHeading(session,row)){
  53. return "end";
  54. }
  55. }
  56. return "";
  57. };
  58. this.getFoldWidgetRange = function(session, foldStyle, row) {
  59. var line = session.getLine(row);
  60. var startColumn = line.length;
  61. var maxRow = session.getLength();
  62. var startRow = row;
  63. var endRow = row;
  64. if (this.isHeading(session,row)) {
  65. while (++row < maxRow) {
  66. if (this.isHeading(session,row)){
  67. row--;
  68. break;
  69. }
  70. }
  71. endRow = row;
  72. if (endRow > startRow) {
  73. while (endRow > startRow && /^\s*$/.test(session.getLine(endRow)))
  74. endRow--;
  75. }
  76. if (endRow > startRow) {
  77. var endColumn = session.getLine(endRow).length;
  78. return new Range(startRow, startColumn, endRow, endColumn);
  79. }
  80. } else if (this.getFoldWidget(session, foldStyle, row)==="end"){
  81. var endRow = row;
  82. var endColumn = session.getLine(endRow).length;
  83. while (--row>=0){
  84. if (this.isHeading(session,row)){
  85. break;
  86. }
  87. }
  88. var line = session.getLine(row);
  89. var startColumn = line.length;
  90. return new Range(row, startColumn, endRow, endColumn);
  91. }
  92. };
  93. }).call(FoldMode.prototype);
  94. });
  95. ace.define("ace/mode/haskell_cabal",["require","exports","module","ace/lib/oop","ace/mode/text","ace/mode/haskell_cabal_highlight_rules","ace/mode/folding/haskell_cabal"], function(require, exports, module) {
  96. "use strict";
  97. var oop = require("../lib/oop");
  98. var TextMode = require("./text").Mode;
  99. var CabalHighlightRules = require("./haskell_cabal_highlight_rules").CabalHighlightRules;
  100. var FoldMode = require("./folding/haskell_cabal").FoldMode;
  101. var Mode = function() {
  102. this.HighlightRules = CabalHighlightRules;
  103. this.foldingRules = new FoldMode();
  104. this.$behaviour = this.$defaultBehaviour;
  105. };
  106. oop.inherits(Mode, TextMode);
  107. (function() {
  108. this.lineCommentStart = "--";
  109. this.blockComment = null;
  110. this.$id = "ace/mode/haskell_cabal";
  111. }).call(Mode.prototype);
  112. exports.Mode = Mode;
  113. });