mode-hjson.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  1. ace.define("ace/mode/hjson_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 HjsonHighlightRules = function() {
  6. this.$rules = {
  7. start: [{
  8. include: "#comments"
  9. }, {
  10. include: "#rootObject"
  11. }, {
  12. include: "#value"
  13. }],
  14. "#array": [{
  15. token: "paren.lparen",
  16. regex: /\[/,
  17. push: [{
  18. token: "paren.rparen",
  19. regex: /\]/,
  20. next: "pop"
  21. }, {
  22. include: "#value"
  23. }, {
  24. include: "#comments"
  25. }, {
  26. token: "text",
  27. regex: /,|$/
  28. }, {
  29. token: "invalid.illegal",
  30. regex: /[^\s\]]/
  31. }, {
  32. defaultToken: "array"
  33. }]
  34. }],
  35. "#comments": [{
  36. token: [
  37. "comment.punctuation",
  38. "comment.line"
  39. ],
  40. regex: /(#)(.*$)/
  41. }, {
  42. token: "comment.punctuation",
  43. regex: /\/\*/,
  44. push: [{
  45. token: "comment.punctuation",
  46. regex: /\*\//,
  47. next: "pop"
  48. }, {
  49. defaultToken: "comment.block"
  50. }]
  51. }, {
  52. token: [
  53. "comment.punctuation",
  54. "comment.line"
  55. ],
  56. regex: /(\/\/)(.*$)/
  57. }],
  58. "#constant": [{
  59. token: "constant",
  60. regex: /\b(?:true|false|null)\b/
  61. }],
  62. "#keyname": [{
  63. token: "keyword",
  64. regex: /(?:[^,\{\[\}\]\s]+|"(?:[^"\\]|\\.)*")\s*(?=:)/
  65. }],
  66. "#mstring": [{
  67. token: "string",
  68. regex: /'''/,
  69. push: [{
  70. token: "string",
  71. regex: /'''/,
  72. next: "pop"
  73. }, {
  74. defaultToken: "string"
  75. }]
  76. }],
  77. "#number": [{
  78. token: "constant.numeric",
  79. regex: /-?(?:0|[1-9]\d*)(?:(?:\.\d+)?(?:[eE][+-]?\d+)?)?/,
  80. comment: "handles integer and decimal numbers"
  81. }],
  82. "#object": [{
  83. token: "paren.lparen",
  84. regex: /\{/,
  85. push: [{
  86. token: "paren.rparen",
  87. regex: /\}/,
  88. next: "pop"
  89. }, {
  90. include: "#keyname"
  91. }, {
  92. include: "#value"
  93. }, {
  94. token: "text",
  95. regex: /:/
  96. }, {
  97. token: "text",
  98. regex: /,/
  99. }, {
  100. defaultToken: "paren"
  101. }]
  102. }],
  103. "#rootObject": [{
  104. token: "paren",
  105. regex: /(?=\s*(?:[^,\{\[\}\]\s]+|"(?:[^"\\]|\\.)*")\s*:)/,
  106. push: [{
  107. token: "paren.rparen",
  108. regex: /---none---/,
  109. next: "pop"
  110. }, {
  111. include: "#keyname"
  112. }, {
  113. include: "#value"
  114. }, {
  115. token: "text",
  116. regex: /:/
  117. }, {
  118. token: "text",
  119. regex: /,/
  120. }, {
  121. defaultToken: "paren"
  122. }]
  123. }],
  124. "#string": [{
  125. token: "string",
  126. regex: /"/,
  127. push: [{
  128. token: "string",
  129. regex: /"/,
  130. next: "pop"
  131. }, {
  132. token: "constant.language.escape",
  133. regex: /\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/
  134. }, {
  135. token: "invalid.illegal",
  136. regex: /\\./
  137. }, {
  138. defaultToken: "string"
  139. }]
  140. }],
  141. "#ustring": [{
  142. token: "string",
  143. regex: /\b[^:,0-9\-\{\[\}\]\s].*$/
  144. }],
  145. "#value": [{
  146. include: "#constant"
  147. }, {
  148. include: "#number"
  149. }, {
  150. include: "#string"
  151. }, {
  152. include: "#array"
  153. }, {
  154. include: "#object"
  155. }, {
  156. include: "#comments"
  157. }, {
  158. include: "#mstring"
  159. }, {
  160. include: "#ustring"
  161. }]
  162. };
  163. this.normalizeRules();
  164. };
  165. HjsonHighlightRules.metaData = {
  166. fileTypes: ["hjson"],
  167. foldingStartMarker: "(?x: # turn on extended mode\n ^ # a line beginning with\n \\s* # some optional space\n [{\\[] # the start of an object or array\n (?! # but not followed by\n .* # whatever\n [}\\]] # and the close of an object or array\n ,? # an optional comma\n \\s* # some optional space\n $ # at the end of the line\n )\n | # ...or...\n [{\\[] # the start of an object or array\n \\s* # some optional space\n $ # at the end of the line\n )",
  168. foldingStopMarker: "(?x: # turn on extended mode\n ^ # a line beginning with\n \\s* # some optional space\n [}\\]] # and the close of an object or array\n )",
  169. keyEquivalent: "^~J",
  170. name: "Hjson",
  171. scopeName: "source.hjson"
  172. };
  173. oop.inherits(HjsonHighlightRules, TextHighlightRules);
  174. exports.HjsonHighlightRules = HjsonHighlightRules;
  175. });
  176. ace.define("ace/mode/folding/cstyle",[], function(require, exports, module) {
  177. "use strict";
  178. var oop = require("../../lib/oop");
  179. var Range = require("../../range").Range;
  180. var BaseFoldMode = require("./fold_mode").FoldMode;
  181. var FoldMode = exports.FoldMode = function(commentRegex) {
  182. if (commentRegex) {
  183. this.foldingStartMarker = new RegExp(
  184. this.foldingStartMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.start)
  185. );
  186. this.foldingStopMarker = new RegExp(
  187. this.foldingStopMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.end)
  188. );
  189. }
  190. };
  191. oop.inherits(FoldMode, BaseFoldMode);
  192. (function() {
  193. this.foldingStartMarker = /([\{\[\(])[^\}\]\)]*$|^\s*(\/\*)/;
  194. this.foldingStopMarker = /^[^\[\{\(]*([\}\]\)])|^[\s\*]*(\*\/)/;
  195. this.singleLineBlockCommentRe= /^\s*(\/\*).*\*\/\s*$/;
  196. this.tripleStarBlockCommentRe = /^\s*(\/\*\*\*).*\*\/\s*$/;
  197. this.startRegionRe = /^\s*(\/\*|\/\/)#?region\b/;
  198. this._getFoldWidgetBase = this.getFoldWidget;
  199. this.getFoldWidget = function(session, foldStyle, row) {
  200. var line = session.getLine(row);
  201. if (this.singleLineBlockCommentRe.test(line)) {
  202. if (!this.startRegionRe.test(line) && !this.tripleStarBlockCommentRe.test(line))
  203. return "";
  204. }
  205. var fw = this._getFoldWidgetBase(session, foldStyle, row);
  206. if (!fw && this.startRegionRe.test(line))
  207. return "start"; // lineCommentRegionStart
  208. return fw;
  209. };
  210. this.getFoldWidgetRange = function(session, foldStyle, row, forceMultiline) {
  211. var line = session.getLine(row);
  212. if (this.startRegionRe.test(line))
  213. return this.getCommentRegionBlock(session, line, row);
  214. var match = line.match(this.foldingStartMarker);
  215. if (match) {
  216. var i = match.index;
  217. if (match[1])
  218. return this.openingBracketBlock(session, match[1], row, i);
  219. var range = session.getCommentFoldRange(row, i + match[0].length, 1);
  220. if (range && !range.isMultiLine()) {
  221. if (forceMultiline) {
  222. range = this.getSectionRange(session, row);
  223. } else if (foldStyle != "all")
  224. range = null;
  225. }
  226. return range;
  227. }
  228. if (foldStyle === "markbegin")
  229. return;
  230. var match = line.match(this.foldingStopMarker);
  231. if (match) {
  232. var i = match.index + match[0].length;
  233. if (match[1])
  234. return this.closingBracketBlock(session, match[1], row, i);
  235. return session.getCommentFoldRange(row, i, -1);
  236. }
  237. };
  238. this.getSectionRange = function(session, row) {
  239. var line = session.getLine(row);
  240. var startIndent = line.search(/\S/);
  241. var startRow = row;
  242. var startColumn = line.length;
  243. row = row + 1;
  244. var endRow = row;
  245. var maxRow = session.getLength();
  246. while (++row < maxRow) {
  247. line = session.getLine(row);
  248. var indent = line.search(/\S/);
  249. if (indent === -1)
  250. continue;
  251. if (startIndent > indent)
  252. break;
  253. var subRange = this.getFoldWidgetRange(session, "all", row);
  254. if (subRange) {
  255. if (subRange.start.row <= startRow) {
  256. break;
  257. } else if (subRange.isMultiLine()) {
  258. row = subRange.end.row;
  259. } else if (startIndent == indent) {
  260. break;
  261. }
  262. }
  263. endRow = row;
  264. }
  265. return new Range(startRow, startColumn, endRow, session.getLine(endRow).length);
  266. };
  267. this.getCommentRegionBlock = function(session, line, row) {
  268. var startColumn = line.search(/\s*$/);
  269. var maxRow = session.getLength();
  270. var startRow = row;
  271. var re = /^\s*(?:\/\*|\/\/|--)#?(end)?region\b/;
  272. var depth = 1;
  273. while (++row < maxRow) {
  274. line = session.getLine(row);
  275. var m = re.exec(line);
  276. if (!m) continue;
  277. if (m[1]) depth--;
  278. else depth++;
  279. if (!depth) break;
  280. }
  281. var endRow = row;
  282. if (endRow > startRow) {
  283. return new Range(startRow, startColumn, endRow, line.length);
  284. }
  285. };
  286. }).call(FoldMode.prototype);
  287. });
  288. ace.define("ace/mode/hjson",[], function(require, exports, module) {
  289. "use strict";
  290. var oop = require("../lib/oop");
  291. var TextMode = require("./text").Mode;
  292. var HjsonHighlightRules = require("./hjson_highlight_rules").HjsonHighlightRules;
  293. var FoldMode = require("./folding/cstyle").FoldMode;
  294. var Mode = function() {
  295. this.HighlightRules = HjsonHighlightRules;
  296. this.foldingRules = new FoldMode();
  297. };
  298. oop.inherits(Mode, TextMode);
  299. (function() {
  300. this.lineCommentStart = "//";
  301. this.blockComment = { start: "/*", end: "*/" };
  302. this.$id = "ace/mode/hjson";
  303. }).call(Mode.prototype);
  304. exports.Mode = Mode;
  305. });
  306. (function() {
  307. ace.require(["ace/mode/hjson"], function(m) {
  308. if (typeof module == "object" && typeof exports == "object" && module) {
  309. module.exports = m;
  310. }
  311. });
  312. })();