mode-graphqlschema.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. ace.define("ace/mode/graphqlschema_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 GraphQLSchemaHighlightRules = function() {
  6. var keywords = (
  7. "type|interface|union|enum|schema|input|implements|extends|scalar"
  8. );
  9. var dataTypes = (
  10. "Int|Float|String|ID|Boolean"
  11. );
  12. var keywordMapper = this.createKeywordMapper({
  13. "keyword": keywords,
  14. "storage.type": dataTypes
  15. }, "identifier");
  16. this.$rules = {
  17. "start" : [ {
  18. token : "comment",
  19. regex : "#.*$"
  20. }, {
  21. token : "paren.lparen",
  22. regex : /[\[({]/,
  23. next : "start"
  24. }, {
  25. token : "paren.rparen",
  26. regex : /[\])}]/
  27. }, {
  28. token : keywordMapper,
  29. regex : "[a-zA-Z_$][a-zA-Z0-9_$]*\\b"
  30. } ]
  31. };
  32. this.normalizeRules();
  33. };
  34. oop.inherits(GraphQLSchemaHighlightRules, TextHighlightRules);
  35. exports.GraphQLSchemaHighlightRules = GraphQLSchemaHighlightRules;
  36. });
  37. ace.define("ace/mode/folding/cstyle",[], function(require, exports, module) {
  38. "use strict";
  39. var oop = require("../../lib/oop");
  40. var Range = require("../../range").Range;
  41. var BaseFoldMode = require("./fold_mode").FoldMode;
  42. var FoldMode = exports.FoldMode = function(commentRegex) {
  43. if (commentRegex) {
  44. this.foldingStartMarker = new RegExp(
  45. this.foldingStartMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.start)
  46. );
  47. this.foldingStopMarker = new RegExp(
  48. this.foldingStopMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.end)
  49. );
  50. }
  51. };
  52. oop.inherits(FoldMode, BaseFoldMode);
  53. (function() {
  54. this.foldingStartMarker = /([\{\[\(])[^\}\]\)]*$|^\s*(\/\*)/;
  55. this.foldingStopMarker = /^[^\[\{\(]*([\}\]\)])|^[\s\*]*(\*\/)/;
  56. this.singleLineBlockCommentRe= /^\s*(\/\*).*\*\/\s*$/;
  57. this.tripleStarBlockCommentRe = /^\s*(\/\*\*\*).*\*\/\s*$/;
  58. this.startRegionRe = /^\s*(\/\*|\/\/)#?region\b/;
  59. this._getFoldWidgetBase = this.getFoldWidget;
  60. this.getFoldWidget = function(session, foldStyle, row) {
  61. var line = session.getLine(row);
  62. if (this.singleLineBlockCommentRe.test(line)) {
  63. if (!this.startRegionRe.test(line) && !this.tripleStarBlockCommentRe.test(line))
  64. return "";
  65. }
  66. var fw = this._getFoldWidgetBase(session, foldStyle, row);
  67. if (!fw && this.startRegionRe.test(line))
  68. return "start"; // lineCommentRegionStart
  69. return fw;
  70. };
  71. this.getFoldWidgetRange = function(session, foldStyle, row, forceMultiline) {
  72. var line = session.getLine(row);
  73. if (this.startRegionRe.test(line))
  74. return this.getCommentRegionBlock(session, line, row);
  75. var match = line.match(this.foldingStartMarker);
  76. if (match) {
  77. var i = match.index;
  78. if (match[1])
  79. return this.openingBracketBlock(session, match[1], row, i);
  80. var range = session.getCommentFoldRange(row, i + match[0].length, 1);
  81. if (range && !range.isMultiLine()) {
  82. if (forceMultiline) {
  83. range = this.getSectionRange(session, row);
  84. } else if (foldStyle != "all")
  85. range = null;
  86. }
  87. return range;
  88. }
  89. if (foldStyle === "markbegin")
  90. return;
  91. var match = line.match(this.foldingStopMarker);
  92. if (match) {
  93. var i = match.index + match[0].length;
  94. if (match[1])
  95. return this.closingBracketBlock(session, match[1], row, i);
  96. return session.getCommentFoldRange(row, i, -1);
  97. }
  98. };
  99. this.getSectionRange = function(session, row) {
  100. var line = session.getLine(row);
  101. var startIndent = line.search(/\S/);
  102. var startRow = row;
  103. var startColumn = line.length;
  104. row = row + 1;
  105. var endRow = row;
  106. var maxRow = session.getLength();
  107. while (++row < maxRow) {
  108. line = session.getLine(row);
  109. var indent = line.search(/\S/);
  110. if (indent === -1)
  111. continue;
  112. if (startIndent > indent)
  113. break;
  114. var subRange = this.getFoldWidgetRange(session, "all", row);
  115. if (subRange) {
  116. if (subRange.start.row <= startRow) {
  117. break;
  118. } else if (subRange.isMultiLine()) {
  119. row = subRange.end.row;
  120. } else if (startIndent == indent) {
  121. break;
  122. }
  123. }
  124. endRow = row;
  125. }
  126. return new Range(startRow, startColumn, endRow, session.getLine(endRow).length);
  127. };
  128. this.getCommentRegionBlock = function(session, line, row) {
  129. var startColumn = line.search(/\s*$/);
  130. var maxRow = session.getLength();
  131. var startRow = row;
  132. var re = /^\s*(?:\/\*|\/\/|--)#?(end)?region\b/;
  133. var depth = 1;
  134. while (++row < maxRow) {
  135. line = session.getLine(row);
  136. var m = re.exec(line);
  137. if (!m) continue;
  138. if (m[1]) depth--;
  139. else depth++;
  140. if (!depth) break;
  141. }
  142. var endRow = row;
  143. if (endRow > startRow) {
  144. return new Range(startRow, startColumn, endRow, line.length);
  145. }
  146. };
  147. }).call(FoldMode.prototype);
  148. });
  149. ace.define("ace/mode/graphqlschema",[], function(require, exports, module) {
  150. "use strict";
  151. var oop = require("../lib/oop");
  152. var TextMode = require("./text").Mode;
  153. var GraphQLSchemaHighlightRules = require("./graphqlschema_highlight_rules").GraphQLSchemaHighlightRules;
  154. var FoldMode = require("./folding/cstyle").FoldMode;
  155. var Mode = function() {
  156. this.HighlightRules = GraphQLSchemaHighlightRules;
  157. this.foldingRules = new FoldMode();
  158. };
  159. oop.inherits(Mode, TextMode);
  160. (function() {
  161. this.lineCommentStart = "#";
  162. this.$id = "ace/mode/graphqlschema";
  163. }).call(Mode.prototype);
  164. exports.Mode = Mode;
  165. });
  166. (function() {
  167. ace.require(["ace/mode/graphqlschema"], function(m) {
  168. if (typeof module == "object" && typeof exports == "object" && module) {
  169. module.exports = m;
  170. }
  171. });
  172. })();