1
/* ***** BEGIN LICENSE BLOCK *****
2
* Distributed under the BSD license:
4
* Copyright (c) 2010, Ajax.org B.V.
7
* Redistribution and use in source and binary forms, with or without
8
* modification, are permitted provided that the following conditions are met:
9
* * Redistributions of source code must retain the above copyright
10
* notice, this list of conditions and the following disclaimer.
11
* * Redistributions in binary form must reproduce the above copyright
12
* notice, this list of conditions and the following disclaimer in the
13
* documentation and/or other materials provided with the distribution.
14
* * Neither the name of Ajax.org B.V. nor the
15
* names of its contributors may be used to endorse or promote products
16
* derived from this software without specific prior written permission.
18
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21
* DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY
22
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
* ***** END LICENSE BLOCK ***** */
31
define('ace/mode/c_cpp', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/text', 'ace/tokenizer', 'ace/mode/c_cpp_highlight_rules', 'ace/mode/matching_brace_outdent', 'ace/range', 'ace/mode/behaviour/cstyle', 'ace/mode/folding/cstyle'], function(require, exports, module) {
34
var oop = require("../lib/oop");
35
var TextMode = require("./text").Mode;
36
var Tokenizer = require("../tokenizer").Tokenizer;
37
var c_cppHighlightRules = require("./c_cpp_highlight_rules").c_cppHighlightRules;
38
var MatchingBraceOutdent = require("./matching_brace_outdent").MatchingBraceOutdent;
39
var Range = require("../range").Range;
40
var CstyleBehaviour = require("./behaviour/cstyle").CstyleBehaviour;
41
var CStyleFoldMode = require("./folding/cstyle").FoldMode;
43
var Mode = function() {
44
this.$tokenizer = new Tokenizer(new c_cppHighlightRules().getRules());
45
this.$outdent = new MatchingBraceOutdent();
46
this.$behaviour = new CstyleBehaviour();
47
this.foldingRules = new CStyleFoldMode();
49
oop.inherits(Mode, TextMode);
53
this.lineCommentStart = "//";
54
this.blockComment = {start: "/*", end: "*/"};
56
this.getNextLineIndent = function(state, line, tab) {
57
var indent = this.$getIndent(line);
59
var tokenizedLine = this.$tokenizer.getLineTokens(line, state);
60
var tokens = tokenizedLine.tokens;
61
var endState = tokenizedLine.state;
63
if (tokens.length && tokens[tokens.length-1].type == "comment") {
67
if (state == "start") {
68
var match = line.match(/^.*[\{\(\[]\s*$/);
72
} else if (state == "doc-start") {
73
if (endState == "start") {
76
var match = line.match(/^\s*(\/?)\*/);
88
this.checkOutdent = function(state, line, input) {
89
return this.$outdent.checkOutdent(line, input);
92
this.autoOutdent = function(state, doc, row) {
93
this.$outdent.autoOutdent(doc, row);
96
}).call(Mode.prototype);
100
define('ace/mode/c_cpp_highlight_rules', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/doc_comment_highlight_rules', 'ace/mode/text_highlight_rules'], function(require, exports, module) {
103
var oop = require("../lib/oop");
104
var DocCommentHighlightRules = require("./doc_comment_highlight_rules").DocCommentHighlightRules;
105
var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
106
var cFunctions = exports.cFunctions = "\\s*\\bhypot(?:f|l)?|s(?:scanf|ystem|nprintf|ca(?:nf|lb(?:n(?:f|l)?|ln(?:f|l)?))|i(?:n(?:h(?:f|l)?|f|l)?|gn(?:al|bit))|tr(?:s(?:tr|pn)|nc(?:py|at|mp)|c(?:spn|hr|oll|py|at|mp)|to(?:imax|d|u(?:l(?:l)?|max)|k|f|l(?:d|l)?)|error|pbrk|ftime|len|rchr|xfrm)|printf|et(?:jmp|vbuf|locale|buf)|qrt(?:f|l)?|w(?:scanf|printf)|rand)|n(?:e(?:arbyint(?:f|l)?|xt(?:toward(?:f|l)?|after(?:f|l)?))|an(?:f|l)?)|c(?:s(?:in(?:h(?:f|l)?|f|l)?|qrt(?:f|l)?)|cos(?:h(?:f)?|f|l)?|imag(?:f|l)?|t(?:ime|an(?:h(?:f|l)?|f|l)?)|o(?:s(?:h(?:f|l)?|f|l)?|nj(?:f|l)?|pysign(?:f|l)?)|p(?:ow(?:f|l)?|roj(?:f|l)?)|e(?:il(?:f|l)?|xp(?:f|l)?)|l(?:o(?:ck|g(?:f|l)?)|earerr)|a(?:sin(?:h(?:f|l)?|f|l)?|cos(?:h(?:f|l)?|f|l)?|tan(?:h(?:f|l)?|f|l)?|lloc|rg(?:f|l)?|bs(?:f|l)?)|real(?:f|l)?|brt(?:f|l)?)|t(?:ime|o(?:upper|lower)|an(?:h(?:f|l)?|f|l)?|runc(?:f|l)?|gamma(?:f|l)?|mp(?:nam|file))|i(?:s(?:space|n(?:ormal|an)|cntrl|inf|digit|u(?:nordered|pper)|p(?:unct|rint)|finite|w(?:space|c(?:ntrl|type)|digit|upper|p(?:unct|rint)|lower|al(?:num|pha)|graph|xdigit|blank)|l(?:ower|ess(?:equal|greater)?)|al(?:num|pha)|gr(?:eater(?:equal)?|aph)|xdigit|blank)|logb(?:f|l)?|max(?:div|abs))|di(?:v|fftime)|_Exit|unget(?:c|wc)|p(?:ow(?:f|l)?|ut(?:s|c(?:har)?|wc(?:har)?)|error|rintf)|e(?:rf(?:c(?:f|l)?|f|l)?|x(?:it|p(?:2(?:f|l)?|f|l|m1(?:f|l)?)?))|v(?:s(?:scanf|nprintf|canf|printf|w(?:scanf|printf))|printf|f(?:scanf|printf|w(?:scanf|printf))|w(?:scanf|printf)|a_(?:start|copy|end|arg))|qsort|f(?:s(?:canf|e(?:tpos|ek))|close|tell|open|dim(?:f|l)?|p(?:classify|ut(?:s|c|w(?:s|c))|rintf)|e(?:holdexcept|set(?:e(?:nv|xceptflag)|round)|clearexcept|testexcept|of|updateenv|r(?:aiseexcept|ror)|get(?:e(?:nv|xceptflag)|round))|flush|w(?:scanf|ide|printf|rite)|loor(?:f|l)?|abs(?:f|l)?|get(?:s|c|pos|w(?:s|c))|re(?:open|e|ad|xp(?:f|l)?)|m(?:in(?:f|l)?|od(?:f|l)?|a(?:f|l|x(?:f|l)?)?))|l(?:d(?:iv|exp(?:f|l)?)|o(?:ngjmp|cal(?:time|econv)|g(?:1(?:p(?:f|l)?|0(?:f|l)?)|2(?:f|l)?|f|l|b(?:f|l)?)?)|abs|l(?:div|abs|r(?:int(?:f|l)?|ound(?:f|l)?))|r(?:int(?:f|l)?|ound(?:f|l)?)|gamma(?:f|l)?)|w(?:scanf|c(?:s(?:s(?:tr|pn)|nc(?:py|at|mp)|c(?:spn|hr|oll|py|at|mp)|to(?:imax|d|u(?:l(?:l)?|max)|k|f|l(?:d|l)?|mbs)|pbrk|ftime|len|r(?:chr|tombs)|xfrm)|to(?:b|mb)|rtomb)|printf|mem(?:set|c(?:hr|py|mp)|move))|a(?:s(?:sert|ctime|in(?:h(?:f|l)?|f|l)?)|cos(?:h(?:f|l)?|f|l)?|t(?:o(?:i|f|l(?:l)?)|exit|an(?:h(?:f|l)?|2(?:f|l)?|f|l)?)|b(?:s|ort))|g(?:et(?:s|c(?:har)?|env|wc(?:har)?)|mtime)|r(?:int(?:f|l)?|ound(?:f|l)?|e(?:name|alloc|wind|m(?:ove|quo(?:f|l)?|ainder(?:f|l)?))|a(?:nd|ise))|b(?:search|towc)|m(?:odf(?:f|l)?|em(?:set|c(?:hr|py|mp)|move)|ktime|alloc|b(?:s(?:init|towcs|rtowcs)|towc|len|r(?:towc|len)))\\b"
108
var c_cppHighlightRules = function() {
110
var keywordControls = (
111
"break|case|continue|default|do|else|for|goto|if|_Pragma|" +
112
"return|switch|while|catch|operator|try|throw|using"
116
"asm|__asm__|auto|bool|_Bool|char|_Complex|double|enum|float|" +
117
"_Imaginary|int|long|short|signed|struct|typedef|union|unsigned|void|" +
118
"class|wchar_t|template"
121
var storageModifiers = (
122
"const|extern|register|restrict|static|volatile|inline|private:|" +
123
"protected:|public:|friend|explicit|virtual|export|mutable|typename"
126
var keywordOperators = (
127
"and|and_eq|bitand|bitor|compl|not|not_eq|or|or_eq|typeid|xor|xor_eq" +
128
"const_cast|dynamic_cast|reinterpret_cast|static_cast|sizeof|namespace"
131
var builtinConstants = (
132
"NULL|true|false|TRUE|FALSE"
135
var keywordMapper = this.$keywords = this.createKeywordMapper({
136
"keyword.control" : keywordControls,
137
"storage.type" : storageType,
138
"storage.modifier" : storageModifiers,
139
"keyword.operator" : keywordOperators,
140
"variable.language": "this",
141
"constant.language": builtinConstants
144
var identifierRe = "[a-zA-Z\\$_\u00a1-\uffff][a-zA-Z\d\\$_\u00a1-\uffff]*\\b";
152
DocCommentHighlightRules.getStartRule("doc-start"),
154
token : "comment", // multi line comment
158
token : "string", // single line
159
regex : '["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]'
161
token : "string", // multi line string start
162
regex : '["].*\\\\$',
165
token : "string", // single line
166
regex : "['](?:(?:\\\\.)|(?:[^'\\\\]))*?[']"
168
token : "string", // multi line string start
169
regex : "['].*\\\\$",
172
token : "constant.numeric", // hex
173
regex : "0[xX][0-9a-fA-F]+\\b"
175
token : "constant.numeric", // float
176
regex : "[+-]?\\d+(?:(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)?\\b"
178
token : "keyword", // pre-compiler directives
179
regex : "(?:#include|#import|#pragma|#line|#define|#undef|#if|#ifdef|#else|#elif|#ifndef)\\b",
182
token : "keyword", // special case pre-compiler directive
183
regex : "(?:#endif)\\b"
185
token : "support.function.C99.c",
188
token : keywordMapper,
189
regex : "[a-zA-Z_$][a-zA-Z0-9_$]*\\b"
191
token : "keyword.operator",
192
regex : "!|\\$|%|&|\\*|\\-\\-|\\-|\\+\\+|\\+|~|==|=|!=|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\\|\\||\\?\\:|\\*=|%=|\\+=|\\-=|&=|\\^=|\\b(?:in|new|delete|typeof|void)"
194
token : "punctuation.operator",
195
regex : "\\?|\\:|\\,|\\;|\\."
197
token : "paren.lparen",
200
token : "paren.rparen",
209
token : "comment", // closing comment
213
token : "comment", // comment spanning whole line
220
regex : '(?:(?:\\\\.)|(?:[^"\\\\]))*?"',
230
regex : "(?:(?:\\\\.)|(?:[^'\\\\]))*?'",
239
token : "constant.other.multiline",
243
token : "constant.other.multiline",
247
token : "constant.other",
252
token : "constant.other", // single line
253
regex : '\\s*["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]',
257
token : "constant.other", // single line
258
regex : "\\s*['](?:(?:\\\\.)|(?:[^'\\\\]))*?[']",
262
token : "constant.other",
269
this.embedRules(DocCommentHighlightRules, "doc-",
270
[ DocCommentHighlightRules.getEndRule("start") ]);
273
oop.inherits(c_cppHighlightRules, TextHighlightRules);
275
exports.c_cppHighlightRules = c_cppHighlightRules;
278
define('ace/mode/doc_comment_highlight_rules', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/text_highlight_rules'], function(require, exports, module) {
281
var oop = require("../lib/oop");
282
var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
284
var DocCommentHighlightRules = function() {
288
token : "comment.doc.tag",
289
regex : "@[\\w\\d_]+" // TODO: fix email addresses
291
token : "comment.doc.tag",
294
defaultToken : "comment.doc"
299
oop.inherits(DocCommentHighlightRules, TextHighlightRules);
301
DocCommentHighlightRules.getStartRule = function(start) {
303
token : "comment.doc", // doc comment
304
regex : "\\/\\*(?=\\*)",
309
DocCommentHighlightRules.getEndRule = function (start) {
311
token : "comment.doc", // closing comment
318
exports.DocCommentHighlightRules = DocCommentHighlightRules;
322
define('ace/mode/matching_brace_outdent', ['require', 'exports', 'module' , 'ace/range'], function(require, exports, module) {
325
var Range = require("../range").Range;
327
var MatchingBraceOutdent = function() {};
331
this.checkOutdent = function(line, input) {
332
if (! /^\s+$/.test(line))
335
return /^\s*\}/.test(input);
338
this.autoOutdent = function(doc, row) {
339
var line = doc.getLine(row);
340
var match = line.match(/^(\s*\})/);
342
if (!match) return 0;
344
var column = match[1].length;
345
var openBracePos = doc.findMatchingBracket({row: row, column: column});
347
if (!openBracePos || openBracePos.row == row) return 0;
349
var indent = this.$getIndent(doc.getLine(openBracePos.row));
350
doc.replace(new Range(row, 0, row, column-1), indent);
353
this.$getIndent = function(line) {
354
return line.match(/^\s*/)[0];
357
}).call(MatchingBraceOutdent.prototype);
359
exports.MatchingBraceOutdent = MatchingBraceOutdent;
362
define('ace/mode/behaviour/cstyle', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/behaviour', 'ace/token_iterator', 'ace/lib/lang'], function(require, exports, module) {
365
var oop = require("../../lib/oop");
366
var Behaviour = require("../behaviour").Behaviour;
367
var TokenIterator = require("../../token_iterator").TokenIterator;
368
var lang = require("../../lib/lang");
370
var SAFE_INSERT_IN_TOKENS =
371
["text", "paren.rparen", "punctuation.operator"];
372
var SAFE_INSERT_BEFORE_TOKENS =
373
["text", "paren.rparen", "punctuation.operator", "comment"];
376
var autoInsertedBrackets = 0;
377
var autoInsertedRow = -1;
378
var autoInsertedLineEnd = "";
379
var maybeInsertedBrackets = 0;
380
var maybeInsertedRow = -1;
381
var maybeInsertedLineStart = "";
382
var maybeInsertedLineEnd = "";
384
var CstyleBehaviour = function () {
386
CstyleBehaviour.isSaneInsertion = function(editor, session) {
387
var cursor = editor.getCursorPosition();
388
var iterator = new TokenIterator(session, cursor.row, cursor.column);
389
if (!this.$matchTokenType(iterator.getCurrentToken() || "text", SAFE_INSERT_IN_TOKENS)) {
390
var iterator2 = new TokenIterator(session, cursor.row, cursor.column + 1);
391
if (!this.$matchTokenType(iterator2.getCurrentToken() || "text", SAFE_INSERT_IN_TOKENS))
394
iterator.stepForward();
395
return iterator.getCurrentTokenRow() !== cursor.row ||
396
this.$matchTokenType(iterator.getCurrentToken() || "text", SAFE_INSERT_BEFORE_TOKENS);
399
CstyleBehaviour.$matchTokenType = function(token, types) {
400
return types.indexOf(token.type || token) > -1;
403
CstyleBehaviour.recordAutoInsert = function(editor, session, bracket) {
404
var cursor = editor.getCursorPosition();
405
var line = session.doc.getLine(cursor.row);
406
if (!this.isAutoInsertedClosing(cursor, line, autoInsertedLineEnd[0]))
407
autoInsertedBrackets = 0;
408
autoInsertedRow = cursor.row;
409
autoInsertedLineEnd = bracket + line.substr(cursor.column);
410
autoInsertedBrackets++;
413
CstyleBehaviour.recordMaybeInsert = function(editor, session, bracket) {
414
var cursor = editor.getCursorPosition();
415
var line = session.doc.getLine(cursor.row);
416
if (!this.isMaybeInsertedClosing(cursor, line))
417
maybeInsertedBrackets = 0;
418
maybeInsertedRow = cursor.row;
419
maybeInsertedLineStart = line.substr(0, cursor.column) + bracket;
420
maybeInsertedLineEnd = line.substr(cursor.column);
421
maybeInsertedBrackets++;
424
CstyleBehaviour.isAutoInsertedClosing = function(cursor, line, bracket) {
425
return autoInsertedBrackets > 0 &&
426
cursor.row === autoInsertedRow &&
427
bracket === autoInsertedLineEnd[0] &&
428
line.substr(cursor.column) === autoInsertedLineEnd;
431
CstyleBehaviour.isMaybeInsertedClosing = function(cursor, line) {
432
return maybeInsertedBrackets > 0 &&
433
cursor.row === maybeInsertedRow &&
434
line.substr(cursor.column) === maybeInsertedLineEnd &&
435
line.substr(0, cursor.column) == maybeInsertedLineStart;
438
CstyleBehaviour.popAutoInsertedClosing = function() {
439
autoInsertedLineEnd = autoInsertedLineEnd.substr(1);
440
autoInsertedBrackets--;
443
CstyleBehaviour.clearMaybeInsertedClosing = function() {
444
maybeInsertedBrackets = 0;
445
maybeInsertedRow = -1;
448
this.add("braces", "insertion", function (state, action, editor, session, text) {
449
var cursor = editor.getCursorPosition();
450
var line = session.doc.getLine(cursor.row);
452
var selection = editor.getSelectionRange();
453
var selected = session.doc.getTextRange(selection);
454
if (selected !== "" && selected !== "{" && editor.getWrapBehavioursEnabled()) {
456
text: '{' + selected + '}',
459
} else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
460
if (/[\]\}\)]/.test(line[cursor.column])) {
461
CstyleBehaviour.recordAutoInsert(editor, session, "}");
467
CstyleBehaviour.recordMaybeInsert(editor, session, "{");
474
} else if (text == '}') {
475
var rightChar = line.substring(cursor.column, cursor.column + 1);
476
if (rightChar == '}') {
477
var matching = session.$findOpeningBracket('}', {column: cursor.column + 1, row: cursor.row});
478
if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) {
479
CstyleBehaviour.popAutoInsertedClosing();
486
} else if (text == "\n" || text == "\r\n") {
488
if (CstyleBehaviour.isMaybeInsertedClosing(cursor, line)) {
489
closing = lang.stringRepeat("}", maybeInsertedBrackets);
490
CstyleBehaviour.clearMaybeInsertedClosing();
492
var rightChar = line.substring(cursor.column, cursor.column + 1);
493
if (rightChar == '}' || closing !== "") {
494
var openBracePos = session.findMatchingBracket({row: cursor.row, column: cursor.column}, '}');
498
var indent = this.getNextLineIndent(state, line.substring(0, cursor.column), session.getTabString());
499
var next_indent = this.$getIndent(line);
502
text: '\n' + indent + '\n' + next_indent + closing,
503
selection: [1, indent.length, 1, indent.length]
509
this.add("braces", "deletion", function (state, action, editor, session, range) {
510
var selected = session.doc.getTextRange(range);
511
if (!range.isMultiLine() && selected == '{') {
512
var line = session.doc.getLine(range.start.row);
513
var rightChar = line.substring(range.end.column, range.end.column + 1);
514
if (rightChar == '}') {
518
maybeInsertedBrackets--;
523
this.add("parens", "insertion", function (state, action, editor, session, text) {
525
var selection = editor.getSelectionRange();
526
var selected = session.doc.getTextRange(selection);
527
if (selected !== "" && editor.getWrapBehavioursEnabled()) {
529
text: '(' + selected + ')',
532
} else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
533
CstyleBehaviour.recordAutoInsert(editor, session, ")");
539
} else if (text == ')') {
540
var cursor = editor.getCursorPosition();
541
var line = session.doc.getLine(cursor.row);
542
var rightChar = line.substring(cursor.column, cursor.column + 1);
543
if (rightChar == ')') {
544
var matching = session.$findOpeningBracket(')', {column: cursor.column + 1, row: cursor.row});
545
if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) {
546
CstyleBehaviour.popAutoInsertedClosing();
556
this.add("parens", "deletion", function (state, action, editor, session, range) {
557
var selected = session.doc.getTextRange(range);
558
if (!range.isMultiLine() && selected == '(') {
559
var line = session.doc.getLine(range.start.row);
560
var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
561
if (rightChar == ')') {
568
this.add("brackets", "insertion", function (state, action, editor, session, text) {
570
var selection = editor.getSelectionRange();
571
var selected = session.doc.getTextRange(selection);
572
if (selected !== "" && editor.getWrapBehavioursEnabled()) {
574
text: '[' + selected + ']',
577
} else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
578
CstyleBehaviour.recordAutoInsert(editor, session, "]");
584
} else if (text == ']') {
585
var cursor = editor.getCursorPosition();
586
var line = session.doc.getLine(cursor.row);
587
var rightChar = line.substring(cursor.column, cursor.column + 1);
588
if (rightChar == ']') {
589
var matching = session.$findOpeningBracket(']', {column: cursor.column + 1, row: cursor.row});
590
if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) {
591
CstyleBehaviour.popAutoInsertedClosing();
601
this.add("brackets", "deletion", function (state, action, editor, session, range) {
602
var selected = session.doc.getTextRange(range);
603
if (!range.isMultiLine() && selected == '[') {
604
var line = session.doc.getLine(range.start.row);
605
var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
606
if (rightChar == ']') {
613
this.add("string_dquotes", "insertion", function (state, action, editor, session, text) {
614
if (text == '"' || text == "'") {
616
var selection = editor.getSelectionRange();
617
var selected = session.doc.getTextRange(selection);
618
if (selected !== "" && selected !== "'" && selected != '"' && editor.getWrapBehavioursEnabled()) {
620
text: quote + selected + quote,
624
var cursor = editor.getCursorPosition();
625
var line = session.doc.getLine(cursor.row);
626
var leftChar = line.substring(cursor.column-1, cursor.column);
627
if (leftChar == '\\') {
630
var tokens = session.getTokens(selection.start.row);
632
var quotepos = -1; // Track whether we're inside an open quote.
634
for (var x = 0; x < tokens.length; x++) {
636
if (token.type == "string") {
638
} else if (quotepos < 0) {
639
quotepos = token.value.indexOf(quote);
641
if ((token.value.length + col) > selection.start.column) {
644
col += tokens[x].value.length;
646
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)))) {
647
if (!CstyleBehaviour.isSaneInsertion(editor, session))
653
} else if (token && token.type === "string") {
654
var rightChar = line.substring(cursor.column, cursor.column + 1);
655
if (rightChar == quote) {
666
this.add("string_dquotes", "deletion", function (state, action, editor, session, range) {
667
var selected = session.doc.getTextRange(range);
668
if (!range.isMultiLine() && (selected == '"' || selected == "'")) {
669
var line = session.doc.getLine(range.start.row);
670
var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
671
if (rightChar == selected) {
680
oop.inherits(CstyleBehaviour, Behaviour);
682
exports.CstyleBehaviour = CstyleBehaviour;
685
define('ace/mode/folding/cstyle', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/range', 'ace/mode/folding/fold_mode'], function(require, exports, module) {
688
var oop = require("../../lib/oop");
689
var Range = require("../../range").Range;
690
var BaseFoldMode = require("./fold_mode").FoldMode;
692
var FoldMode = exports.FoldMode = function(commentRegex) {
694
this.foldingStartMarker = new RegExp(
695
this.foldingStartMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.start)
697
this.foldingStopMarker = new RegExp(
698
this.foldingStopMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.end)
702
oop.inherits(FoldMode, BaseFoldMode);
706
this.foldingStartMarker = /(\{|\[)[^\}\]]*$|^\s*(\/\*)/;
707
this.foldingStopMarker = /^[^\[\{]*(\}|\])|^[\s\*]*(\*\/)/;
709
this.getFoldWidgetRange = function(session, foldStyle, row) {
710
var line = session.getLine(row);
711
var match = line.match(this.foldingStartMarker);
716
return this.openingBracketBlock(session, match[1], row, i);
718
return session.getCommentFoldRange(row, i + match[0].length, 1);
721
if (foldStyle !== "markbeginend")
724
var match = line.match(this.foldingStopMarker);
726
var i = match.index + match[0].length;
729
return this.closingBracketBlock(session, match[1], row, i);
731
return session.getCommentFoldRange(row, i, -1);
735
}).call(FoldMode.prototype);