mode-json5.js 11 KB

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