mode-cirru.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. ace.define("ace/mode/cirru_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 CirruHighlightRules = function() {
  6. this.$rules = {
  7. start: [{
  8. token: 'constant.numeric',
  9. regex: /[\d\.]+/
  10. }, {
  11. token: 'comment.line.double-dash',
  12. regex: /--/,
  13. next: 'comment'
  14. }, {
  15. token: 'storage.modifier',
  16. regex: /\(/
  17. }, {
  18. token: 'storage.modifier',
  19. regex: /,/,
  20. next: 'line'
  21. }, {
  22. token: 'support.function',
  23. regex: /[^\(\)"\s]+/,
  24. next: 'line'
  25. }, {
  26. token: 'string.quoted.double',
  27. regex: /"/,
  28. next: 'string'
  29. }, {
  30. token: 'storage.modifier',
  31. regex: /\)/
  32. }],
  33. comment: [{
  34. token: 'comment.line.double-dash',
  35. regex: / +[^\n]+/,
  36. next: 'start'
  37. }],
  38. string: [{
  39. token: 'string.quoted.double',
  40. regex: /"/,
  41. next: 'line'
  42. }, {
  43. token: 'constant.character.escape',
  44. regex: /\\/,
  45. next: 'escape'
  46. }, {
  47. token: 'string.quoted.double',
  48. regex: /[^\\"]+/
  49. }],
  50. escape: [{
  51. token: 'constant.character.escape',
  52. regex: /./,
  53. next: 'string'
  54. }],
  55. line: [{
  56. token: 'constant.numeric',
  57. regex: /[\d\.]+/
  58. }, {
  59. token: 'markup.raw',
  60. regex: /^\s*/,
  61. next: 'start'
  62. }, {
  63. token: 'storage.modifier',
  64. regex: /\$/,
  65. next: 'start'
  66. }, {
  67. token: 'variable.parameter',
  68. regex: /[^\(\)"\s]+/
  69. }, {
  70. token: 'storage.modifier',
  71. regex: /\(/,
  72. next: 'start'
  73. }, {
  74. token: 'storage.modifier',
  75. regex: /\)/
  76. }, {
  77. token: 'markup.raw',
  78. regex: /^ */,
  79. next: 'start'
  80. }, {
  81. token: 'string.quoted.double',
  82. regex: /"/,
  83. next: 'string'
  84. }]
  85. }
  86. };
  87. oop.inherits(CirruHighlightRules, TextHighlightRules);
  88. exports.CirruHighlightRules = CirruHighlightRules;
  89. });
  90. ace.define("ace/mode/folding/coffee",["require","exports","module","ace/lib/oop","ace/mode/folding/fold_mode","ace/range"], function(require, exports, module) {
  91. "use strict";
  92. var oop = require("../../lib/oop");
  93. var BaseFoldMode = require("./fold_mode").FoldMode;
  94. var Range = require("../../range").Range;
  95. var FoldMode = exports.FoldMode = function() {};
  96. oop.inherits(FoldMode, BaseFoldMode);
  97. (function() {
  98. this.getFoldWidgetRange = function(session, foldStyle, row) {
  99. var range = this.indentationBlock(session, row);
  100. if (range)
  101. return range;
  102. var re = /\S/;
  103. var line = session.getLine(row);
  104. var startLevel = line.search(re);
  105. if (startLevel == -1 || line[startLevel] != "#")
  106. return;
  107. var startColumn = line.length;
  108. var maxRow = session.getLength();
  109. var startRow = row;
  110. var endRow = row;
  111. while (++row < maxRow) {
  112. line = session.getLine(row);
  113. var level = line.search(re);
  114. if (level == -1)
  115. continue;
  116. if (line[level] != "#")
  117. break;
  118. endRow = row;
  119. }
  120. if (endRow > startRow) {
  121. var endColumn = session.getLine(endRow).length;
  122. return new Range(startRow, startColumn, endRow, endColumn);
  123. }
  124. };
  125. this.getFoldWidget = function(session, foldStyle, row) {
  126. var line = session.getLine(row);
  127. var indent = line.search(/\S/);
  128. var next = session.getLine(row + 1);
  129. var prev = session.getLine(row - 1);
  130. var prevIndent = prev.search(/\S/);
  131. var nextIndent = next.search(/\S/);
  132. if (indent == -1) {
  133. session.foldWidgets[row - 1] = prevIndent!= -1 && prevIndent < nextIndent ? "start" : "";
  134. return "";
  135. }
  136. if (prevIndent == -1) {
  137. if (indent == nextIndent && line[indent] == "#" && next[indent] == "#") {
  138. session.foldWidgets[row - 1] = "";
  139. session.foldWidgets[row + 1] = "";
  140. return "start";
  141. }
  142. } else if (prevIndent == indent && line[indent] == "#" && prev[indent] == "#") {
  143. if (session.getLine(row - 2).search(/\S/) == -1) {
  144. session.foldWidgets[row - 1] = "start";
  145. session.foldWidgets[row + 1] = "";
  146. return "";
  147. }
  148. }
  149. if (prevIndent!= -1 && prevIndent < indent)
  150. session.foldWidgets[row - 1] = "start";
  151. else
  152. session.foldWidgets[row - 1] = "";
  153. if (indent < nextIndent)
  154. return "start";
  155. else
  156. return "";
  157. };
  158. }).call(FoldMode.prototype);
  159. });
  160. ace.define("ace/mode/cirru",["require","exports","module","ace/lib/oop","ace/mode/text","ace/mode/cirru_highlight_rules","ace/mode/folding/coffee"], function(require, exports, module) {
  161. "use strict";
  162. var oop = require("../lib/oop");
  163. var TextMode = require("./text").Mode;
  164. var CirruHighlightRules = require("./cirru_highlight_rules").CirruHighlightRules;
  165. var CoffeeFoldMode = require("./folding/coffee").FoldMode;
  166. var Mode = function() {
  167. this.HighlightRules = CirruHighlightRules;
  168. this.foldingRules = new CoffeeFoldMode();
  169. this.$behaviour = this.$defaultBehaviour;
  170. };
  171. oop.inherits(Mode, TextMode);
  172. (function() {
  173. this.lineCommentStart = "--";
  174. this.$id = "ace/mode/cirru";
  175. }).call(Mode.prototype);
  176. exports.Mode = Mode;
  177. });