Nav apraksta
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

mode-csharp.js 30KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847
  1. ace.define("ace/mode/doc_comment_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 DocCommentHighlightRules = function() {
  6. this.$rules = {
  7. "start" : [ {
  8. token : "comment.doc.tag",
  9. regex : "@[\\w\\d_]+" // TODO: fix email addresses
  10. },
  11. DocCommentHighlightRules.getTagRule(),
  12. {
  13. defaultToken : "comment.doc",
  14. caseInsensitive: true
  15. }]
  16. };
  17. };
  18. oop.inherits(DocCommentHighlightRules, TextHighlightRules);
  19. DocCommentHighlightRules.getTagRule = function(start) {
  20. return {
  21. token : "comment.doc.tag.storage.type",
  22. regex : "\\b(?:TODO|FIXME|XXX|HACK)\\b"
  23. };
  24. }
  25. DocCommentHighlightRules.getStartRule = function(start) {
  26. return {
  27. token : "comment.doc", // doc comment
  28. regex : "\\/\\*(?=\\*)",
  29. next : start
  30. };
  31. };
  32. DocCommentHighlightRules.getEndRule = function (start) {
  33. return {
  34. token : "comment.doc", // closing comment
  35. regex : "\\*\\/",
  36. next : start
  37. };
  38. };
  39. exports.DocCommentHighlightRules = DocCommentHighlightRules;
  40. });
  41. ace.define("ace/mode/csharp_highlight_rules",["require","exports","module","ace/lib/oop","ace/mode/doc_comment_highlight_rules","ace/mode/text_highlight_rules"], function(require, exports, module) {
  42. "use strict";
  43. var oop = require("../lib/oop");
  44. var DocCommentHighlightRules = require("./doc_comment_highlight_rules").DocCommentHighlightRules;
  45. var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
  46. var CSharpHighlightRules = function() {
  47. var keywordMapper = this.createKeywordMapper({
  48. "variable.language": "this",
  49. "keyword": "abstract|event|new|struct|as|explicit|null|switch|base|extern|object|this|bool|false|operator|throw|break|finally|out|true|byte|fixed|override|try|case|float|params|typeof|catch|for|private|uint|char|foreach|protected|ulong|checked|goto|public|unchecked|class|if|readonly|unsafe|const|implicit|ref|ushort|continue|in|return|using|decimal|int|sbyte|virtual|default|interface|sealed|volatile|delegate|internal|short|void|do|is|sizeof|while|double|lock|stackalloc|else|long|static|enum|namespace|string|var|dynamic",
  50. "constant.language": "null|true|false"
  51. }, "identifier");
  52. this.$rules = {
  53. "start" : [
  54. {
  55. token : "comment",
  56. regex : "\\/\\/.*$"
  57. },
  58. DocCommentHighlightRules.getStartRule("doc-start"),
  59. {
  60. token : "comment", // multi line comment
  61. regex : "\\/\\*",
  62. next : "comment"
  63. }, {
  64. token : "string", // character
  65. regex : /'(?:.|\\(:?u[\da-fA-F]+|x[\da-fA-F]+|[tbrf'"n]))'/
  66. }, {
  67. token : "string", start : '"', end : '"|$', next: [
  68. {token: "constant.language.escape", regex: /\\(:?u[\da-fA-F]+|x[\da-fA-F]+|[tbrf'"n])/},
  69. {token: "invalid", regex: /\\./}
  70. ]
  71. }, {
  72. token : "string", start : '@"', end : '"', next:[
  73. {token: "constant.language.escape", regex: '""'}
  74. ]
  75. }, {
  76. token : "constant.numeric", // hex
  77. regex : "0[xX][0-9a-fA-F]+\\b"
  78. }, {
  79. token : "constant.numeric", // float
  80. regex : "[+-]?\\d+(?:(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)?\\b"
  81. }, {
  82. token : "constant.language.boolean",
  83. regex : "(?:true|false)\\b"
  84. }, {
  85. token : keywordMapper,
  86. regex : "[a-zA-Z_$][a-zA-Z0-9_$]*\\b"
  87. }, {
  88. token : "keyword.operator",
  89. regex : "!|\\$|%|&|\\*|\\-\\-|\\-|\\+\\+|\\+|~|===|==|=|!=|!==|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\\|\\||\\?\\:|\\*=|%=|\\+=|\\-=|&=|\\^=|\\b(?:in|instanceof|new|delete|typeof|void)"
  90. }, {
  91. token : "keyword",
  92. regex : "^\\s*#(if|else|elif|endif|define|undef|warning|error|line|region|endregion|pragma)"
  93. }, {
  94. token : "punctuation.operator",
  95. regex : "\\?|\\:|\\,|\\;|\\."
  96. }, {
  97. token : "paren.lparen",
  98. regex : "[[({]"
  99. }, {
  100. token : "paren.rparen",
  101. regex : "[\\])}]"
  102. }, {
  103. token : "text",
  104. regex : "\\s+"
  105. }
  106. ],
  107. "comment" : [
  108. {
  109. token : "comment", // closing comment
  110. regex : ".*?\\*\\/",
  111. next : "start"
  112. }, {
  113. token : "comment", // comment spanning whole line
  114. regex : ".+"
  115. }
  116. ]
  117. };
  118. this.embedRules(DocCommentHighlightRules, "doc-",
  119. [ DocCommentHighlightRules.getEndRule("start") ]);
  120. this.normalizeRules();
  121. };
  122. oop.inherits(CSharpHighlightRules, TextHighlightRules);
  123. exports.CSharpHighlightRules = CSharpHighlightRules;
  124. });
  125. ace.define("ace/mode/matching_brace_outdent",["require","exports","module","ace/range"], function(require, exports, module) {
  126. "use strict";
  127. var Range = 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. 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) {
  152. "use strict";
  153. var oop = require("../../lib/oop");
  154. var Behaviour = require("../behaviour").Behaviour;
  155. var TokenIterator = require("../../token_iterator").TokenIterator;
  156. var lang = require("../../lib/lang");
  157. var SAFE_INSERT_IN_TOKENS =
  158. ["text", "paren.rparen", "punctuation.operator"];
  159. var SAFE_INSERT_BEFORE_TOKENS =
  160. ["text", "paren.rparen", "punctuation.operator", "comment"];
  161. var context;
  162. var contextCache = {};
  163. var initContext = function(editor) {
  164. var id = -1;
  165. if (editor.multiSelect) {
  166. id = editor.selection.index;
  167. if (contextCache.rangeCount != editor.multiSelect.rangeCount)
  168. contextCache = {rangeCount: editor.multiSelect.rangeCount};
  169. }
  170. if (contextCache[id])
  171. return context = contextCache[id];
  172. context = contextCache[id] = {
  173. autoInsertedBrackets: 0,
  174. autoInsertedRow: -1,
  175. autoInsertedLineEnd: "",
  176. maybeInsertedBrackets: 0,
  177. maybeInsertedRow: -1,
  178. maybeInsertedLineStart: "",
  179. maybeInsertedLineEnd: ""
  180. };
  181. };
  182. var CstyleBehaviour = function() {
  183. this.add("braces", "insertion", function(state, action, editor, session, text) {
  184. var cursor = editor.getCursorPosition();
  185. var line = session.doc.getLine(cursor.row);
  186. if (text == '{') {
  187. initContext(editor);
  188. var selection = editor.getSelectionRange();
  189. var selected = session.doc.getTextRange(selection);
  190. if (selected !== "" && selected !== "{" && editor.getWrapBehavioursEnabled()) {
  191. return {
  192. text: '{' + selected + '}',
  193. selection: false
  194. };
  195. } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
  196. if (/[\]\}\)]/.test(line[cursor.column]) || editor.inMultiSelectMode) {
  197. CstyleBehaviour.recordAutoInsert(editor, session, "}");
  198. return {
  199. text: '{}',
  200. selection: [1, 1]
  201. };
  202. } else {
  203. CstyleBehaviour.recordMaybeInsert(editor, session, "{");
  204. return {
  205. text: '{',
  206. selection: [1, 1]
  207. };
  208. }
  209. }
  210. } else if (text == '}') {
  211. initContext(editor);
  212. var rightChar = line.substring(cursor.column, cursor.column + 1);
  213. if (rightChar == '}') {
  214. var matching = session.$findOpeningBracket('}', {column: cursor.column + 1, row: cursor.row});
  215. if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) {
  216. CstyleBehaviour.popAutoInsertedClosing();
  217. return {
  218. text: '',
  219. selection: [1, 1]
  220. };
  221. }
  222. }
  223. } else if (text == "\n" || text == "\r\n") {
  224. initContext(editor);
  225. var closing = "";
  226. if (CstyleBehaviour.isMaybeInsertedClosing(cursor, line)) {
  227. closing = lang.stringRepeat("}", context.maybeInsertedBrackets);
  228. CstyleBehaviour.clearMaybeInsertedClosing();
  229. }
  230. var rightChar = line.substring(cursor.column, cursor.column + 1);
  231. if (rightChar === '}') {
  232. var openBracePos = session.findMatchingBracket({row: cursor.row, column: cursor.column+1}, '}');
  233. if (!openBracePos)
  234. return null;
  235. var next_indent = this.$getIndent(session.getLine(openBracePos.row));
  236. } else if (closing) {
  237. var next_indent = this.$getIndent(line);
  238. } else {
  239. CstyleBehaviour.clearMaybeInsertedClosing();
  240. return;
  241. }
  242. var indent = next_indent + session.getTabString();
  243. return {
  244. text: '\n' + indent + '\n' + next_indent + closing,
  245. selection: [1, indent.length, 1, indent.length]
  246. };
  247. } else {
  248. CstyleBehaviour.clearMaybeInsertedClosing();
  249. }
  250. });
  251. this.add("braces", "deletion", function(state, action, editor, session, range) {
  252. var selected = session.doc.getTextRange(range);
  253. if (!range.isMultiLine() && selected == '{') {
  254. initContext(editor);
  255. var line = session.doc.getLine(range.start.row);
  256. var rightChar = line.substring(range.end.column, range.end.column + 1);
  257. if (rightChar == '}') {
  258. range.end.column++;
  259. return range;
  260. } else {
  261. context.maybeInsertedBrackets--;
  262. }
  263. }
  264. });
  265. this.add("parens", "insertion", function(state, action, editor, session, text) {
  266. if (text == '(') {
  267. initContext(editor);
  268. var selection = editor.getSelectionRange();
  269. var selected = session.doc.getTextRange(selection);
  270. if (selected !== "" && editor.getWrapBehavioursEnabled()) {
  271. return {
  272. text: '(' + selected + ')',
  273. selection: false
  274. };
  275. } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
  276. CstyleBehaviour.recordAutoInsert(editor, session, ")");
  277. return {
  278. text: '()',
  279. selection: [1, 1]
  280. };
  281. }
  282. } else if (text == ')') {
  283. initContext(editor);
  284. var cursor = editor.getCursorPosition();
  285. var line = session.doc.getLine(cursor.row);
  286. var rightChar = line.substring(cursor.column, cursor.column + 1);
  287. if (rightChar == ')') {
  288. var matching = session.$findOpeningBracket(')', {column: cursor.column + 1, row: cursor.row});
  289. if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) {
  290. CstyleBehaviour.popAutoInsertedClosing();
  291. return {
  292. text: '',
  293. selection: [1, 1]
  294. };
  295. }
  296. }
  297. }
  298. });
  299. this.add("parens", "deletion", function(state, action, editor, session, range) {
  300. var selected = session.doc.getTextRange(range);
  301. if (!range.isMultiLine() && selected == '(') {
  302. initContext(editor);
  303. var line = session.doc.getLine(range.start.row);
  304. var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
  305. if (rightChar == ')') {
  306. range.end.column++;
  307. return range;
  308. }
  309. }
  310. });
  311. this.add("brackets", "insertion", function(state, action, editor, session, text) {
  312. if (text == '[') {
  313. initContext(editor);
  314. var selection = editor.getSelectionRange();
  315. var selected = session.doc.getTextRange(selection);
  316. if (selected !== "" && editor.getWrapBehavioursEnabled()) {
  317. return {
  318. text: '[' + selected + ']',
  319. selection: false
  320. };
  321. } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
  322. CstyleBehaviour.recordAutoInsert(editor, session, "]");
  323. return {
  324. text: '[]',
  325. selection: [1, 1]
  326. };
  327. }
  328. } else if (text == ']') {
  329. initContext(editor);
  330. var cursor = editor.getCursorPosition();
  331. var line = session.doc.getLine(cursor.row);
  332. var rightChar = line.substring(cursor.column, cursor.column + 1);
  333. if (rightChar == ']') {
  334. var matching = session.$findOpeningBracket(']', {column: cursor.column + 1, row: cursor.row});
  335. if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) {
  336. CstyleBehaviour.popAutoInsertedClosing();
  337. return {
  338. text: '',
  339. selection: [1, 1]
  340. };
  341. }
  342. }
  343. }
  344. });
  345. this.add("brackets", "deletion", function(state, action, editor, session, range) {
  346. var selected = session.doc.getTextRange(range);
  347. if (!range.isMultiLine() && selected == '[') {
  348. initContext(editor);
  349. var line = session.doc.getLine(range.start.row);
  350. var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
  351. if (rightChar == ']') {
  352. range.end.column++;
  353. return range;
  354. }
  355. }
  356. });
  357. this.add("string_dquotes", "insertion", function(state, action, editor, session, text) {
  358. if (text == '"' || text == "'") {
  359. initContext(editor);
  360. var quote = text;
  361. var selection = editor.getSelectionRange();
  362. var selected = session.doc.getTextRange(selection);
  363. if (selected !== "" && selected !== "'" && selected != '"' && editor.getWrapBehavioursEnabled()) {
  364. return {
  365. text: quote + selected + quote,
  366. selection: false
  367. };
  368. } else {
  369. var cursor = editor.getCursorPosition();
  370. var line = session.doc.getLine(cursor.row);
  371. var leftChar = line.substring(cursor.column-1, cursor.column);
  372. var rightChar = line.substring(cursor.column, cursor.column + 1);
  373. var token = session.getTokenAt(cursor.row, cursor.column);
  374. var rightToken = session.getTokenAt(cursor.row, cursor.column + 1);
  375. if (leftChar == "\\" && token && /escape/.test(token.type))
  376. return null;
  377. var stringBefore = token && /string/.test(token.type);
  378. var stringAfter = !rightToken || /string/.test(rightToken.type);
  379. var pair;
  380. if (rightChar == quote) {
  381. pair = stringBefore !== stringAfter;
  382. } else {
  383. if (stringBefore && !stringAfter)
  384. return null; // wrap string with different quote
  385. if (stringBefore && stringAfter)
  386. return null; // do not pair quotes inside strings
  387. var wordRe = session.$mode.tokenRe;
  388. wordRe.lastIndex = 0;
  389. var isWordBefore = wordRe.test(leftChar);
  390. wordRe.lastIndex = 0;
  391. var isWordAfter = wordRe.test(leftChar);
  392. if (isWordBefore || isWordAfter)
  393. return null; // before or after alphanumeric
  394. if (rightChar && !/[\s;,.})\]\\]/.test(rightChar))
  395. return null; // there is rightChar and it isn't closing
  396. pair = true;
  397. }
  398. return {
  399. text: pair ? quote + quote : "",
  400. selection: [1,1]
  401. };
  402. }
  403. }
  404. });
  405. this.add("string_dquotes", "deletion", function(state, action, editor, session, range) {
  406. var selected = session.doc.getTextRange(range);
  407. if (!range.isMultiLine() && (selected == '"' || selected == "'")) {
  408. initContext(editor);
  409. var line = session.doc.getLine(range.start.row);
  410. var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
  411. if (rightChar == selected) {
  412. range.end.column++;
  413. return range;
  414. }
  415. }
  416. });
  417. };
  418. CstyleBehaviour.isSaneInsertion = function(editor, session) {
  419. var cursor = editor.getCursorPosition();
  420. var iterator = new TokenIterator(session, cursor.row, cursor.column);
  421. if (!this.$matchTokenType(iterator.getCurrentToken() || "text", SAFE_INSERT_IN_TOKENS)) {
  422. var iterator2 = new TokenIterator(session, cursor.row, cursor.column + 1);
  423. if (!this.$matchTokenType(iterator2.getCurrentToken() || "text", SAFE_INSERT_IN_TOKENS))
  424. return false;
  425. }
  426. iterator.stepForward();
  427. return iterator.getCurrentTokenRow() !== cursor.row ||
  428. this.$matchTokenType(iterator.getCurrentToken() || "text", SAFE_INSERT_BEFORE_TOKENS);
  429. };
  430. CstyleBehaviour.$matchTokenType = function(token, types) {
  431. return types.indexOf(token.type || token) > -1;
  432. };
  433. CstyleBehaviour.recordAutoInsert = function(editor, session, bracket) {
  434. var cursor = editor.getCursorPosition();
  435. var line = session.doc.getLine(cursor.row);
  436. if (!this.isAutoInsertedClosing(cursor, line, context.autoInsertedLineEnd[0]))
  437. context.autoInsertedBrackets = 0;
  438. context.autoInsertedRow = cursor.row;
  439. context.autoInsertedLineEnd = bracket + line.substr(cursor.column);
  440. context.autoInsertedBrackets++;
  441. };
  442. CstyleBehaviour.recordMaybeInsert = function(editor, session, bracket) {
  443. var cursor = editor.getCursorPosition();
  444. var line = session.doc.getLine(cursor.row);
  445. if (!this.isMaybeInsertedClosing(cursor, line))
  446. context.maybeInsertedBrackets = 0;
  447. context.maybeInsertedRow = cursor.row;
  448. context.maybeInsertedLineStart = line.substr(0, cursor.column) + bracket;
  449. context.maybeInsertedLineEnd = line.substr(cursor.column);
  450. context.maybeInsertedBrackets++;
  451. };
  452. CstyleBehaviour.isAutoInsertedClosing = function(cursor, line, bracket) {
  453. return context.autoInsertedBrackets > 0 &&
  454. cursor.row === context.autoInsertedRow &&
  455. bracket === context.autoInsertedLineEnd[0] &&
  456. line.substr(cursor.column) === context.autoInsertedLineEnd;
  457. };
  458. CstyleBehaviour.isMaybeInsertedClosing = function(cursor, line) {
  459. return context.maybeInsertedBrackets > 0 &&
  460. cursor.row === context.maybeInsertedRow &&
  461. line.substr(cursor.column) === context.maybeInsertedLineEnd &&
  462. line.substr(0, cursor.column) == context.maybeInsertedLineStart;
  463. };
  464. CstyleBehaviour.popAutoInsertedClosing = function() {
  465. context.autoInsertedLineEnd = context.autoInsertedLineEnd.substr(1);
  466. context.autoInsertedBrackets--;
  467. };
  468. CstyleBehaviour.clearMaybeInsertedClosing = function() {
  469. if (context) {
  470. context.maybeInsertedBrackets = 0;
  471. context.maybeInsertedRow = -1;
  472. }
  473. };
  474. oop.inherits(CstyleBehaviour, Behaviour);
  475. exports.CstyleBehaviour = CstyleBehaviour;
  476. });
  477. ace.define("ace/mode/folding/cstyle",["require","exports","module","ace/lib/oop","ace/range","ace/mode/folding/fold_mode"], function(require, exports, module) {
  478. "use strict";
  479. var oop = require("../../lib/oop");
  480. var Range = require("../../range").Range;
  481. var BaseFoldMode = require("./fold_mode").FoldMode;
  482. var FoldMode = exports.FoldMode = function(commentRegex) {
  483. if (commentRegex) {
  484. this.foldingStartMarker = new RegExp(
  485. this.foldingStartMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.start)
  486. );
  487. this.foldingStopMarker = new RegExp(
  488. this.foldingStopMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.end)
  489. );
  490. }
  491. };
  492. oop.inherits(FoldMode, BaseFoldMode);
  493. (function() {
  494. this.foldingStartMarker = /(\{|\[)[^\}\]]*$|^\s*(\/\*)/;
  495. this.foldingStopMarker = /^[^\[\{]*(\}|\])|^[\s\*]*(\*\/)/;
  496. this.singleLineBlockCommentRe= /^\s*(\/\*).*\*\/\s*$/;
  497. this.tripleStarBlockCommentRe = /^\s*(\/\*\*\*).*\*\/\s*$/;
  498. this.startRegionRe = /^\s*(\/\*|\/\/)#region\b/;
  499. this._getFoldWidgetBase = this.getFoldWidget;
  500. this.getFoldWidget = function(session, foldStyle, row) {
  501. var line = session.getLine(row);
  502. if (this.singleLineBlockCommentRe.test(line)) {
  503. if (!this.startRegionRe.test(line) && !this.tripleStarBlockCommentRe.test(line))
  504. return "";
  505. }
  506. var fw = this._getFoldWidgetBase(session, foldStyle, row);
  507. if (!fw && this.startRegionRe.test(line))
  508. return "start"; // lineCommentRegionStart
  509. return fw;
  510. };
  511. this.getFoldWidgetRange = function(session, foldStyle, row, forceMultiline) {
  512. var line = session.getLine(row);
  513. if (this.startRegionRe.test(line))
  514. return this.getCommentRegionBlock(session, line, row);
  515. var match = line.match(this.foldingStartMarker);
  516. if (match) {
  517. var i = match.index;
  518. if (match[1])
  519. return this.openingBracketBlock(session, match[1], row, i);
  520. var range = session.getCommentFoldRange(row, i + match[0].length, 1);
  521. if (range && !range.isMultiLine()) {
  522. if (forceMultiline) {
  523. range = this.getSectionRange(session, row);
  524. } else if (foldStyle != "all")
  525. range = null;
  526. }
  527. return range;
  528. }
  529. if (foldStyle === "markbegin")
  530. return;
  531. var match = line.match(this.foldingStopMarker);
  532. if (match) {
  533. var i = match.index + match[0].length;
  534. if (match[1])
  535. return this.closingBracketBlock(session, match[1], row, i);
  536. return session.getCommentFoldRange(row, i, -1);
  537. }
  538. };
  539. this.getSectionRange = function(session, row) {
  540. var line = session.getLine(row);
  541. var startIndent = line.search(/\S/);
  542. var startRow = row;
  543. var startColumn = line.length;
  544. row = row + 1;
  545. var endRow = row;
  546. var maxRow = session.getLength();
  547. while (++row < maxRow) {
  548. line = session.getLine(row);
  549. var indent = line.search(/\S/);
  550. if (indent === -1)
  551. continue;
  552. if (startIndent > indent)
  553. break;
  554. var subRange = this.getFoldWidgetRange(session, "all", row);
  555. if (subRange) {
  556. if (subRange.start.row <= startRow) {
  557. break;
  558. } else if (subRange.isMultiLine()) {
  559. row = subRange.end.row;
  560. } else if (startIndent == indent) {
  561. break;
  562. }
  563. }
  564. endRow = row;
  565. }
  566. return new Range(startRow, startColumn, endRow, session.getLine(endRow).length);
  567. };
  568. this.getCommentRegionBlock = function(session, line, row) {
  569. var startColumn = line.search(/\s*$/);
  570. var maxRow = session.getLength();
  571. var startRow = row;
  572. var re = /^\s*(?:\/\*|\/\/)#(end)?region\b/;
  573. var depth = 1;
  574. while (++row < maxRow) {
  575. line = session.getLine(row);
  576. var m = re.exec(line);
  577. if (!m) continue;
  578. if (m[1]) depth--;
  579. else depth++;
  580. if (!depth) break;
  581. }
  582. var endRow = row;
  583. if (endRow > startRow) {
  584. return new Range(startRow, startColumn, endRow, line.length);
  585. }
  586. };
  587. }).call(FoldMode.prototype);
  588. });
  589. ace.define("ace/mode/folding/csharp",["require","exports","module","ace/lib/oop","ace/range","ace/mode/folding/cstyle"], function(require, exports, module) {
  590. "use strict";
  591. var oop = require("../../lib/oop");
  592. var Range = require("../../range").Range;
  593. var CFoldMode = require("./cstyle").FoldMode;
  594. var FoldMode = exports.FoldMode = function(commentRegex) {
  595. if (commentRegex) {
  596. this.foldingStartMarker = new RegExp(
  597. this.foldingStartMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.start)
  598. );
  599. this.foldingStopMarker = new RegExp(
  600. this.foldingStopMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.end)
  601. );
  602. }
  603. };
  604. oop.inherits(FoldMode, CFoldMode);
  605. (function() {
  606. this.usingRe = /^\s*using \S/;
  607. this.getFoldWidgetRangeBase = this.getFoldWidgetRange;
  608. this.getFoldWidgetBase = this.getFoldWidget;
  609. this.getFoldWidget = function(session, foldStyle, row) {
  610. var fw = this.getFoldWidgetBase(session, foldStyle, row);
  611. if (!fw) {
  612. var line = session.getLine(row);
  613. if (/^\s*#region\b/.test(line))
  614. return "start";
  615. var usingRe = this.usingRe;
  616. if (usingRe.test(line)) {
  617. var prev = session.getLine(row - 1);
  618. var next = session.getLine(row + 1);
  619. if (!usingRe.test(prev) && usingRe.test(next))
  620. return "start"
  621. }
  622. }
  623. return fw;
  624. };
  625. this.getFoldWidgetRange = function(session, foldStyle, row) {
  626. var range = this.getFoldWidgetRangeBase(session, foldStyle, row);
  627. if (range)
  628. return range;
  629. var line = session.getLine(row);
  630. if (this.usingRe.test(line))
  631. return this.getUsingStatementBlock(session, line, row);
  632. if (/^\s*#region\b/.test(line))
  633. return this.getRegionBlock(session, line, row);
  634. };
  635. this.getUsingStatementBlock = function(session, line, row) {
  636. var startColumn = line.match(this.usingRe)[0].length - 1;
  637. var maxRow = session.getLength();
  638. var startRow = row;
  639. var endRow = row;
  640. while (++row < maxRow) {
  641. line = session.getLine(row);
  642. if (/^\s*$/.test(line))
  643. continue;
  644. if (!this.usingRe.test(line))
  645. break;
  646. endRow = row;
  647. }
  648. if (endRow > startRow) {
  649. var endColumn = session.getLine(endRow).length;
  650. return new Range(startRow, startColumn, endRow, endColumn);
  651. }
  652. };
  653. this.getRegionBlock = function(session, line, row) {
  654. var startColumn = line.search(/\s*$/);
  655. var maxRow = session.getLength();
  656. var startRow = row;
  657. var re = /^\s*#(end)?region\b/;
  658. var depth = 1;
  659. while (++row < maxRow) {
  660. line = session.getLine(row);
  661. var m = re.exec(line);
  662. if (!m)
  663. continue;
  664. if (m[1])
  665. depth--;
  666. else
  667. depth++;
  668. if (!depth)
  669. break;
  670. }
  671. var endRow = row;
  672. if (endRow > startRow) {
  673. return new Range(startRow, startColumn, endRow, line.length);
  674. }
  675. };
  676. }).call(FoldMode.prototype);
  677. });
  678. ace.define("ace/mode/csharp",["require","exports","module","ace/lib/oop","ace/mode/text","ace/mode/csharp_highlight_rules","ace/mode/matching_brace_outdent","ace/mode/behaviour/cstyle","ace/mode/folding/csharp"], function(require, exports, module) {
  679. "use strict";
  680. var oop = require("../lib/oop");
  681. var TextMode = require("./text").Mode;
  682. var CSharpHighlightRules = require("./csharp_highlight_rules").CSharpHighlightRules;
  683. var MatchingBraceOutdent = require("./matching_brace_outdent").MatchingBraceOutdent;
  684. var CstyleBehaviour = require("./behaviour/cstyle").CstyleBehaviour;
  685. var CStyleFoldMode = require("./folding/csharp").FoldMode;
  686. var Mode = function() {
  687. this.HighlightRules = CSharpHighlightRules;
  688. this.$outdent = new MatchingBraceOutdent();
  689. this.$behaviour = new CstyleBehaviour();
  690. this.foldingRules = new CStyleFoldMode();
  691. };
  692. oop.inherits(Mode, TextMode);
  693. (function() {
  694. this.lineCommentStart = "//";
  695. this.blockComment = {start: "/*", end: "*/"};
  696. this.getNextLineIndent = function(state, line, tab) {
  697. var indent = this.$getIndent(line);
  698. var tokenizedLine = this.getTokenizer().getLineTokens(line, state);
  699. var tokens = tokenizedLine.tokens;
  700. if (tokens.length && tokens[tokens.length-1].type == "comment") {
  701. return indent;
  702. }
  703. if (state == "start") {
  704. var match = line.match(/^.*[\{\(\[]\s*$/);
  705. if (match) {
  706. indent += tab;
  707. }
  708. }
  709. return indent;
  710. };
  711. this.checkOutdent = function(state, line, input) {
  712. return this.$outdent.checkOutdent(line, input);
  713. };
  714. this.autoOutdent = function(state, doc, row) {
  715. this.$outdent.autoOutdent(doc, row);
  716. };
  717. this.createWorker = function(session) {
  718. return null;
  719. };
  720. this.$id = "ace/mode/csharp";
  721. }).call(Mode.prototype);
  722. exports.Mode = Mode;
  723. });