mode-io.js 9.2 KB

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