06c89bf980f201e95c550f51a020321b.js 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. ace.define("ace/mode/scheme_highlight_rules",["require","exports","module","ace/lib/oop","ace/mode/text_highlight_rules"], function(require, exports, module){"use strict";
  2. var oop = require("../lib/oop");
  3. var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
  4. var SchemeHighlightRules = function () {
  5. var keywordControl = "case|do|let|loop|if|else|when";
  6. var keywordOperator = "eq?|eqv?|equal?|and|or|not|null?";
  7. var constantLanguage = "#t|#f";
  8. var supportFunctions = "cons|car|cdr|cond|lambda|lambda*|syntax-rules|format|set!|quote|eval|append|list|list?|member?|load";
  9. var keywordMapper = this.createKeywordMapper({
  10. "keyword.control": keywordControl,
  11. "keyword.operator": keywordOperator,
  12. "constant.language": constantLanguage,
  13. "support.function": supportFunctions
  14. }, "identifier", true);
  15. this.$rules =
  16. {
  17. "start": [
  18. {
  19. token: "comment",
  20. regex: ";.*$"
  21. },
  22. {
  23. "token": ["storage.type.function-type.scheme", "text", "entity.name.function.scheme"],
  24. "regex": "(?:\\b(?:(define|define-syntax|define-macro))\\b)(\\s+)((?:\\w|\\-|\\!|\\?)*)"
  25. },
  26. {
  27. "token": "punctuation.definition.constant.character.scheme",
  28. "regex": "#:\\S+"
  29. },
  30. {
  31. "token": ["punctuation.definition.variable.scheme", "variable.other.global.scheme", "punctuation.definition.variable.scheme"],
  32. "regex": "(\\*)(\\S*)(\\*)"
  33. },
  34. {
  35. "token": "constant.numeric",
  36. "regex": "#[xXoObB][0-9a-fA-F]+"
  37. },
  38. {
  39. "token": "constant.numeric",
  40. "regex": "[+-]?\\d+(?:(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)?"
  41. },
  42. {
  43. "token": keywordMapper,
  44. "regex": "[a-zA-Z_#][a-zA-Z0-9_\\-\\?\\!\\*]*"
  45. },
  46. {
  47. "token": "string",
  48. "regex": '"(?=.)',
  49. "next": "qqstring"
  50. }
  51. ],
  52. "qqstring": [
  53. {
  54. "token": "constant.character.escape.scheme",
  55. "regex": "\\\\."
  56. },
  57. {
  58. "token": "string",
  59. "regex": '[^"\\\\]+',
  60. "merge": true
  61. }, {
  62. "token": "string",
  63. "regex": "\\\\$",
  64. "next": "qqstring",
  65. "merge": true
  66. }, {
  67. "token": "string",
  68. "regex": '"|$',
  69. "next": "start",
  70. "merge": true
  71. }
  72. ]
  73. };
  74. };
  75. oop.inherits(SchemeHighlightRules, TextHighlightRules);
  76. exports.SchemeHighlightRules = SchemeHighlightRules;
  77. });
  78. ace.define("ace/mode/matching_parens_outdent",["require","exports","module","ace/range"], function(require, exports, module){"use strict";
  79. var Range = require("../range").Range;
  80. var MatchingParensOutdent = function () { };
  81. (function () {
  82. this.checkOutdent = function (line, input) {
  83. if (!/^\s+$/.test(line))
  84. return false;
  85. return /^\s*\)/.test(input);
  86. };
  87. this.autoOutdent = function (doc, row) {
  88. var line = doc.getLine(row);
  89. var match = line.match(/^(\s*\))/);
  90. if (!match)
  91. return 0;
  92. var column = match[1].length;
  93. var openBracePos = doc.findMatchingBracket({ row: row, column: column });
  94. if (!openBracePos || openBracePos.row == row)
  95. return 0;
  96. var indent = this.$getIndent(doc.getLine(openBracePos.row));
  97. doc.replace(new Range(row, 0, row, column - 1), indent);
  98. };
  99. this.$getIndent = function (line) {
  100. var match = line.match(/^(\s+)/);
  101. if (match) {
  102. return match[1];
  103. }
  104. return "";
  105. };
  106. }).call(MatchingParensOutdent.prototype);
  107. exports.MatchingParensOutdent = MatchingParensOutdent;
  108. });
  109. ace.define("ace/mode/scheme",["require","exports","module","ace/lib/oop","ace/mode/text","ace/mode/scheme_highlight_rules","ace/mode/matching_parens_outdent"], function(require, exports, module){"use strict";
  110. var oop = require("../lib/oop");
  111. var TextMode = require("./text").Mode;
  112. var SchemeHighlightRules = require("./scheme_highlight_rules").SchemeHighlightRules;
  113. var MatchingParensOutdent = require("./matching_parens_outdent").MatchingParensOutdent;
  114. var Mode = function () {
  115. this.HighlightRules = SchemeHighlightRules;
  116. this.$outdent = new MatchingParensOutdent();
  117. this.$behaviour = this.$defaultBehaviour;
  118. };
  119. oop.inherits(Mode, TextMode);
  120. (function () {
  121. this.lineCommentStart = ";";
  122. this.minorIndentFunctions = ["define", "lambda", "define-macro", "define-syntax", "syntax-rules", "define-record-type", "define-structure"];
  123. this.$toIndent = function (str) {
  124. return str.split('').map(function (ch) {
  125. if (/\s/.exec(ch)) {
  126. return ch;
  127. }
  128. else {
  129. return ' ';
  130. }
  131. }).join('');
  132. };
  133. this.$calculateIndent = function (line, tab) {
  134. var baseIndent = this.$getIndent(line);
  135. var delta = 0;
  136. var isParen, ch;
  137. for (var i = line.length - 1; i >= 0; i--) {
  138. ch = line[i];
  139. if (ch === '(') {
  140. delta--;
  141. isParen = true;
  142. }
  143. else if (ch === '(' || ch === '[' || ch === '{') {
  144. delta--;
  145. isParen = false;
  146. }
  147. else if (ch === ')' || ch === ']' || ch === '}') {
  148. delta++;
  149. }
  150. if (delta < 0) {
  151. break;
  152. }
  153. }
  154. if (delta < 0 && isParen) {
  155. i += 1;
  156. var iBefore = i;
  157. var fn = '';
  158. while (true) {
  159. ch = line[i];
  160. if (ch === ' ' || ch === '\t') {
  161. if (this.minorIndentFunctions.indexOf(fn) !== -1) {
  162. return this.$toIndent(line.substring(0, iBefore - 1) + tab);
  163. }
  164. else {
  165. return this.$toIndent(line.substring(0, i + 1));
  166. }
  167. }
  168. else if (ch === undefined) {
  169. return this.$toIndent(line.substring(0, iBefore - 1) + tab);
  170. }
  171. fn += line[i];
  172. i++;
  173. }
  174. }
  175. else if (delta < 0 && !isParen) {
  176. return this.$toIndent(line.substring(0, i + 1));
  177. }
  178. else if (delta > 0) {
  179. baseIndent = baseIndent.substring(0, baseIndent.length - tab.length);
  180. return baseIndent;
  181. }
  182. else {
  183. return baseIndent;
  184. }
  185. };
  186. this.getNextLineIndent = function (state, line, tab) {
  187. return this.$calculateIndent(line, tab);
  188. };
  189. this.checkOutdent = function (state, line, input) {
  190. return this.$outdent.checkOutdent(line, input);
  191. };
  192. this.autoOutdent = function (state, doc, row) {
  193. this.$outdent.autoOutdent(doc, row);
  194. };
  195. this.$id = "ace/mode/scheme";
  196. }).call(Mode.prototype);
  197. exports.Mode = Mode;
  198. }); (function() {
  199. ace.require(["ace/mode/scheme"], function(m) {
  200. if (typeof module == "object" && typeof exports == "object" && module) {
  201. module.exports = m;
  202. }
  203. });
  204. })();