Нема описа
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668
  1. ace.define("ace/mode/json_highlight_rules",["require","exports","module","ace/lib/oop","ace/mode/text_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 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 : "invalid.illegal", // single quoted strings are not allowed
  26. regex : "['](?:(?:\\\\.)|(?:[^'\\\\]))*?[']"
  27. }, {
  28. token : "invalid.illegal", // comments are not allowed
  29. regex : "\\/\\/.*$"
  30. }, {
  31. token : "paren.lparen",
  32. regex : "[[({]"
  33. }, {
  34. token : "paren.rparen",
  35. regex : "[\\])}]"
  36. }, {
  37. token : "text",
  38. regex : "\\s+"
  39. }
  40. ],
  41. "string" : [
  42. {
  43. token : "constant.language.escape",
  44. regex : /\\(?:x[0-9a-fA-F]{2}|u[0-9a-fA-F]{4}|["\\\/bfnrt])/
  45. }, {
  46. token : "string",
  47. regex : '[^"\\\\]+'
  48. }, {
  49. token : "string",
  50. regex : '"',
  51. next : "start"
  52. }, {
  53. token : "string",
  54. regex : "",
  55. next : "start"
  56. }
  57. ]
  58. };
  59. };
  60. oop.inherits(JsonHighlightRules, TextHighlightRules);
  61. exports.JsonHighlightRules = JsonHighlightRules;
  62. });
  63. ace.define("ace/mode/matching_brace_outdent",["require","exports","module","ace/range"], function(require, exports, module) {
  64. "use strict";
  65. var Range = require("../range").Range;
  66. var MatchingBraceOutdent = function() {};
  67. (function() {
  68. this.checkOutdent = function(line, input) {
  69. if (! /^\s+$/.test(line))
  70. return false;
  71. return /^\s*\}/.test(input);
  72. };
  73. this.autoOutdent = function(doc, row) {
  74. var line = doc.getLine(row);
  75. var match = line.match(/^(\s*\})/);
  76. if (!match) return 0;
  77. var column = match[1].length;
  78. var openBracePos = doc.findMatchingBracket({row: row, column: column});
  79. if (!openBracePos || openBracePos.row == row) return 0;
  80. var indent = this.$getIndent(doc.getLine(openBracePos.row));
  81. doc.replace(new Range(row, 0, row, column-1), indent);
  82. };
  83. this.$getIndent = function(line) {
  84. return line.match(/^\s*/)[0];
  85. };
  86. }).call(MatchingBraceOutdent.prototype);
  87. exports.MatchingBraceOutdent = MatchingBraceOutdent;
  88. });
  89. ace.define("ace/mode/behaviour/cstyle",["require","exports","module","ace/lib/oop","ace/mode/behaviour","ace/token_iterator","ace/lib/lang"], function(require, exports, module) {
  90. "use strict";
  91. var oop = require("../../lib/oop");
  92. var Behaviour = require("../behaviour").Behaviour;
  93. var TokenIterator = require("../../token_iterator").TokenIterator;
  94. var lang = require("../../lib/lang");
  95. var SAFE_INSERT_IN_TOKENS =
  96. ["text", "paren.rparen", "punctuation.operator"];
  97. var SAFE_INSERT_BEFORE_TOKENS =
  98. ["text", "paren.rparen", "punctuation.operator", "comment"];
  99. var context;
  100. var contextCache = {};
  101. var initContext = function(editor) {
  102. var id = -1;
  103. if (editor.multiSelect) {
  104. id = editor.selection.index;
  105. if (contextCache.rangeCount != editor.multiSelect.rangeCount)
  106. contextCache = {rangeCount: editor.multiSelect.rangeCount};
  107. }
  108. if (contextCache[id])
  109. return context = contextCache[id];
  110. context = contextCache[id] = {
  111. autoInsertedBrackets: 0,
  112. autoInsertedRow: -1,
  113. autoInsertedLineEnd: "",
  114. maybeInsertedBrackets: 0,
  115. maybeInsertedRow: -1,
  116. maybeInsertedLineStart: "",
  117. maybeInsertedLineEnd: ""
  118. };
  119. };
  120. var CstyleBehaviour = function() {
  121. this.add("braces", "insertion", function(state, action, editor, session, text) {
  122. var cursor = editor.getCursorPosition();
  123. var line = session.doc.getLine(cursor.row);
  124. if (text == '{') {
  125. initContext(editor);
  126. var selection = editor.getSelectionRange();
  127. var selected = session.doc.getTextRange(selection);
  128. if (selected !== "" && selected !== "{" && editor.getWrapBehavioursEnabled()) {
  129. return {
  130. text: '{' + selected + '}',
  131. selection: false
  132. };
  133. } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
  134. if (/[\]\}\)]/.test(line[cursor.column]) || editor.inMultiSelectMode) {
  135. CstyleBehaviour.recordAutoInsert(editor, session, "}");
  136. return {
  137. text: '{}',
  138. selection: [1, 1]
  139. };
  140. } else {
  141. CstyleBehaviour.recordMaybeInsert(editor, session, "{");
  142. return {
  143. text: '{',
  144. selection: [1, 1]
  145. };
  146. }
  147. }
  148. } else if (text == '}') {
  149. initContext(editor);
  150. var rightChar = line.substring(cursor.column, cursor.column + 1);
  151. if (rightChar == '}') {
  152. var matching = session.$findOpeningBracket('}', {column: cursor.column + 1, row: cursor.row});
  153. if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) {
  154. CstyleBehaviour.popAutoInsertedClosing();
  155. return {
  156. text: '',
  157. selection: [1, 1]
  158. };
  159. }
  160. }
  161. } else if (text == "\n" || text == "\r\n") {
  162. initContext(editor);
  163. var closing = "";
  164. if (CstyleBehaviour.isMaybeInsertedClosing(cursor, line)) {
  165. closing = lang.stringRepeat("}", context.maybeInsertedBrackets);
  166. CstyleBehaviour.clearMaybeInsertedClosing();
  167. }
  168. var rightChar = line.substring(cursor.column, cursor.column + 1);
  169. if (rightChar === '}') {
  170. var openBracePos = session.findMatchingBracket({row: cursor.row, column: cursor.column+1}, '}');
  171. if (!openBracePos)
  172. return null;
  173. var next_indent = this.$getIndent(session.getLine(openBracePos.row));
  174. } else if (closing) {
  175. var next_indent = this.$getIndent(line);
  176. } else {
  177. CstyleBehaviour.clearMaybeInsertedClosing();
  178. return;
  179. }
  180. var indent = next_indent + session.getTabString();
  181. return {
  182. text: '\n' + indent + '\n' + next_indent + closing,
  183. selection: [1, indent.length, 1, indent.length]
  184. };
  185. } else {
  186. CstyleBehaviour.clearMaybeInsertedClosing();
  187. }
  188. });
  189. this.add("braces", "deletion", function(state, action, editor, session, range) {
  190. var selected = session.doc.getTextRange(range);
  191. if (!range.isMultiLine() && selected == '{') {
  192. initContext(editor);
  193. var line = session.doc.getLine(range.start.row);
  194. var rightChar = line.substring(range.end.column, range.end.column + 1);
  195. if (rightChar == '}') {
  196. range.end.column++;
  197. return range;
  198. } else {
  199. context.maybeInsertedBrackets--;
  200. }
  201. }
  202. });
  203. this.add("parens", "insertion", function(state, action, editor, session, text) {
  204. if (text == '(') {
  205. initContext(editor);
  206. var selection = editor.getSelectionRange();
  207. var selected = session.doc.getTextRange(selection);
  208. if (selected !== "" && editor.getWrapBehavioursEnabled()) {
  209. return {
  210. text: '(' + selected + ')',
  211. selection: false
  212. };
  213. } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
  214. CstyleBehaviour.recordAutoInsert(editor, session, ")");
  215. return {
  216. text: '()',
  217. selection: [1, 1]
  218. };
  219. }
  220. } else if (text == ')') {
  221. initContext(editor);
  222. var cursor = editor.getCursorPosition();
  223. var line = session.doc.getLine(cursor.row);
  224. var rightChar = line.substring(cursor.column, cursor.column + 1);
  225. if (rightChar == ')') {
  226. var matching = session.$findOpeningBracket(')', {column: cursor.column + 1, row: cursor.row});
  227. if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) {
  228. CstyleBehaviour.popAutoInsertedClosing();
  229. return {
  230. text: '',
  231. selection: [1, 1]
  232. };
  233. }
  234. }
  235. }
  236. });
  237. this.add("parens", "deletion", function(state, action, editor, session, range) {
  238. var selected = session.doc.getTextRange(range);
  239. if (!range.isMultiLine() && selected == '(') {
  240. initContext(editor);
  241. var line = session.doc.getLine(range.start.row);
  242. var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
  243. if (rightChar == ')') {
  244. range.end.column++;
  245. return range;
  246. }
  247. }
  248. });
  249. this.add("brackets", "insertion", function(state, action, editor, session, text) {
  250. if (text == '[') {
  251. initContext(editor);
  252. var selection = editor.getSelectionRange();
  253. var selected = session.doc.getTextRange(selection);
  254. if (selected !== "" && editor.getWrapBehavioursEnabled()) {
  255. return {
  256. text: '[' + selected + ']',
  257. selection: false
  258. };
  259. } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
  260. CstyleBehaviour.recordAutoInsert(editor, session, "]");
  261. return {
  262. text: '[]',
  263. selection: [1, 1]
  264. };
  265. }
  266. } else if (text == ']') {
  267. initContext(editor);
  268. var cursor = editor.getCursorPosition();
  269. var line = session.doc.getLine(cursor.row);
  270. var rightChar = line.substring(cursor.column, cursor.column + 1);
  271. if (rightChar == ']') {
  272. var matching = session.$findOpeningBracket(']', {column: cursor.column + 1, row: cursor.row});
  273. if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) {
  274. CstyleBehaviour.popAutoInsertedClosing();
  275. return {
  276. text: '',
  277. selection: [1, 1]
  278. };
  279. }
  280. }
  281. }
  282. });
  283. this.add("brackets", "deletion", function(state, action, editor, session, range) {
  284. var selected = session.doc.getTextRange(range);
  285. if (!range.isMultiLine() && selected == '[') {
  286. initContext(editor);
  287. var line = session.doc.getLine(range.start.row);
  288. var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
  289. if (rightChar == ']') {
  290. range.end.column++;
  291. return range;
  292. }
  293. }
  294. });
  295. this.add("string_dquotes", "insertion", function(state, action, editor, session, text) {
  296. if (text == '"' || text == "'") {
  297. initContext(editor);
  298. var quote = text;
  299. var selection = editor.getSelectionRange();
  300. var selected = session.doc.getTextRange(selection);
  301. if (selected !== "" && selected !== "'" && selected != '"' && editor.getWrapBehavioursEnabled()) {
  302. return {
  303. text: quote + selected + quote,
  304. selection: false
  305. };
  306. } else {
  307. var cursor = editor.getCursorPosition();
  308. var line = session.doc.getLine(cursor.row);
  309. var leftChar = line.substring(cursor.column-1, cursor.column);
  310. var rightChar = line.substring(cursor.column, cursor.column + 1);
  311. var token = session.getTokenAt(cursor.row, cursor.column);
  312. var rightToken = session.getTokenAt(cursor.row, cursor.column + 1);
  313. if (leftChar == "\\" && token && /escape/.test(token.type))
  314. return null;
  315. var stringBefore = token && /string/.test(token.type);
  316. var stringAfter = !rightToken || /string/.test(rightToken.type);
  317. var pair;
  318. if (rightChar == quote) {
  319. pair = stringBefore !== stringAfter;
  320. } else {
  321. if (stringBefore && !stringAfter)
  322. return null; // wrap string with different quote
  323. if (stringBefore && stringAfter)
  324. return null; // do not pair quotes inside strings
  325. var wordRe = session.$mode.tokenRe;
  326. wordRe.lastIndex = 0;
  327. var isWordBefore = wordRe.test(leftChar);
  328. wordRe.lastIndex = 0;
  329. var isWordAfter = wordRe.test(leftChar);
  330. if (isWordBefore || isWordAfter)
  331. return null; // before or after alphanumeric
  332. if (rightChar && !/[\s;,.})\]\\]/.test(rightChar))
  333. return null; // there is rightChar and it isn't closing
  334. pair = true;
  335. }
  336. return {
  337. text: pair ? quote + quote : "",
  338. selection: [1,1]
  339. };
  340. }
  341. }
  342. });
  343. this.add("string_dquotes", "deletion", function(state, action, editor, session, range) {
  344. var selected = session.doc.getTextRange(range);
  345. if (!range.isMultiLine() && (selected == '"' || selected == "'")) {
  346. initContext(editor);
  347. var line = session.doc.getLine(range.start.row);
  348. var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
  349. if (rightChar == selected) {
  350. range.end.column++;
  351. return range;
  352. }
  353. }
  354. });
  355. };
  356. CstyleBehaviour.isSaneInsertion = function(editor, session) {
  357. var cursor = editor.getCursorPosition();
  358. var iterator = new TokenIterator(session, cursor.row, cursor.column);
  359. if (!this.$matchTokenType(iterator.getCurrentToken() || "text", SAFE_INSERT_IN_TOKENS)) {
  360. var iterator2 = new TokenIterator(session, cursor.row, cursor.column + 1);
  361. if (!this.$matchTokenType(iterator2.getCurrentToken() || "text", SAFE_INSERT_IN_TOKENS))
  362. return false;
  363. }
  364. iterator.stepForward();
  365. return iterator.getCurrentTokenRow() !== cursor.row ||
  366. this.$matchTokenType(iterator.getCurrentToken() || "text", SAFE_INSERT_BEFORE_TOKENS);
  367. };
  368. CstyleBehaviour.$matchTokenType = function(token, types) {
  369. return types.indexOf(token.type || token) > -1;
  370. };
  371. CstyleBehaviour.recordAutoInsert = function(editor, session, bracket) {
  372. var cursor = editor.getCursorPosition();
  373. var line = session.doc.getLine(cursor.row);
  374. if (!this.isAutoInsertedClosing(cursor, line, context.autoInsertedLineEnd[0]))
  375. context.autoInsertedBrackets = 0;
  376. context.autoInsertedRow = cursor.row;
  377. context.autoInsertedLineEnd = bracket + line.substr(cursor.column);
  378. context.autoInsertedBrackets++;
  379. };
  380. CstyleBehaviour.recordMaybeInsert = function(editor, session, bracket) {
  381. var cursor = editor.getCursorPosition();
  382. var line = session.doc.getLine(cursor.row);
  383. if (!this.isMaybeInsertedClosing(cursor, line))
  384. context.maybeInsertedBrackets = 0;
  385. context.maybeInsertedRow = cursor.row;
  386. context.maybeInsertedLineStart = line.substr(0, cursor.column) + bracket;
  387. context.maybeInsertedLineEnd = line.substr(cursor.column);
  388. context.maybeInsertedBrackets++;
  389. };
  390. CstyleBehaviour.isAutoInsertedClosing = function(cursor, line, bracket) {
  391. return context.autoInsertedBrackets > 0 &&
  392. cursor.row === context.autoInsertedRow &&
  393. bracket === context.autoInsertedLineEnd[0] &&
  394. line.substr(cursor.column) === context.autoInsertedLineEnd;
  395. };
  396. CstyleBehaviour.isMaybeInsertedClosing = function(cursor, line) {
  397. return context.maybeInsertedBrackets > 0 &&
  398. cursor.row === context.maybeInsertedRow &&
  399. line.substr(cursor.column) === context.maybeInsertedLineEnd &&
  400. line.substr(0, cursor.column) == context.maybeInsertedLineStart;
  401. };
  402. CstyleBehaviour.popAutoInsertedClosing = function() {
  403. context.autoInsertedLineEnd = context.autoInsertedLineEnd.substr(1);
  404. context.autoInsertedBrackets--;
  405. };
  406. CstyleBehaviour.clearMaybeInsertedClosing = function() {
  407. if (context) {
  408. context.maybeInsertedBrackets = 0;
  409. context.maybeInsertedRow = -1;
  410. }
  411. };
  412. oop.inherits(CstyleBehaviour, Behaviour);
  413. exports.CstyleBehaviour = CstyleBehaviour;
  414. });
  415. ace.define("ace/mode/folding/cstyle",["require","exports","module","ace/lib/oop","ace/range","ace/mode/folding/fold_mode"], function(require, exports, module) {
  416. "use strict";
  417. var oop = require("../../lib/oop");
  418. var Range = require("../../range").Range;
  419. var BaseFoldMode = require("./fold_mode").FoldMode;
  420. var FoldMode = exports.FoldMode = function(commentRegex) {
  421. if (commentRegex) {
  422. this.foldingStartMarker = new RegExp(
  423. this.foldingStartMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.start)
  424. );
  425. this.foldingStopMarker = new RegExp(
  426. this.foldingStopMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.end)
  427. );
  428. }
  429. };
  430. oop.inherits(FoldMode, BaseFoldMode);
  431. (function() {
  432. this.foldingStartMarker = /(\{|\[)[^\}\]]*$|^\s*(\/\*)/;
  433. this.foldingStopMarker = /^[^\[\{]*(\}|\])|^[\s\*]*(\*\/)/;
  434. this.singleLineBlockCommentRe= /^\s*(\/\*).*\*\/\s*$/;
  435. this.tripleStarBlockCommentRe = /^\s*(\/\*\*\*).*\*\/\s*$/;
  436. this.startRegionRe = /^\s*(\/\*|\/\/)#region\b/;
  437. this._getFoldWidgetBase = this.getFoldWidget;
  438. this.getFoldWidget = function(session, foldStyle, row) {
  439. var line = session.getLine(row);
  440. if (this.singleLineBlockCommentRe.test(line)) {
  441. if (!this.startRegionRe.test(line) && !this.tripleStarBlockCommentRe.test(line))
  442. return "";
  443. }
  444. var fw = this._getFoldWidgetBase(session, foldStyle, row);
  445. if (!fw && this.startRegionRe.test(line))
  446. return "start"; // lineCommentRegionStart
  447. return fw;
  448. };
  449. this.getFoldWidgetRange = function(session, foldStyle, row, forceMultiline) {
  450. var line = session.getLine(row);
  451. if (this.startRegionRe.test(line))
  452. return this.getCommentRegionBlock(session, line, row);
  453. var match = line.match(this.foldingStartMarker);
  454. if (match) {
  455. var i = match.index;
  456. if (match[1])
  457. return this.openingBracketBlock(session, match[1], row, i);
  458. var range = session.getCommentFoldRange(row, i + match[0].length, 1);
  459. if (range && !range.isMultiLine()) {
  460. if (forceMultiline) {
  461. range = this.getSectionRange(session, row);
  462. } else if (foldStyle != "all")
  463. range = null;
  464. }
  465. return range;
  466. }
  467. if (foldStyle === "markbegin")
  468. return;
  469. var match = line.match(this.foldingStopMarker);
  470. if (match) {
  471. var i = match.index + match[0].length;
  472. if (match[1])
  473. return this.closingBracketBlock(session, match[1], row, i);
  474. return session.getCommentFoldRange(row, i, -1);
  475. }
  476. };
  477. this.getSectionRange = function(session, row) {
  478. var line = session.getLine(row);
  479. var startIndent = line.search(/\S/);
  480. var startRow = row;
  481. var startColumn = line.length;
  482. row = row + 1;
  483. var endRow = row;
  484. var maxRow = session.getLength();
  485. while (++row < maxRow) {
  486. line = session.getLine(row);
  487. var indent = line.search(/\S/);
  488. if (indent === -1)
  489. continue;
  490. if (startIndent > indent)
  491. break;
  492. var subRange = this.getFoldWidgetRange(session, "all", row);
  493. if (subRange) {
  494. if (subRange.start.row <= startRow) {
  495. break;
  496. } else if (subRange.isMultiLine()) {
  497. row = subRange.end.row;
  498. } else if (startIndent == indent) {
  499. break;
  500. }
  501. }
  502. endRow = row;
  503. }
  504. return new Range(startRow, startColumn, endRow, session.getLine(endRow).length);
  505. };
  506. this.getCommentRegionBlock = function(session, line, row) {
  507. var startColumn = line.search(/\s*$/);
  508. var maxRow = session.getLength();
  509. var startRow = row;
  510. var re = /^\s*(?:\/\*|\/\/)#(end)?region\b/;
  511. var depth = 1;
  512. while (++row < maxRow) {
  513. line = session.getLine(row);
  514. var m = re.exec(line);
  515. if (!m) continue;
  516. if (m[1]) depth--;
  517. else depth++;
  518. if (!depth) break;
  519. }
  520. var endRow = row;
  521. if (endRow > startRow) {
  522. return new Range(startRow, startColumn, endRow, line.length);
  523. }
  524. };
  525. }).call(FoldMode.prototype);
  526. });
  527. 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) {
  528. "use strict";
  529. var oop = require("../lib/oop");
  530. var TextMode = require("./text").Mode;
  531. var HighlightRules = require("./json_highlight_rules").JsonHighlightRules;
  532. var MatchingBraceOutdent = require("./matching_brace_outdent").MatchingBraceOutdent;
  533. var CstyleBehaviour = require("./behaviour/cstyle").CstyleBehaviour;
  534. var CStyleFoldMode = require("./folding/cstyle").FoldMode;
  535. var WorkerClient = require("../worker/worker_client").WorkerClient;
  536. var Mode = function() {
  537. this.HighlightRules = HighlightRules;
  538. this.$outdent = new MatchingBraceOutdent();
  539. this.$behaviour = new CstyleBehaviour();
  540. this.foldingRules = new CStyleFoldMode();
  541. };
  542. oop.inherits(Mode, TextMode);
  543. (function() {
  544. this.getNextLineIndent = function(state, line, tab) {
  545. var indent = this.$getIndent(line);
  546. if (state == "start") {
  547. var match = line.match(/^.*[\{\(\[]\s*$/);
  548. if (match) {
  549. indent += tab;
  550. }
  551. }
  552. return indent;
  553. };
  554. this.checkOutdent = function(state, line, input) {
  555. return this.$outdent.checkOutdent(line, input);
  556. };
  557. this.autoOutdent = function(state, doc, row) {
  558. this.$outdent.autoOutdent(doc, row);
  559. };
  560. this.createWorker = function(session) {
  561. var worker = new WorkerClient(["ace"], "ace/mode/json_worker", "JsonWorker");
  562. worker.attachToDocument(session.getDocument());
  563. worker.on("error", function(e) {
  564. session.setAnnotations([e.data]);
  565. });
  566. worker.on("ok", function() {
  567. session.clearAnnotations();
  568. });
  569. return worker;
  570. };
  571. this.$id = "ace/mode/json";
  572. }).call(Mode.prototype);
  573. exports.Mode = Mode;
  574. });