mode-csharp.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496
  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 : "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. token : "comment", // comment spanning whole line
  120. regex : ".+"
  121. }
  122. ]
  123. };
  124. this.embedRules(DocCommentHighlightRules, "doc-",
  125. [ DocCommentHighlightRules.getEndRule("start") ]);
  126. this.normalizeRules();
  127. };
  128. oop.inherits(CSharpHighlightRules, TextHighlightRules);
  129. exports.CSharpHighlightRules = CSharpHighlightRules;
  130. });
  131. ace.define("ace/mode/matching_brace_outdent",["require","exports","module","ace/range"], function(require, exports, module) {
  132. "use strict";
  133. var Range = require("../range").Range;
  134. var MatchingBraceOutdent = function() {};
  135. (function() {
  136. this.checkOutdent = function(line, input) {
  137. if (! /^\s+$/.test(line))
  138. return false;
  139. return /^\s*\}/.test(input);
  140. };
  141. this.autoOutdent = function(doc, row) {
  142. var line = doc.getLine(row);
  143. var match = line.match(/^(\s*\})/);
  144. if (!match) return 0;
  145. var column = match[1].length;
  146. var openBracePos = doc.findMatchingBracket({row: row, column: column});
  147. if (!openBracePos || openBracePos.row == row) return 0;
  148. var indent = this.$getIndent(doc.getLine(openBracePos.row));
  149. doc.replace(new Range(row, 0, row, column-1), indent);
  150. };
  151. this.$getIndent = function(line) {
  152. return line.match(/^\s*/)[0];
  153. };
  154. }).call(MatchingBraceOutdent.prototype);
  155. exports.MatchingBraceOutdent = MatchingBraceOutdent;
  156. });
  157. ace.define("ace/mode/folding/cstyle",["require","exports","module","ace/lib/oop","ace/range","ace/mode/folding/fold_mode"], function(require, exports, module) {
  158. "use strict";
  159. var oop = require("../../lib/oop");
  160. var Range = require("../../range").Range;
  161. var BaseFoldMode = require("./fold_mode").FoldMode;
  162. var FoldMode = exports.FoldMode = function(commentRegex) {
  163. if (commentRegex) {
  164. this.foldingStartMarker = new RegExp(
  165. this.foldingStartMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.start)
  166. );
  167. this.foldingStopMarker = new RegExp(
  168. this.foldingStopMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.end)
  169. );
  170. }
  171. };
  172. oop.inherits(FoldMode, BaseFoldMode);
  173. (function() {
  174. this.foldingStartMarker = /(\{|\[)[^\}\]]*$|^\s*(\/\*)/;
  175. this.foldingStopMarker = /^[^\[\{]*(\}|\])|^[\s\*]*(\*\/)/;
  176. this.singleLineBlockCommentRe= /^\s*(\/\*).*\*\/\s*$/;
  177. this.tripleStarBlockCommentRe = /^\s*(\/\*\*\*).*\*\/\s*$/;
  178. this.startRegionRe = /^\s*(\/\*|\/\/)#?region\b/;
  179. this._getFoldWidgetBase = this.getFoldWidget;
  180. this.getFoldWidget = function(session, foldStyle, row) {
  181. var line = session.getLine(row);
  182. if (this.singleLineBlockCommentRe.test(line)) {
  183. if (!this.startRegionRe.test(line) && !this.tripleStarBlockCommentRe.test(line))
  184. return "";
  185. }
  186. var fw = this._getFoldWidgetBase(session, foldStyle, row);
  187. if (!fw && this.startRegionRe.test(line))
  188. return "start"; // lineCommentRegionStart
  189. return fw;
  190. };
  191. this.getFoldWidgetRange = function(session, foldStyle, row, forceMultiline) {
  192. var line = session.getLine(row);
  193. if (this.startRegionRe.test(line))
  194. return this.getCommentRegionBlock(session, line, row);
  195. var match = line.match(this.foldingStartMarker);
  196. if (match) {
  197. var i = match.index;
  198. if (match[1])
  199. return this.openingBracketBlock(session, match[1], row, i);
  200. var range = session.getCommentFoldRange(row, i + match[0].length, 1);
  201. if (range && !range.isMultiLine()) {
  202. if (forceMultiline) {
  203. range = this.getSectionRange(session, row);
  204. } else if (foldStyle != "all")
  205. range = null;
  206. }
  207. return range;
  208. }
  209. if (foldStyle === "markbegin")
  210. return;
  211. var match = line.match(this.foldingStopMarker);
  212. if (match) {
  213. var i = match.index + match[0].length;
  214. if (match[1])
  215. return this.closingBracketBlock(session, match[1], row, i);
  216. return session.getCommentFoldRange(row, i, -1);
  217. }
  218. };
  219. this.getSectionRange = function(session, row) {
  220. var line = session.getLine(row);
  221. var startIndent = line.search(/\S/);
  222. var startRow = row;
  223. var startColumn = line.length;
  224. row = row + 1;
  225. var endRow = row;
  226. var maxRow = session.getLength();
  227. while (++row < maxRow) {
  228. line = session.getLine(row);
  229. var indent = line.search(/\S/);
  230. if (indent === -1)
  231. continue;
  232. if (startIndent > indent)
  233. break;
  234. var subRange = this.getFoldWidgetRange(session, "all", row);
  235. if (subRange) {
  236. if (subRange.start.row <= startRow) {
  237. break;
  238. } else if (subRange.isMultiLine()) {
  239. row = subRange.end.row;
  240. } else if (startIndent == indent) {
  241. break;
  242. }
  243. }
  244. endRow = row;
  245. }
  246. return new Range(startRow, startColumn, endRow, session.getLine(endRow).length);
  247. };
  248. this.getCommentRegionBlock = function(session, line, row) {
  249. var startColumn = line.search(/\s*$/);
  250. var maxRow = session.getLength();
  251. var startRow = row;
  252. var re = /^\s*(?:\/\*|\/\/|--)#?(end)?region\b/;
  253. var depth = 1;
  254. while (++row < maxRow) {
  255. line = session.getLine(row);
  256. var m = re.exec(line);
  257. if (!m) continue;
  258. if (m[1]) depth--;
  259. else depth++;
  260. if (!depth) break;
  261. }
  262. var endRow = row;
  263. if (endRow > startRow) {
  264. return new Range(startRow, startColumn, endRow, line.length);
  265. }
  266. };
  267. }).call(FoldMode.prototype);
  268. });
  269. ace.define("ace/mode/folding/csharp",["require","exports","module","ace/lib/oop","ace/range","ace/mode/folding/cstyle"], function(require, exports, module) {
  270. "use strict";
  271. var oop = require("../../lib/oop");
  272. var Range = require("../../range").Range;
  273. var CFoldMode = require("./cstyle").FoldMode;
  274. var FoldMode = exports.FoldMode = function(commentRegex) {
  275. if (commentRegex) {
  276. this.foldingStartMarker = new RegExp(
  277. this.foldingStartMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.start)
  278. );
  279. this.foldingStopMarker = new RegExp(
  280. this.foldingStopMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.end)
  281. );
  282. }
  283. };
  284. oop.inherits(FoldMode, CFoldMode);
  285. (function() {
  286. this.usingRe = /^\s*using \S/;
  287. this.getFoldWidgetRangeBase = this.getFoldWidgetRange;
  288. this.getFoldWidgetBase = this.getFoldWidget;
  289. this.getFoldWidget = function(session, foldStyle, row) {
  290. var fw = this.getFoldWidgetBase(session, foldStyle, row);
  291. if (!fw) {
  292. var line = session.getLine(row);
  293. if (/^\s*#region\b/.test(line))
  294. return "start";
  295. var usingRe = this.usingRe;
  296. if (usingRe.test(line)) {
  297. var prev = session.getLine(row - 1);
  298. var next = session.getLine(row + 1);
  299. if (!usingRe.test(prev) && usingRe.test(next))
  300. return "start"
  301. }
  302. }
  303. return fw;
  304. };
  305. this.getFoldWidgetRange = function(session, foldStyle, row) {
  306. var range = this.getFoldWidgetRangeBase(session, foldStyle, row);
  307. if (range)
  308. return range;
  309. var line = session.getLine(row);
  310. if (this.usingRe.test(line))
  311. return this.getUsingStatementBlock(session, line, row);
  312. if (/^\s*#region\b/.test(line))
  313. return this.getRegionBlock(session, line, row);
  314. };
  315. this.getUsingStatementBlock = function(session, line, row) {
  316. var startColumn = line.match(this.usingRe)[0].length - 1;
  317. var maxRow = session.getLength();
  318. var startRow = row;
  319. var endRow = row;
  320. while (++row < maxRow) {
  321. line = session.getLine(row);
  322. if (/^\s*$/.test(line))
  323. continue;
  324. if (!this.usingRe.test(line))
  325. break;
  326. endRow = row;
  327. }
  328. if (endRow > startRow) {
  329. var endColumn = session.getLine(endRow).length;
  330. return new Range(startRow, startColumn, endRow, endColumn);
  331. }
  332. };
  333. this.getRegionBlock = function(session, line, row) {
  334. var startColumn = line.search(/\s*$/);
  335. var maxRow = session.getLength();
  336. var startRow = row;
  337. var re = /^\s*#(end)?region\b/;
  338. var depth = 1;
  339. while (++row < maxRow) {
  340. line = session.getLine(row);
  341. var m = re.exec(line);
  342. if (!m)
  343. continue;
  344. if (m[1])
  345. depth--;
  346. else
  347. depth++;
  348. if (!depth)
  349. break;
  350. }
  351. var endRow = row;
  352. if (endRow > startRow) {
  353. return new Range(startRow, startColumn, endRow, line.length);
  354. }
  355. };
  356. }).call(FoldMode.prototype);
  357. });
  358. 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) {
  359. "use strict";
  360. var oop = require("../lib/oop");
  361. var TextMode = require("./text").Mode;
  362. var CSharpHighlightRules = require("./csharp_highlight_rules").CSharpHighlightRules;
  363. var MatchingBraceOutdent = require("./matching_brace_outdent").MatchingBraceOutdent;
  364. var CstyleBehaviour = require("./behaviour/cstyle").CstyleBehaviour;
  365. var CStyleFoldMode = require("./folding/csharp").FoldMode;
  366. var Mode = function() {
  367. this.HighlightRules = CSharpHighlightRules;
  368. this.$outdent = new MatchingBraceOutdent();
  369. this.$behaviour = new CstyleBehaviour();
  370. this.foldingRules = new CStyleFoldMode();
  371. };
  372. oop.inherits(Mode, TextMode);
  373. (function() {
  374. this.lineCommentStart = "//";
  375. this.blockComment = {start: "/*", end: "*/"};
  376. this.getNextLineIndent = function(state, line, tab) {
  377. var indent = this.$getIndent(line);
  378. var tokenizedLine = this.getTokenizer().getLineTokens(line, state);
  379. var tokens = tokenizedLine.tokens;
  380. if (tokens.length && tokens[tokens.length-1].type == "comment") {
  381. return indent;
  382. }
  383. if (state == "start") {
  384. var match = line.match(/^.*[\{\(\[]\s*$/);
  385. if (match) {
  386. indent += tab;
  387. }
  388. }
  389. return indent;
  390. };
  391. this.checkOutdent = function(state, line, input) {
  392. return this.$outdent.checkOutdent(line, input);
  393. };
  394. this.autoOutdent = function(state, doc, row) {
  395. this.$outdent.autoOutdent(doc, row);
  396. };
  397. this.createWorker = function(session) {
  398. return null;
  399. };
  400. this.$id = "ace/mode/csharp";
  401. }).call(Mode.prototype);
  402. exports.Mode = Mode;
  403. });