mode-csharp.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502
  1. define("ace/mode/doc_comment_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 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. define("ace/mode/csharp_highlight_rules",["ace_require","exports","module","ace/lib/oop","ace/mode/doc_comment_highlight_rules","ace/mode/text_highlight_rules"], function(ace_require, exports, module) {
  42. "use strict";
  43. var oop = ace_require("../lib/oop");
  44. var DocCommentHighlightRules = ace_require("./doc_comment_highlight_rules").DocCommentHighlightRules;
  45. var TextHighlightRules = ace_require("./text_highlight_rules").TextHighlightRules;
  46. var CSharpHighlightRules = function() {
  47. var keywordMapper = this.createKeywordMapper({
  48. "variable.language": "this",
  49. "keyword": "abstract|async|await|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|partial|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 : "string", start : /\$"/, end : '"|$', next: [
  77. {token: "constant.language.escape", regex: /\\(:?$)|{{/},
  78. {token: "constant.language.escape", regex: /\\(:?u[\da-fA-F]+|x[\da-fA-F]+|[tbrf'"n])/},
  79. {token: "invalid", regex: /\\./}
  80. ]
  81. }, {
  82. token : "constant.numeric", // hex
  83. regex : "0[xX][0-9a-fA-F]+\\b"
  84. }, {
  85. token : "constant.numeric", // float
  86. regex : "[+-]?\\d+(?:(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)?\\b"
  87. }, {
  88. token : "constant.language.boolean",
  89. regex : "(?:true|false)\\b"
  90. }, {
  91. token : keywordMapper,
  92. regex : "[a-zA-Z_$][a-zA-Z0-9_$]*\\b"
  93. }, {
  94. token : "keyword.operator",
  95. regex : "!|\\$|%|&|\\*|\\-\\-|\\-|\\+\\+|\\+|~|===|==|=|!=|!==|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\\|\\||\\?\\:|\\*=|%=|\\+=|\\-=|&=|\\^=|\\b(?:in|instanceof|new|delete|typeof|void)"
  96. }, {
  97. token : "keyword",
  98. regex : "^\\s*#(if|else|elif|endif|define|undef|warning|error|line|region|endregion|pragma)"
  99. }, {
  100. token : "punctuation.operator",
  101. regex : "\\?|\\:|\\,|\\;|\\."
  102. }, {
  103. token : "paren.lparen",
  104. regex : "[[({]"
  105. }, {
  106. token : "paren.rparen",
  107. regex : "[\\])}]"
  108. }, {
  109. token : "text",
  110. regex : "\\s+"
  111. }
  112. ],
  113. "comment" : [
  114. {
  115. token : "comment", // closing comment
  116. regex : "\\*\\/",
  117. next : "start"
  118. }, {
  119. defaultToken : "comment"
  120. }
  121. ]
  122. };
  123. this.embedRules(DocCommentHighlightRules, "doc-",
  124. [ DocCommentHighlightRules.getEndRule("start") ]);
  125. this.normalizeRules();
  126. };
  127. oop.inherits(CSharpHighlightRules, TextHighlightRules);
  128. exports.CSharpHighlightRules = CSharpHighlightRules;
  129. });
  130. define("ace/mode/matching_brace_outdent",["ace_require","exports","module","ace/range"], function(ace_require, exports, module) {
  131. "use strict";
  132. var Range = ace_require("../range").Range;
  133. var MatchingBraceOutdent = function() {};
  134. (function() {
  135. this.checkOutdent = function(line, input) {
  136. if (! /^\s+$/.test(line))
  137. return false;
  138. return /^\s*\}/.test(input);
  139. };
  140. this.autoOutdent = function(doc, row) {
  141. var line = doc.getLine(row);
  142. var match = line.match(/^(\s*\})/);
  143. if (!match) return 0;
  144. var column = match[1].length;
  145. var openBracePos = doc.findMatchingBracket({row: row, column: column});
  146. if (!openBracePos || openBracePos.row == row) return 0;
  147. var indent = this.$getIndent(doc.getLine(openBracePos.row));
  148. doc.replace(new Range(row, 0, row, column-1), indent);
  149. };
  150. this.$getIndent = function(line) {
  151. return line.match(/^\s*/)[0];
  152. };
  153. }).call(MatchingBraceOutdent.prototype);
  154. exports.MatchingBraceOutdent = MatchingBraceOutdent;
  155. });
  156. define("ace/mode/folding/cstyle",["ace_require","exports","module","ace/lib/oop","ace/range","ace/mode/folding/fold_mode"], function(ace_require, exports, module) {
  157. "use strict";
  158. var oop = ace_require("../../lib/oop");
  159. var Range = ace_require("../../range").Range;
  160. var BaseFoldMode = ace_require("./fold_mode").FoldMode;
  161. var FoldMode = exports.FoldMode = function(commentRegex) {
  162. if (commentRegex) {
  163. this.foldingStartMarker = new RegExp(
  164. this.foldingStartMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.start)
  165. );
  166. this.foldingStopMarker = new RegExp(
  167. this.foldingStopMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.end)
  168. );
  169. }
  170. };
  171. oop.inherits(FoldMode, BaseFoldMode);
  172. (function() {
  173. this.foldingStartMarker = /([\{\[\(])[^\}\]\)]*$|^\s*(\/\*)/;
  174. this.foldingStopMarker = /^[^\[\{\(]*([\}\]\)])|^[\s\*]*(\*\/)/;
  175. this.singleLineBlockCommentRe= /^\s*(\/\*).*\*\/\s*$/;
  176. this.tripleStarBlockCommentRe = /^\s*(\/\*\*\*).*\*\/\s*$/;
  177. this.startRegionRe = /^\s*(\/\*|\/\/)#?region\b/;
  178. this._getFoldWidgetBase = this.getFoldWidget;
  179. this.getFoldWidget = function(session, foldStyle, row) {
  180. var line = session.getLine(row);
  181. if (this.singleLineBlockCommentRe.test(line)) {
  182. if (!this.startRegionRe.test(line) && !this.tripleStarBlockCommentRe.test(line))
  183. return "";
  184. }
  185. var fw = this._getFoldWidgetBase(session, foldStyle, row);
  186. if (!fw && this.startRegionRe.test(line))
  187. return "start"; // lineCommentRegionStart
  188. return fw;
  189. };
  190. this.getFoldWidgetRange = function(session, foldStyle, row, forceMultiline) {
  191. var line = session.getLine(row);
  192. if (this.startRegionRe.test(line))
  193. return this.getCommentRegionBlock(session, line, row);
  194. var match = line.match(this.foldingStartMarker);
  195. if (match) {
  196. var i = match.index;
  197. if (match[1])
  198. return this.openingBracketBlock(session, match[1], row, i);
  199. var range = session.getCommentFoldRange(row, i + match[0].length, 1);
  200. if (range && !range.isMultiLine()) {
  201. if (forceMultiline) {
  202. range = this.getSectionRange(session, row);
  203. } else if (foldStyle != "all")
  204. range = null;
  205. }
  206. return range;
  207. }
  208. if (foldStyle === "markbegin")
  209. return;
  210. var match = line.match(this.foldingStopMarker);
  211. if (match) {
  212. var i = match.index + match[0].length;
  213. if (match[1])
  214. return this.closingBracketBlock(session, match[1], row, i);
  215. return session.getCommentFoldRange(row, i, -1);
  216. }
  217. };
  218. this.getSectionRange = function(session, row) {
  219. var line = session.getLine(row);
  220. var startIndent = line.search(/\S/);
  221. var startRow = row;
  222. var startColumn = line.length;
  223. row = row + 1;
  224. var endRow = row;
  225. var maxRow = session.getLength();
  226. while (++row < maxRow) {
  227. line = session.getLine(row);
  228. var indent = line.search(/\S/);
  229. if (indent === -1)
  230. continue;
  231. if (startIndent > indent)
  232. break;
  233. var subRange = this.getFoldWidgetRange(session, "all", row);
  234. if (subRange) {
  235. if (subRange.start.row <= startRow) {
  236. break;
  237. } else if (subRange.isMultiLine()) {
  238. row = subRange.end.row;
  239. } else if (startIndent == indent) {
  240. break;
  241. }
  242. }
  243. endRow = row;
  244. }
  245. return new Range(startRow, startColumn, endRow, session.getLine(endRow).length);
  246. };
  247. this.getCommentRegionBlock = function(session, line, row) {
  248. var startColumn = line.search(/\s*$/);
  249. var maxRow = session.getLength();
  250. var startRow = row;
  251. var re = /^\s*(?:\/\*|\/\/|--)#?(end)?region\b/;
  252. var depth = 1;
  253. while (++row < maxRow) {
  254. line = session.getLine(row);
  255. var m = re.exec(line);
  256. if (!m) continue;
  257. if (m[1]) depth--;
  258. else depth++;
  259. if (!depth) break;
  260. }
  261. var endRow = row;
  262. if (endRow > startRow) {
  263. return new Range(startRow, startColumn, endRow, line.length);
  264. }
  265. };
  266. }).call(FoldMode.prototype);
  267. });
  268. define("ace/mode/folding/csharp",["ace_require","exports","module","ace/lib/oop","ace/range","ace/mode/folding/cstyle"], function(ace_require, exports, module) {
  269. "use strict";
  270. var oop = ace_require("../../lib/oop");
  271. var Range = ace_require("../../range").Range;
  272. var CFoldMode = ace_require("./cstyle").FoldMode;
  273. var FoldMode = exports.FoldMode = function(commentRegex) {
  274. if (commentRegex) {
  275. this.foldingStartMarker = new RegExp(
  276. this.foldingStartMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.start)
  277. );
  278. this.foldingStopMarker = new RegExp(
  279. this.foldingStopMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.end)
  280. );
  281. }
  282. };
  283. oop.inherits(FoldMode, CFoldMode);
  284. (function() {
  285. this.usingRe = /^\s*using \S/;
  286. this.getFoldWidgetRangeBase = this.getFoldWidgetRange;
  287. this.getFoldWidgetBase = this.getFoldWidget;
  288. this.getFoldWidget = function(session, foldStyle, row) {
  289. var fw = this.getFoldWidgetBase(session, foldStyle, row);
  290. if (!fw) {
  291. var line = session.getLine(row);
  292. if (/^\s*#region\b/.test(line))
  293. return "start";
  294. var usingRe = this.usingRe;
  295. if (usingRe.test(line)) {
  296. var prev = session.getLine(row - 1);
  297. var next = session.getLine(row + 1);
  298. if (!usingRe.test(prev) && usingRe.test(next))
  299. return "start";
  300. }
  301. }
  302. return fw;
  303. };
  304. this.getFoldWidgetRange = function(session, foldStyle, row) {
  305. var range = this.getFoldWidgetRangeBase(session, foldStyle, row);
  306. if (range)
  307. return range;
  308. var line = session.getLine(row);
  309. if (this.usingRe.test(line))
  310. return this.getUsingStatementBlock(session, line, row);
  311. if (/^\s*#region\b/.test(line))
  312. return this.getRegionBlock(session, line, row);
  313. };
  314. this.getUsingStatementBlock = function(session, line, row) {
  315. var startColumn = line.match(this.usingRe)[0].length - 1;
  316. var maxRow = session.getLength();
  317. var startRow = row;
  318. var endRow = row;
  319. while (++row < maxRow) {
  320. line = session.getLine(row);
  321. if (/^\s*$/.test(line))
  322. continue;
  323. if (!this.usingRe.test(line))
  324. break;
  325. endRow = row;
  326. }
  327. if (endRow > startRow) {
  328. var endColumn = session.getLine(endRow).length;
  329. return new Range(startRow, startColumn, endRow, endColumn);
  330. }
  331. };
  332. this.getRegionBlock = function(session, line, row) {
  333. var startColumn = line.search(/\s*$/);
  334. var maxRow = session.getLength();
  335. var startRow = row;
  336. var re = /^\s*#(end)?region\b/;
  337. var depth = 1;
  338. while (++row < maxRow) {
  339. line = session.getLine(row);
  340. var m = re.exec(line);
  341. if (!m)
  342. continue;
  343. if (m[1])
  344. depth--;
  345. else
  346. depth++;
  347. if (!depth)
  348. break;
  349. }
  350. var endRow = row;
  351. if (endRow > startRow) {
  352. return new Range(startRow, startColumn, endRow, line.length);
  353. }
  354. };
  355. }).call(FoldMode.prototype);
  356. });
  357. define("ace/mode/csharp",["ace_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(ace_require, exports, module) {
  358. "use strict";
  359. var oop = ace_require("../lib/oop");
  360. var TextMode = ace_require("./text").Mode;
  361. var CSharpHighlightRules = ace_require("./csharp_highlight_rules").CSharpHighlightRules;
  362. var MatchingBraceOutdent = ace_require("./matching_brace_outdent").MatchingBraceOutdent;
  363. var CstyleBehaviour = ace_require("./behaviour/cstyle").CstyleBehaviour;
  364. var CStyleFoldMode = ace_require("./folding/csharp").FoldMode;
  365. var Mode = function() {
  366. this.HighlightRules = CSharpHighlightRules;
  367. this.$outdent = new MatchingBraceOutdent();
  368. this.$behaviour = new CstyleBehaviour();
  369. this.foldingRules = new CStyleFoldMode();
  370. };
  371. oop.inherits(Mode, TextMode);
  372. (function() {
  373. this.lineCommentStart = "//";
  374. this.blockComment = {start: "/*", end: "*/"};
  375. this.getNextLineIndent = function(state, line, tab) {
  376. var indent = this.$getIndent(line);
  377. var tokenizedLine = this.getTokenizer().getLineTokens(line, state);
  378. var tokens = tokenizedLine.tokens;
  379. if (tokens.length && tokens[tokens.length-1].type == "comment") {
  380. return indent;
  381. }
  382. if (state == "start") {
  383. var match = line.match(/^.*[\{\(\[]\s*$/);
  384. if (match) {
  385. indent += tab;
  386. }
  387. }
  388. return indent;
  389. };
  390. this.checkOutdent = function(state, line, input) {
  391. return this.$outdent.checkOutdent(line, input);
  392. };
  393. this.autoOutdent = function(state, doc, row) {
  394. this.$outdent.autoOutdent(doc, row);
  395. };
  396. this.createWorker = function(session) {
  397. return null;
  398. };
  399. this.$id = "ace/mode/csharp";
  400. }).call(Mode.prototype);
  401. exports.Mode = Mode;
  402. }); (function() {
  403. window.ace_require(["ace/mode/csharp"], function(m) {
  404. if (typeof module == "object" && typeof exports == "object" && module) {
  405. module.exports = m;
  406. }
  407. });
  408. })();