mode-io.js 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. ace.define("ace/mode/io_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 IoHighlightRules = function() {
  6. this.$rules = { start:
  7. [ { token: 'keyword.control.io',
  8. regex: '\\b(?:if|ifTrue|ifFalse|ifTrueIfFalse|for|loop|reverseForeach|foreach|map|continue|break|while|do|return)\\b' },
  9. { token: 'punctuation.definition.comment.io',
  10. regex: '/\\*',
  11. push:
  12. [ { token: 'punctuation.definition.comment.io',
  13. regex: '\\*/',
  14. next: 'pop' },
  15. { defaultToken: 'comment.block.io' } ] },
  16. { token: 'punctuation.definition.comment.io',
  17. regex: '//',
  18. push:
  19. [ { token: 'comment.line.double-slash.io',
  20. regex: '$',
  21. next: 'pop' },
  22. { defaultToken: 'comment.line.double-slash.io' } ] },
  23. { token: 'punctuation.definition.comment.io',
  24. regex: '#',
  25. push:
  26. [ { token: 'comment.line.number-sign.io', regex: '$', next: 'pop' },
  27. { defaultToken: 'comment.line.number-sign.io' } ] },
  28. { token: 'variable.language.io',
  29. regex: '\\b(?:self|sender|target|proto|protos|parent)\\b',
  30. comment: 'I wonder if some of this isn\'t variable.other.language? --Allan; scoping this as variable.language to match Objective-C\'s handling of \'self\', which is inconsistent with C++\'s handling of \'this\' but perhaps intentionally so -- Rob' },
  31. { token: 'keyword.operator.io',
  32. regex: '<=|>=|=|:=|\\*|\\||\\|\\||\\+|-|/|&|&&|>|<|\\?|@|@@|\\b(?:and|or)\\b' },
  33. { token: 'constant.other.io', regex: '\\bGL[\\w_]+\\b' },
  34. { token: 'support.class.io', regex: '\\b[A-Z](?:\\w+)?\\b' },
  35. { token: 'support.function.io',
  36. regex: '\\b(?:clone|call|init|method|list|vector|block|\\w+(?=\\s*\\())\\b' },
  37. { token: 'support.function.open-gl.io',
  38. regex: '\\bgl(?:u|ut)?[A-Z]\\w+\\b' },
  39. { token: 'punctuation.definition.string.begin.io',
  40. regex: '"""',
  41. push:
  42. [ { token: 'punctuation.definition.string.end.io',
  43. regex: '"""',
  44. next: 'pop' },
  45. { token: 'constant.character.escape.io', regex: '\\\\.' },
  46. { defaultToken: 'string.quoted.triple.io' } ] },
  47. { token: 'punctuation.definition.string.begin.io',
  48. regex: '"',
  49. push:
  50. [ { token: 'punctuation.definition.string.end.io',
  51. regex: '"',
  52. next: 'pop' },
  53. { token: 'constant.character.escape.io', regex: '\\\\.' },
  54. { defaultToken: 'string.quoted.double.io' } ] },
  55. { token: 'constant.numeric.io',
  56. regex: '\\b(?:0(?:x|X)[0-9a-fA-F]*|(?:[0-9]+\\.?[0-9]*|\\.[0-9]+)(?:(?:e|E)(?:\\+|-)?[0-9]+)?)(?:L|l|UL|ul|u|U|F|f)?\\b' },
  57. { token: 'variable.other.global.io', regex: 'Lobby\\b' },
  58. { token: 'constant.language.io',
  59. regex: '\\b(?:TRUE|true|FALSE|false|NULL|null|Null|Nil|nil|YES|NO)\\b' } ] };
  60. this.normalizeRules();
  61. };
  62. IoHighlightRules.metaData = { fileTypes: [ 'io' ],
  63. keyEquivalent: '^~I',
  64. name: 'Io',
  65. scopeName: 'source.io' };
  66. oop.inherits(IoHighlightRules, TextHighlightRules);
  67. exports.IoHighlightRules = IoHighlightRules;
  68. });
  69. ace.define("ace/mode/folding/cstyle",["require","exports","module","ace/lib/oop","ace/range","ace/mode/folding/fold_mode"], function(require, exports, module) {
  70. "use strict";
  71. var oop = require("../../lib/oop");
  72. var Range = require("../../range").Range;
  73. var BaseFoldMode = require("./fold_mode").FoldMode;
  74. var FoldMode = exports.FoldMode = function(commentRegex) {
  75. if (commentRegex) {
  76. this.foldingStartMarker = new RegExp(
  77. this.foldingStartMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.start)
  78. );
  79. this.foldingStopMarker = new RegExp(
  80. this.foldingStopMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.end)
  81. );
  82. }
  83. };
  84. oop.inherits(FoldMode, BaseFoldMode);
  85. (function() {
  86. this.foldingStartMarker = /([\{\[\(])[^\}\]\)]*$|^\s*(\/\*)/;
  87. this.foldingStopMarker = /^[^\[\{\(]*([\}\]\)])|^[\s\*]*(\*\/)/;
  88. this.singleLineBlockCommentRe= /^\s*(\/\*).*\*\/\s*$/;
  89. this.tripleStarBlockCommentRe = /^\s*(\/\*\*\*).*\*\/\s*$/;
  90. this.startRegionRe = /^\s*(\/\*|\/\/)#?region\b/;
  91. this._getFoldWidgetBase = this.getFoldWidget;
  92. this.getFoldWidget = function(session, foldStyle, row) {
  93. var line = session.getLine(row);
  94. if (this.singleLineBlockCommentRe.test(line)) {
  95. if (!this.startRegionRe.test(line) && !this.tripleStarBlockCommentRe.test(line))
  96. return "";
  97. }
  98. var fw = this._getFoldWidgetBase(session, foldStyle, row);
  99. if (!fw && this.startRegionRe.test(line))
  100. return "start"; // lineCommentRegionStart
  101. return fw;
  102. };
  103. this.getFoldWidgetRange = function(session, foldStyle, row, forceMultiline) {
  104. var line = session.getLine(row);
  105. if (this.startRegionRe.test(line))
  106. return this.getCommentRegionBlock(session, line, row);
  107. var match = line.match(this.foldingStartMarker);
  108. if (match) {
  109. var i = match.index;
  110. if (match[1])
  111. return this.openingBracketBlock(session, match[1], row, i);
  112. var range = session.getCommentFoldRange(row, i + match[0].length, 1);
  113. if (range && !range.isMultiLine()) {
  114. if (forceMultiline) {
  115. range = this.getSectionRange(session, row);
  116. } else if (foldStyle != "all")
  117. range = null;
  118. }
  119. return range;
  120. }
  121. if (foldStyle === "markbegin")
  122. return;
  123. var match = line.match(this.foldingStopMarker);
  124. if (match) {
  125. var i = match.index + match[0].length;
  126. if (match[1])
  127. return this.closingBracketBlock(session, match[1], row, i);
  128. return session.getCommentFoldRange(row, i, -1);
  129. }
  130. };
  131. this.getSectionRange = function(session, row) {
  132. var line = session.getLine(row);
  133. var startIndent = line.search(/\S/);
  134. var startRow = row;
  135. var startColumn = line.length;
  136. row = row + 1;
  137. var endRow = row;
  138. var maxRow = session.getLength();
  139. while (++row < maxRow) {
  140. line = session.getLine(row);
  141. var indent = line.search(/\S/);
  142. if (indent === -1)
  143. continue;
  144. if (startIndent > indent)
  145. break;
  146. var subRange = this.getFoldWidgetRange(session, "all", row);
  147. if (subRange) {
  148. if (subRange.start.row <= startRow) {
  149. break;
  150. } else if (subRange.isMultiLine()) {
  151. row = subRange.end.row;
  152. } else if (startIndent == indent) {
  153. break;
  154. }
  155. }
  156. endRow = row;
  157. }
  158. return new Range(startRow, startColumn, endRow, session.getLine(endRow).length);
  159. };
  160. this.getCommentRegionBlock = function(session, line, row) {
  161. var startColumn = line.search(/\s*$/);
  162. var maxRow = session.getLength();
  163. var startRow = row;
  164. var re = /^\s*(?:\/\*|\/\/|--)#?(end)?region\b/;
  165. var depth = 1;
  166. while (++row < maxRow) {
  167. line = session.getLine(row);
  168. var m = re.exec(line);
  169. if (!m) continue;
  170. if (m[1]) depth--;
  171. else depth++;
  172. if (!depth) break;
  173. }
  174. var endRow = row;
  175. if (endRow > startRow) {
  176. return new Range(startRow, startColumn, endRow, line.length);
  177. }
  178. };
  179. }).call(FoldMode.prototype);
  180. });
  181. ace.define("ace/mode/io",["require","exports","module","ace/lib/oop","ace/mode/text","ace/mode/io_highlight_rules","ace/mode/folding/cstyle"], function(require, exports, module) {
  182. "use strict";
  183. var oop = require("../lib/oop");
  184. var TextMode = require("./text").Mode;
  185. var IoHighlightRules = require("./io_highlight_rules").IoHighlightRules;
  186. var FoldMode = require("./folding/cstyle").FoldMode;
  187. var Mode = function() {
  188. this.HighlightRules = IoHighlightRules;
  189. this.foldingRules = new FoldMode();
  190. this.$behaviour = this.$defaultBehaviour;
  191. };
  192. oop.inherits(Mode, TextMode);
  193. (function() {
  194. this.lineCommentStart = "//";
  195. this.blockComment = {start: "/*", end: "*/"};
  196. this.$id = "ace/mode/io";
  197. this.snippetFileId = "ace/snippets/io";
  198. }).call(Mode.prototype);
  199. exports.Mode = Mode;
  200. }); (function() {
  201. ace.require(["ace/mode/io"], function(m) {
  202. if (typeof module == "object" && typeof exports == "object" && module) {
  203. module.exports = m;
  204. }
  205. });
  206. })();