504a0846d6283cc54c7ea6fe9984f737.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. ace.define("ace/mode/json_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 JsonHighlightRules = function () {
  5. this.$rules = {
  6. "start": [
  7. {
  8. token: "variable",
  9. regex: '["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]\\s*(?=:)'
  10. }, {
  11. token: "string",
  12. regex: '"',
  13. next: "string"
  14. }, {
  15. token: "constant.numeric",
  16. regex: "0[xX][0-9a-fA-F]+\\b"
  17. }, {
  18. token: "constant.numeric",
  19. regex: "[+-]?\\d+(?:(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)?\\b"
  20. }, {
  21. token: "constant.language.boolean",
  22. regex: "(?:true|false)\\b"
  23. }, {
  24. token: "text",
  25. regex: "['](?:(?:\\\\.)|(?:[^'\\\\]))*?[']"
  26. }, {
  27. token: "comment",
  28. regex: "\\/\\/.*$"
  29. }, {
  30. token: "comment.start",
  31. regex: "\\/\\*",
  32. next: "comment"
  33. }, {
  34. token: "paren.lparen",
  35. regex: "[[({]"
  36. }, {
  37. token: "paren.rparen",
  38. regex: "[\\])}]"
  39. }, {
  40. token: "punctuation.operator",
  41. regex: /[,]/
  42. }, {
  43. token: "text",
  44. regex: "\\s+"
  45. }
  46. ],
  47. "string": [
  48. {
  49. token: "constant.language.escape",
  50. regex: /\\(?:x[0-9a-fA-F]{2}|u[0-9a-fA-F]{4}|["\\\/bfnrt])/
  51. }, {
  52. token: "string",
  53. regex: '"|$',
  54. next: "start"
  55. }, {
  56. defaultToken: "string"
  57. }
  58. ],
  59. "comment": [
  60. {
  61. token: "comment.end",
  62. regex: "\\*\\/",
  63. next: "start"
  64. }, {
  65. defaultToken: "comment"
  66. }
  67. ]
  68. };
  69. };
  70. oop.inherits(JsonHighlightRules, TextHighlightRules);
  71. exports.JsonHighlightRules = JsonHighlightRules;
  72. });
  73. ace.define("ace/mode/matching_brace_outdent",["require","exports","module","ace/range"], function(require, exports, module){"use strict";
  74. var Range = require("../range").Range;
  75. var MatchingBraceOutdent = function () { };
  76. (function () {
  77. this.checkOutdent = function (line, input) {
  78. if (!/^\s+$/.test(line))
  79. return false;
  80. return /^\s*\}/.test(input);
  81. };
  82. this.autoOutdent = function (doc, row) {
  83. var line = doc.getLine(row);
  84. var match = line.match(/^(\s*\})/);
  85. if (!match)
  86. return 0;
  87. var column = match[1].length;
  88. var openBracePos = doc.findMatchingBracket({ row: row, column: column });
  89. if (!openBracePos || openBracePos.row == row)
  90. return 0;
  91. var indent = this.$getIndent(doc.getLine(openBracePos.row));
  92. doc.replace(new Range(row, 0, row, column - 1), indent);
  93. };
  94. this.$getIndent = function (line) {
  95. return line.match(/^\s*/)[0];
  96. };
  97. }).call(MatchingBraceOutdent.prototype);
  98. exports.MatchingBraceOutdent = MatchingBraceOutdent;
  99. });
  100. ace.define("ace/mode/folding/cstyle",["require","exports","module","ace/lib/oop","ace/range","ace/mode/folding/fold_mode"], function(require, exports, module){"use strict";
  101. var oop = require("../../lib/oop");
  102. var Range = require("../../range").Range;
  103. var BaseFoldMode = require("./fold_mode").FoldMode;
  104. var FoldMode = exports.FoldMode = function (commentRegex) {
  105. if (commentRegex) {
  106. this.foldingStartMarker = new RegExp(this.foldingStartMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.start));
  107. this.foldingStopMarker = new RegExp(this.foldingStopMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.end));
  108. }
  109. };
  110. oop.inherits(FoldMode, BaseFoldMode);
  111. (function () {
  112. this.foldingStartMarker = /([\{\[\(])[^\}\]\)]*$|^\s*(\/\*)/;
  113. this.foldingStopMarker = /^[^\[\{\(]*([\}\]\)])|^[\s\*]*(\*\/)/;
  114. this.singleLineBlockCommentRe = /^\s*(\/\*).*\*\/\s*$/;
  115. this.tripleStarBlockCommentRe = /^\s*(\/\*\*\*).*\*\/\s*$/;
  116. this.startRegionRe = /^\s*(\/\*|\/\/)#?region\b/;
  117. this._getFoldWidgetBase = this.getFoldWidget;
  118. this.getFoldWidget = function (session, foldStyle, row) {
  119. var line = session.getLine(row);
  120. if (this.singleLineBlockCommentRe.test(line)) {
  121. if (!this.startRegionRe.test(line) && !this.tripleStarBlockCommentRe.test(line))
  122. return "";
  123. }
  124. var fw = this._getFoldWidgetBase(session, foldStyle, row);
  125. if (!fw && this.startRegionRe.test(line))
  126. return "start"; // lineCommentRegionStart
  127. return fw;
  128. };
  129. this.getFoldWidgetRange = function (session, foldStyle, row, forceMultiline) {
  130. var line = session.getLine(row);
  131. if (this.startRegionRe.test(line))
  132. return this.getCommentRegionBlock(session, line, row);
  133. var match = line.match(this.foldingStartMarker);
  134. if (match) {
  135. var i = match.index;
  136. if (match[1])
  137. return this.openingBracketBlock(session, match[1], row, i);
  138. var range = session.getCommentFoldRange(row, i + match[0].length, 1);
  139. if (range && !range.isMultiLine()) {
  140. if (forceMultiline) {
  141. range = this.getSectionRange(session, row);
  142. }
  143. else if (foldStyle != "all")
  144. range = null;
  145. }
  146. return range;
  147. }
  148. if (foldStyle === "markbegin")
  149. return;
  150. var match = line.match(this.foldingStopMarker);
  151. if (match) {
  152. var i = match.index + match[0].length;
  153. if (match[1])
  154. return this.closingBracketBlock(session, match[1], row, i);
  155. return session.getCommentFoldRange(row, i, -1);
  156. }
  157. };
  158. this.getSectionRange = function (session, row) {
  159. var line = session.getLine(row);
  160. var startIndent = line.search(/\S/);
  161. var startRow = row;
  162. var startColumn = line.length;
  163. row = row + 1;
  164. var endRow = row;
  165. var maxRow = session.getLength();
  166. while (++row < maxRow) {
  167. line = session.getLine(row);
  168. var indent = line.search(/\S/);
  169. if (indent === -1)
  170. continue;
  171. if (startIndent > indent)
  172. break;
  173. var subRange = this.getFoldWidgetRange(session, "all", row);
  174. if (subRange) {
  175. if (subRange.start.row <= startRow) {
  176. break;
  177. }
  178. else if (subRange.isMultiLine()) {
  179. row = subRange.end.row;
  180. }
  181. else if (startIndent == indent) {
  182. break;
  183. }
  184. }
  185. endRow = row;
  186. }
  187. return new Range(startRow, startColumn, endRow, session.getLine(endRow).length);
  188. };
  189. this.getCommentRegionBlock = function (session, line, row) {
  190. var startColumn = line.search(/\s*$/);
  191. var maxRow = session.getLength();
  192. var startRow = row;
  193. var re = /^\s*(?:\/\*|\/\/|--)#?(end)?region\b/;
  194. var depth = 1;
  195. while (++row < maxRow) {
  196. line = session.getLine(row);
  197. var m = re.exec(line);
  198. if (!m)
  199. continue;
  200. if (m[1])
  201. depth--;
  202. else
  203. depth++;
  204. if (!depth)
  205. break;
  206. }
  207. var endRow = row;
  208. if (endRow > startRow) {
  209. return new Range(startRow, startColumn, endRow, line.length);
  210. }
  211. };
  212. }).call(FoldMode.prototype);
  213. });
  214. ace.define("ace/mode/json",["require","exports","module","ace/lib/oop","ace/mode/text","ace/mode/json_highlight_rules","ace/mode/matching_brace_outdent","ace/mode/behaviour/cstyle","ace/mode/folding/cstyle","ace/worker/worker_client"], function(require, exports, module){"use strict";
  215. var oop = require("../lib/oop");
  216. var TextMode = require("./text").Mode;
  217. var HighlightRules = require("./json_highlight_rules").JsonHighlightRules;
  218. var MatchingBraceOutdent = require("./matching_brace_outdent").MatchingBraceOutdent;
  219. var CstyleBehaviour = require("./behaviour/cstyle").CstyleBehaviour;
  220. var CStyleFoldMode = require("./folding/cstyle").FoldMode;
  221. var WorkerClient = require("../worker/worker_client").WorkerClient;
  222. var Mode = function () {
  223. this.HighlightRules = HighlightRules;
  224. this.$outdent = new MatchingBraceOutdent();
  225. this.$behaviour = new CstyleBehaviour();
  226. this.foldingRules = new CStyleFoldMode();
  227. };
  228. oop.inherits(Mode, TextMode);
  229. (function () {
  230. this.lineCommentStart = "//";
  231. this.blockComment = { start: "/*", end: "*/" };
  232. this.getNextLineIndent = function (state, line, tab) {
  233. var indent = this.$getIndent(line);
  234. if (state == "start") {
  235. var match = line.match(/^.*[\{\(\[]\s*$/);
  236. if (match) {
  237. indent += tab;
  238. }
  239. }
  240. return indent;
  241. };
  242. this.checkOutdent = function (state, line, input) {
  243. return this.$outdent.checkOutdent(line, input);
  244. };
  245. this.autoOutdent = function (state, doc, row) {
  246. this.$outdent.autoOutdent(doc, row);
  247. };
  248. this.createWorker = function (session) {
  249. var worker = new WorkerClient(["ace"], "ace/mode/json_worker", "JsonWorker");
  250. worker.attachToDocument(session.getDocument());
  251. worker.on("annotate", function (e) {
  252. session.setAnnotations(e.data);
  253. });
  254. worker.on("terminate", function () {
  255. session.clearAnnotations();
  256. });
  257. return worker;
  258. };
  259. this.$id = "ace/mode/json";
  260. }).call(Mode.prototype);
  261. exports.Mode = Mode;
  262. }); (function() {
  263. ace.require(["ace/mode/json"], function(m) {
  264. if (typeof module == "object" && typeof exports == "object" && module) {
  265. module.exports = m;
  266. }
  267. });
  268. })();