1
define('ace/mode/csharp', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/text', 'ace/tokenizer', 'ace/mode/csharp_highlight_rules', 'ace/mode/matching_brace_outdent', 'ace/mode/behaviour/cstyle', 'ace/mode/folding/cstyle'], function(require, exports, module) {
4
var oop = require("../lib/oop");
5
var TextMode = require("./text").Mode;
6
var Tokenizer = require("../tokenizer").Tokenizer;
7
var CSharpHighlightRules = require("./csharp_highlight_rules").CSharpHighlightRules;
8
var MatchingBraceOutdent = require("./matching_brace_outdent").MatchingBraceOutdent;
9
var CstyleBehaviour = require("./behaviour/cstyle").CstyleBehaviour;
10
var CStyleFoldMode = require("./folding/cstyle").FoldMode;
12
var Mode = function() {
13
this.$tokenizer = new Tokenizer(new CSharpHighlightRules().getRules());
14
this.$outdent = new MatchingBraceOutdent();
15
this.$behaviour = new CstyleBehaviour();
16
this.foldingRules = new CStyleFoldMode();
18
oop.inherits(Mode, TextMode);
22
this.lineCommentStart = "//";
23
this.blockComment = {start: "/*", end: "*/"};
25
this.getNextLineIndent = function(state, line, tab) {
26
var indent = this.$getIndent(line);
28
var tokenizedLine = this.$tokenizer.getLineTokens(line, state);
29
var tokens = tokenizedLine.tokens;
31
if (tokens.length && tokens[tokens.length-1].type == "comment") {
35
if (state == "start") {
36
var match = line.match(/^.*[\{\(\[]\s*$/);
45
this.checkOutdent = function(state, line, input) {
46
return this.$outdent.checkOutdent(line, input);
49
this.autoOutdent = function(state, doc, row) {
50
this.$outdent.autoOutdent(doc, row);
54
this.createWorker = function(session) {
58
}).call(Mode.prototype);
62
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) {
65
var oop = require("../lib/oop");
66
var DocCommentHighlightRules = require("./doc_comment_highlight_rules").DocCommentHighlightRules;
67
var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
69
var CSharpHighlightRules = function() {
70
var keywordMapper = this.createKeywordMapper({
71
"variable.language": "this",
72
"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",
73
"constant.language": "null|true|false"
82
DocCommentHighlightRules.getStartRule("doc-start"),
84
token : "comment", // multi line comment
88
token : "string.regexp",
89
regex : "[/](?:(?:\\[(?:\\\\]|[^\\]])+\\])|(?:\\\\/|[^\\]/]))*[/]\\w*\\s*(?=[).,;]|$)"
91
token : "string", // character
92
regex : /'(?:.|\\(:?u[\da-fA-F]+|x[\da-fA-F]+|[tbrf'"n]))'/
94
token : "string", start : '"', end : '"|$', next: [
95
{token: "constant.language.escape", regex: /\\(:?u[\da-fA-F]+|x[\da-fA-F]+|[tbrf'"n])/},
96
{token: "invalid", regex: /\\./}
99
token : "string", start : '@"', end : '"', next:[
100
{token: "constant.language.escape", regex: '""'}
103
token : "constant.numeric", // hex
104
regex : "0[xX][0-9a-fA-F]+\\b"
106
token : "constant.numeric", // float
107
regex : "[+-]?\\d+(?:(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)?\\b"
109
token : "constant.language.boolean",
110
regex : "(?:true|false)\\b"
112
token : keywordMapper,
113
regex : "[a-zA-Z_$][a-zA-Z0-9_$]*\\b"
115
token : "keyword.operator",
116
regex : "!|\\$|%|&|\\*|\\-\\-|\\-|\\+\\+|\\+|~|===|==|=|!=|!==|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\\|\\||\\?\\:|\\*=|%=|\\+=|\\-=|&=|\\^=|\\b(?:in|instanceof|new|delete|typeof|void)"
118
token : "punctuation.operator",
119
regex : "\\?|\\:|\\,|\\;|\\."
121
token : "paren.lparen",
124
token : "paren.rparen",
133
token : "comment", // closing comment
137
token : "comment", // comment spanning whole line
143
this.embedRules(DocCommentHighlightRules, "doc-",
144
[ DocCommentHighlightRules.getEndRule("start") ]);
145
this.normalizeRules();
148
oop.inherits(CSharpHighlightRules, TextHighlightRules);
150
exports.CSharpHighlightRules = CSharpHighlightRules;
153
define('ace/mode/doc_comment_highlight_rules', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/text_highlight_rules'], function(require, exports, module) {
156
var oop = require("../lib/oop");
157
var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
159
var DocCommentHighlightRules = function() {
163
token : "comment.doc.tag",
164
regex : "@[\\w\\d_]+" // TODO: fix email addresses
166
token : "comment.doc.tag",
169
defaultToken : "comment.doc"
174
oop.inherits(DocCommentHighlightRules, TextHighlightRules);
176
DocCommentHighlightRules.getStartRule = function(start) {
178
token : "comment.doc", // doc comment
179
regex : "\\/\\*(?=\\*)",
184
DocCommentHighlightRules.getEndRule = function (start) {
186
token : "comment.doc", // closing comment
193
exports.DocCommentHighlightRules = DocCommentHighlightRules;
197
define('ace/mode/matching_brace_outdent', ['require', 'exports', 'module' , 'ace/range'], function(require, exports, module) {
200
var Range = require("../range").Range;
202
var MatchingBraceOutdent = function() {};
206
this.checkOutdent = function(line, input) {
207
if (! /^\s+$/.test(line))
210
return /^\s*\}/.test(input);
213
this.autoOutdent = function(doc, row) {
214
var line = doc.getLine(row);
215
var match = line.match(/^(\s*\})/);
217
if (!match) return 0;
219
var column = match[1].length;
220
var openBracePos = doc.findMatchingBracket({row: row, column: column});
222
if (!openBracePos || openBracePos.row == row) return 0;
224
var indent = this.$getIndent(doc.getLine(openBracePos.row));
225
doc.replace(new Range(row, 0, row, column-1), indent);
228
this.$getIndent = function(line) {
229
return line.match(/^\s*/)[0];
232
}).call(MatchingBraceOutdent.prototype);
234
exports.MatchingBraceOutdent = MatchingBraceOutdent;
237
define('ace/mode/behaviour/cstyle', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/behaviour', 'ace/token_iterator', 'ace/lib/lang'], function(require, exports, module) {
240
var oop = require("../../lib/oop");
241
var Behaviour = require("../behaviour").Behaviour;
242
var TokenIterator = require("../../token_iterator").TokenIterator;
243
var lang = require("../../lib/lang");
245
var SAFE_INSERT_IN_TOKENS =
246
["text", "paren.rparen", "punctuation.operator"];
247
var SAFE_INSERT_BEFORE_TOKENS =
248
["text", "paren.rparen", "punctuation.operator", "comment"];
251
var autoInsertedBrackets = 0;
252
var autoInsertedRow = -1;
253
var autoInsertedLineEnd = "";
254
var maybeInsertedBrackets = 0;
255
var maybeInsertedRow = -1;
256
var maybeInsertedLineStart = "";
257
var maybeInsertedLineEnd = "";
259
var CstyleBehaviour = function () {
261
CstyleBehaviour.isSaneInsertion = function(editor, session) {
262
var cursor = editor.getCursorPosition();
263
var iterator = new TokenIterator(session, cursor.row, cursor.column);
264
if (!this.$matchTokenType(iterator.getCurrentToken() || "text", SAFE_INSERT_IN_TOKENS)) {
265
var iterator2 = new TokenIterator(session, cursor.row, cursor.column + 1);
266
if (!this.$matchTokenType(iterator2.getCurrentToken() || "text", SAFE_INSERT_IN_TOKENS))
269
iterator.stepForward();
270
return iterator.getCurrentTokenRow() !== cursor.row ||
271
this.$matchTokenType(iterator.getCurrentToken() || "text", SAFE_INSERT_BEFORE_TOKENS);
274
CstyleBehaviour.$matchTokenType = function(token, types) {
275
return types.indexOf(token.type || token) > -1;
278
CstyleBehaviour.recordAutoInsert = function(editor, session, bracket) {
279
var cursor = editor.getCursorPosition();
280
var line = session.doc.getLine(cursor.row);
281
if (!this.isAutoInsertedClosing(cursor, line, autoInsertedLineEnd[0]))
282
autoInsertedBrackets = 0;
283
autoInsertedRow = cursor.row;
284
autoInsertedLineEnd = bracket + line.substr(cursor.column);
285
autoInsertedBrackets++;
288
CstyleBehaviour.recordMaybeInsert = function(editor, session, bracket) {
289
var cursor = editor.getCursorPosition();
290
var line = session.doc.getLine(cursor.row);
291
if (!this.isMaybeInsertedClosing(cursor, line))
292
maybeInsertedBrackets = 0;
293
maybeInsertedRow = cursor.row;
294
maybeInsertedLineStart = line.substr(0, cursor.column) + bracket;
295
maybeInsertedLineEnd = line.substr(cursor.column);
296
maybeInsertedBrackets++;
299
CstyleBehaviour.isAutoInsertedClosing = function(cursor, line, bracket) {
300
return autoInsertedBrackets > 0 &&
301
cursor.row === autoInsertedRow &&
302
bracket === autoInsertedLineEnd[0] &&
303
line.substr(cursor.column) === autoInsertedLineEnd;
306
CstyleBehaviour.isMaybeInsertedClosing = function(cursor, line) {
307
return maybeInsertedBrackets > 0 &&
308
cursor.row === maybeInsertedRow &&
309
line.substr(cursor.column) === maybeInsertedLineEnd &&
310
line.substr(0, cursor.column) == maybeInsertedLineStart;
313
CstyleBehaviour.popAutoInsertedClosing = function() {
314
autoInsertedLineEnd = autoInsertedLineEnd.substr(1);
315
autoInsertedBrackets--;
318
CstyleBehaviour.clearMaybeInsertedClosing = function() {
319
maybeInsertedBrackets = 0;
320
maybeInsertedRow = -1;
323
this.add("braces", "insertion", function (state, action, editor, session, text) {
324
var cursor = editor.getCursorPosition();
325
var line = session.doc.getLine(cursor.row);
327
var selection = editor.getSelectionRange();
328
var selected = session.doc.getTextRange(selection);
329
if (selected !== "" && selected !== "{" && editor.getWrapBehavioursEnabled()) {
331
text: '{' + selected + '}',
334
} else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
335
if (/[\]\}\)]/.test(line[cursor.column])) {
336
CstyleBehaviour.recordAutoInsert(editor, session, "}");
342
CstyleBehaviour.recordMaybeInsert(editor, session, "{");
349
} else if (text == '}') {
350
var rightChar = line.substring(cursor.column, cursor.column + 1);
351
if (rightChar == '}') {
352
var matching = session.$findOpeningBracket('}', {column: cursor.column + 1, row: cursor.row});
353
if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) {
354
CstyleBehaviour.popAutoInsertedClosing();
361
} else if (text == "\n" || text == "\r\n") {
363
if (CstyleBehaviour.isMaybeInsertedClosing(cursor, line)) {
364
closing = lang.stringRepeat("}", maybeInsertedBrackets);
365
CstyleBehaviour.clearMaybeInsertedClosing();
367
var rightChar = line.substring(cursor.column, cursor.column + 1);
368
if (rightChar == '}' || closing !== "") {
369
var openBracePos = session.findMatchingBracket({row: cursor.row, column: cursor.column}, '}');
373
var indent = this.getNextLineIndent(state, line.substring(0, cursor.column), session.getTabString());
374
var next_indent = this.$getIndent(line);
377
text: '\n' + indent + '\n' + next_indent + closing,
378
selection: [1, indent.length, 1, indent.length]
384
this.add("braces", "deletion", function (state, action, editor, session, range) {
385
var selected = session.doc.getTextRange(range);
386
if (!range.isMultiLine() && selected == '{') {
387
var line = session.doc.getLine(range.start.row);
388
var rightChar = line.substring(range.end.column, range.end.column + 1);
389
if (rightChar == '}') {
393
maybeInsertedBrackets--;
398
this.add("parens", "insertion", function (state, action, editor, session, text) {
400
var selection = editor.getSelectionRange();
401
var selected = session.doc.getTextRange(selection);
402
if (selected !== "" && editor.getWrapBehavioursEnabled()) {
404
text: '(' + selected + ')',
407
} else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
408
CstyleBehaviour.recordAutoInsert(editor, session, ")");
414
} else if (text == ')') {
415
var cursor = editor.getCursorPosition();
416
var line = session.doc.getLine(cursor.row);
417
var rightChar = line.substring(cursor.column, cursor.column + 1);
418
if (rightChar == ')') {
419
var matching = session.$findOpeningBracket(')', {column: cursor.column + 1, row: cursor.row});
420
if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) {
421
CstyleBehaviour.popAutoInsertedClosing();
431
this.add("parens", "deletion", function (state, action, editor, session, range) {
432
var selected = session.doc.getTextRange(range);
433
if (!range.isMultiLine() && selected == '(') {
434
var line = session.doc.getLine(range.start.row);
435
var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
436
if (rightChar == ')') {
443
this.add("brackets", "insertion", function (state, action, editor, session, text) {
445
var selection = editor.getSelectionRange();
446
var selected = session.doc.getTextRange(selection);
447
if (selected !== "" && editor.getWrapBehavioursEnabled()) {
449
text: '[' + selected + ']',
452
} else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
453
CstyleBehaviour.recordAutoInsert(editor, session, "]");
459
} else if (text == ']') {
460
var cursor = editor.getCursorPosition();
461
var line = session.doc.getLine(cursor.row);
462
var rightChar = line.substring(cursor.column, cursor.column + 1);
463
if (rightChar == ']') {
464
var matching = session.$findOpeningBracket(']', {column: cursor.column + 1, row: cursor.row});
465
if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) {
466
CstyleBehaviour.popAutoInsertedClosing();
476
this.add("brackets", "deletion", function (state, action, editor, session, range) {
477
var selected = session.doc.getTextRange(range);
478
if (!range.isMultiLine() && selected == '[') {
479
var line = session.doc.getLine(range.start.row);
480
var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
481
if (rightChar == ']') {
488
this.add("string_dquotes", "insertion", function (state, action, editor, session, text) {
489
if (text == '"' || text == "'") {
491
var selection = editor.getSelectionRange();
492
var selected = session.doc.getTextRange(selection);
493
if (selected !== "" && selected !== "'" && selected != '"' && editor.getWrapBehavioursEnabled()) {
495
text: quote + selected + quote,
499
var cursor = editor.getCursorPosition();
500
var line = session.doc.getLine(cursor.row);
501
var leftChar = line.substring(cursor.column-1, cursor.column);
502
if (leftChar == '\\') {
505
var tokens = session.getTokens(selection.start.row);
507
var quotepos = -1; // Track whether we're inside an open quote.
509
for (var x = 0; x < tokens.length; x++) {
511
if (token.type == "string") {
513
} else if (quotepos < 0) {
514
quotepos = token.value.indexOf(quote);
516
if ((token.value.length + col) > selection.start.column) {
519
col += tokens[x].value.length;
521
if (!token || (quotepos < 0 && token.type !== "comment" && (token.type !== "string" || ((selection.start.column !== token.value.length+col-1) && token.value.lastIndexOf(quote) === token.value.length-1)))) {
522
if (!CstyleBehaviour.isSaneInsertion(editor, session))
528
} else if (token && token.type === "string") {
529
var rightChar = line.substring(cursor.column, cursor.column + 1);
530
if (rightChar == quote) {
541
this.add("string_dquotes", "deletion", function (state, action, editor, session, range) {
542
var selected = session.doc.getTextRange(range);
543
if (!range.isMultiLine() && (selected == '"' || selected == "'")) {
544
var line = session.doc.getLine(range.start.row);
545
var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
546
if (rightChar == selected) {
555
oop.inherits(CstyleBehaviour, Behaviour);
557
exports.CstyleBehaviour = CstyleBehaviour;
560
define('ace/mode/folding/cstyle', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/range', 'ace/mode/folding/fold_mode'], function(require, exports, module) {
563
var oop = require("../../lib/oop");
564
var Range = require("../../range").Range;
565
var BaseFoldMode = require("./fold_mode").FoldMode;
567
var FoldMode = exports.FoldMode = function(commentRegex) {
569
this.foldingStartMarker = new RegExp(
570
this.foldingStartMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.start)
572
this.foldingStopMarker = new RegExp(
573
this.foldingStopMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.end)
577
oop.inherits(FoldMode, BaseFoldMode);
581
this.foldingStartMarker = /(\{|\[)[^\}\]]*$|^\s*(\/\*)/;
582
this.foldingStopMarker = /^[^\[\{]*(\}|\])|^[\s\*]*(\*\/)/;
584
this.getFoldWidgetRange = function(session, foldStyle, row) {
585
var line = session.getLine(row);
586
var match = line.match(this.foldingStartMarker);
591
return this.openingBracketBlock(session, match[1], row, i);
593
return session.getCommentFoldRange(row, i + match[0].length, 1);
596
if (foldStyle !== "markbeginend")
599
var match = line.match(this.foldingStopMarker);
601
var i = match.index + match[0].length;
604
return this.closingBracketBlock(session, match[1], row, i);
606
return session.getCommentFoldRange(row, i, -1);
610
}).call(FoldMode.prototype);