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/javascript', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/text', 'ace/tokenizer', 'ace/mode/javascript_highlight_rules', 'ace/mode/matching_brace_outdent', 'ace/range', 'ace/worker/worker_client', '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 JavaScriptHighlightRules = require("./javascript_highlight_rules").JavaScriptHighlightRules;
38
var MatchingBraceOutdent = require("./matching_brace_outdent").MatchingBraceOutdent;
39
var Range = require("../range").Range;
40
var WorkerClient = require("../worker/worker_client").WorkerClient;
41
var CstyleBehaviour = require("./behaviour/cstyle").CstyleBehaviour;
42
var CStyleFoldMode = require("./folding/cstyle").FoldMode;
44
var Mode = function() {
45
this.$tokenizer = new Tokenizer(new JavaScriptHighlightRules().getRules());
46
this.$outdent = new MatchingBraceOutdent();
47
this.$behaviour = new CstyleBehaviour();
48
this.foldingRules = new CStyleFoldMode();
50
oop.inherits(Mode, TextMode);
54
this.lineCommentStart = "//";
55
this.blockComment = {start: "/*", end: "*/"};
57
this.getNextLineIndent = function(state, line, tab) {
58
var indent = this.$getIndent(line);
60
var tokenizedLine = this.$tokenizer.getLineTokens(line, state);
61
var tokens = tokenizedLine.tokens;
62
var endState = tokenizedLine.state;
64
if (tokens.length && tokens[tokens.length-1].type == "comment") {
68
if (state == "start" || state == "no_regex") {
69
var match = line.match(/^.*(?:\bcase\b.*\:|[\{\(\[])\s*$/);
73
} else if (state == "doc-start") {
74
if (endState == "start" || endState == "no_regex") {
77
var match = line.match(/^\s*(\/?)\*/);
89
this.checkOutdent = function(state, line, input) {
90
return this.$outdent.checkOutdent(line, input);
93
this.autoOutdent = function(state, doc, row) {
94
this.$outdent.autoOutdent(doc, row);
97
this.createWorker = function(session) {
98
var worker = new WorkerClient(["ace"], "ace/mode/javascript_worker", "JavaScriptWorker");
99
worker.attachToDocument(session.getDocument());
101
worker.on("jslint", function(results) {
102
session.setAnnotations(results.data);
105
worker.on("terminate", function() {
106
session.clearAnnotations();
112
}).call(Mode.prototype);
117
define('ace/mode/javascript_highlight_rules', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/doc_comment_highlight_rules', 'ace/mode/text_highlight_rules'], function(require, exports, module) {
120
var oop = require("../lib/oop");
121
var DocCommentHighlightRules = require("./doc_comment_highlight_rules").DocCommentHighlightRules;
122
var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
124
var JavaScriptHighlightRules = function() {
125
var keywordMapper = this.createKeywordMapper({
127
"Array|Boolean|Date|Function|Iterator|Number|Object|RegExp|String|Proxy|" + // Constructors
128
"Namespace|QName|XML|XMLList|" + // E4X
129
"ArrayBuffer|Float32Array|Float64Array|Int16Array|Int32Array|Int8Array|" +
130
"Uint16Array|Uint32Array|Uint8Array|Uint8ClampedArray|" +
131
"Error|EvalError|InternalError|RangeError|ReferenceError|StopIteration|" + // Errors
132
"SyntaxError|TypeError|URIError|" +
133
"decodeURI|decodeURIComponent|encodeURI|encodeURIComponent|eval|isFinite|" + // Non-constructor functions
134
"isNaN|parseFloat|parseInt|" +
135
"JSON|Math|" + // Other
136
"this|arguments|prototype|window|document" , // Pseudo
138
"const|yield|import|get|set|" +
139
"break|case|catch|continue|default|delete|do|else|finally|for|function|" +
140
"if|in|instanceof|new|return|switch|throw|try|typeof|let|var|while|with|debugger|" +
141
"__parent__|__count__|escape|unescape|with|__proto__|" +
142
"class|enum|extends|super|export|implements|private|public|interface|package|protected|static",
144
"const|let|var|function",
146
"null|Infinity|NaN|undefined",
149
"constant.language.boolean": "true|false"
151
var kwBeforeRe = "case|do|else|finally|in|instanceof|return|throw|try|typeof|yield|void";
152
var identifierRe = "[a-zA-Z\\$_\u00a1-\uffff][a-zA-Z\\d\\$_\u00a1-\uffff]*\\b";
154
var escapedRe = "\\\\(?:x[0-9a-fA-F]{2}|" + // hex
155
"u[0-9a-fA-F]{4}|" + // unicode
156
"[0-2][0-7]{0,2}|" + // oct
157
"3[0-6][0-7]?|" + // oct
159
"[4-7][0-7]?|" + //oct
168
DocCommentHighlightRules.getStartRule("doc-start"),
170
token : "comment", // multi line comment
182
token : "constant.numeric", // hex
183
regex : /0[xX][0-9a-fA-F]+\b/
185
token : "constant.numeric", // float
186
regex : /[+-]?\d+(?:(?:\.\d*)?(?:[eE][+-]?\d+)?)?\b/
189
"storage.type", "punctuation.operator", "support.function",
190
"punctuation.operator", "entity.name.function", "text","keyword.operator"
192
regex : "(" + identifierRe + ")(\\.)(prototype)(\\.)(" + identifierRe +")(\\s*)(=)",
193
next: "function_arguments"
196
"storage.type", "punctuation.operator", "entity.name.function", "text",
197
"keyword.operator", "text", "storage.type", "text", "paren.lparen"
199
regex : "(" + identifierRe + ")(\\.)(" + identifierRe +")(\\s*)(=)(\\s*)(function)(\\s*)(\\()",
200
next: "function_arguments"
203
"entity.name.function", "text", "keyword.operator", "text", "storage.type",
204
"text", "paren.lparen"
206
regex : "(" + identifierRe +")(\\s*)(=)(\\s*)(function)(\\s*)(\\()",
207
next: "function_arguments"
210
"storage.type", "punctuation.operator", "entity.name.function", "text",
211
"keyword.operator", "text",
212
"storage.type", "text", "entity.name.function", "text", "paren.lparen"
214
regex : "(" + identifierRe + ")(\\.)(" + identifierRe +")(\\s*)(=)(\\s*)(function)(\\s+)(\\w+)(\\s*)(\\()",
215
next: "function_arguments"
218
"storage.type", "text", "entity.name.function", "text", "paren.lparen"
220
regex : "(function)(\\s+)(" + identifierRe + ")(\\s*)(\\()",
221
next: "function_arguments"
224
"entity.name.function", "text", "punctuation.operator",
225
"text", "storage.type", "text", "paren.lparen"
227
regex : "(" + identifierRe + ")(\\s*)(:)(\\s*)(function)(\\s*)(\\()",
228
next: "function_arguments"
231
"text", "text", "storage.type", "text", "paren.lparen"
233
regex : "(:)(\\s*)(function)(\\s*)(\\()",
234
next: "function_arguments"
237
regex : "(?:" + kwBeforeRe + ")\\b",
240
token : ["punctuation.operator", "support.function"],
241
regex : /(\.)(s(?:h(?:ift|ow(?:Mod(?:elessDialog|alDialog)|Help))|croll(?:X|By(?:Pages|Lines)?|Y|To)?|t(?:opzzzz|rike)|i(?:n|zeToContent|debar|gnText)|ort|u(?:p|b(?:str(?:ing)?)?)|pli(?:ce|t)|e(?:nd|t(?:Re(?:sizable|questHeader)|M(?:i(?:nutes|lliseconds)|onth)|Seconds|Ho(?:tKeys|urs)|Year|Cursor|Time(?:out)?|Interval|ZOptions|Date|UTC(?:M(?:i(?:nutes|lliseconds)|onth)|Seconds|Hours|Date|FullYear)|FullYear|Active)|arch)|qrt|lice|avePreferences|mall)|h(?:ome|andleEvent)|navigate|c(?:har(?:CodeAt|At)|o(?:s|n(?:cat|textual|firm)|mpile)|eil|lear(?:Timeout|Interval)?|a(?:ptureEvents|ll)|reate(?:StyleSheet|Popup|EventObject))|t(?:o(?:GMTString|S(?:tring|ource)|U(?:TCString|pperCase)|Lo(?:caleString|werCase))|est|a(?:n|int(?:Enabled)?))|i(?:s(?:NaN|Finite)|ndexOf|talics)|d(?:isableExternalCapture|ump|etachEvent)|u(?:n(?:shift|taint|escape|watch)|pdateCommands)|j(?:oin|avaEnabled)|p(?:o(?:p|w)|ush|lugins.refresh|a(?:ddings|rse(?:Int|Float)?)|r(?:int|ompt|eference))|e(?:scape|nableExternalCapture|val|lementFromPoint|x(?:p|ec(?:Script|Command)?))|valueOf|UTC|queryCommand(?:State|Indeterm|Enabled|Value)|f(?:i(?:nd|le(?:ModifiedDate|Size|CreatedDate|UpdatedDate)|xed)|o(?:nt(?:size|color)|rward)|loor|romCharCode)|watch|l(?:ink|o(?:ad|g)|astIndexOf)|a(?:sin|nchor|cos|t(?:tachEvent|ob|an(?:2)?)|pply|lert|b(?:s|ort))|r(?:ou(?:nd|teEvents)|e(?:size(?:By|To)|calc|turnValue|place|verse|l(?:oad|ease(?:Capture|Events)))|andom)|g(?:o|et(?:ResponseHeader|M(?:i(?:nutes|lliseconds)|onth)|Se(?:conds|lection)|Hours|Year|Time(?:zoneOffset)?|Da(?:y|te)|UTC(?:M(?:i(?:nutes|lliseconds)|onth)|Seconds|Hours|Da(?:y|te)|FullYear)|FullYear|A(?:ttention|llResponseHeaders)))|m(?:in|ove(?:B(?:y|elow)|To(?:Absolute)?|Above)|ergeAttributes|a(?:tch|rgins|x))|b(?:toa|ig|o(?:ld|rderWidths)|link|ack))\b(?=\()/
243
token : ["punctuation.operator", "support.function.dom"],
244
regex : /(\.)(s(?:ub(?:stringData|mit)|plitText|e(?:t(?:NamedItem|Attribute(?:Node)?)|lect))|has(?:ChildNodes|Feature)|namedItem|c(?:l(?:ick|o(?:se|neNode))|reate(?:C(?:omment|DATASection|aption)|T(?:Head|extNode|Foot)|DocumentFragment|ProcessingInstruction|E(?:ntityReference|lement)|Attribute))|tabIndex|i(?:nsert(?:Row|Before|Cell|Data)|tem)|open|delete(?:Row|C(?:ell|aption)|T(?:Head|Foot)|Data)|focus|write(?:ln)?|a(?:dd|ppend(?:Child|Data))|re(?:set|place(?:Child|Data)|move(?:NamedItem|Child|Attribute(?:Node)?)?)|get(?:NamedItem|Element(?:sBy(?:Name|TagName)|ById)|Attribute(?:Node)?)|blur)\b(?=\()/
246
token : ["punctuation.operator", "support.constant"],
247
regex : /(\.)(s(?:ystemLanguage|cr(?:ipts|ollbars|een(?:X|Y|Top|Left))|t(?:yle(?:Sheets)?|atus(?:Text|bar)?)|ibling(?:Below|Above)|ource|uffixes|e(?:curity(?:Policy)?|l(?:ection|f)))|h(?:istory|ost(?:name)?|as(?:h|Focus))|y|X(?:MLDocument|SLDocument)|n(?:ext|ame(?:space(?:s|URI)|Prop))|M(?:IN_VALUE|AX_VALUE)|c(?:haracterSet|o(?:n(?:structor|trollers)|okieEnabled|lorDepth|mp(?:onents|lete))|urrent|puClass|l(?:i(?:p(?:boardData)?|entInformation)|osed|asses)|alle(?:e|r)|rypto)|t(?:o(?:olbar|p)|ext(?:Transform|Indent|Decoration|Align)|ags)|SQRT(?:1_2|2)|i(?:n(?:ner(?:Height|Width)|put)|ds|gnoreCase)|zIndex|o(?:scpu|n(?:readystatechange|Line)|uter(?:Height|Width)|p(?:sProfile|ener)|ffscreenBuffering)|NEGATIVE_INFINITY|d(?:i(?:splay|alog(?:Height|Top|Width|Left|Arguments)|rectories)|e(?:scription|fault(?:Status|Ch(?:ecked|arset)|View)))|u(?:ser(?:Profile|Language|Agent)|n(?:iqueID|defined)|pdateInterval)|_content|p(?:ixelDepth|ort|ersonalbar|kcs11|l(?:ugins|atform)|a(?:thname|dding(?:Right|Bottom|Top|Left)|rent(?:Window|Layer)?|ge(?:X(?:Offset)?|Y(?:Offset)?))|r(?:o(?:to(?:col|type)|duct(?:Sub)?|mpter)|e(?:vious|fix)))|e(?:n(?:coding|abledPlugin)|x(?:ternal|pando)|mbeds)|v(?:isibility|endor(?:Sub)?|Linkcolor)|URLUnencoded|P(?:I|OSITIVE_INFINITY)|f(?:ilename|o(?:nt(?:Size|Family|Weight)|rmName)|rame(?:s|Element)|gColor)|E|whiteSpace|l(?:i(?:stStyleType|n(?:eHeight|kColor))|o(?:ca(?:tion(?:bar)?|lName)|wsrc)|e(?:ngth|ft(?:Context)?)|a(?:st(?:M(?:odified|atch)|Index|Paren)|yer(?:s|X)|nguage))|a(?:pp(?:MinorVersion|Name|Co(?:deName|re)|Version)|vail(?:Height|Top|Width|Left)|ll|r(?:ity|guments)|Linkcolor|bove)|r(?:ight(?:Context)?|e(?:sponse(?:XML|Text)|adyState))|global|x|m(?:imeTypes|ultiline|enubar|argin(?:Right|Bottom|Top|Left))|L(?:N(?:10|2)|OG(?:10E|2E))|b(?:o(?:ttom|rder(?:Width|RightWidth|BottomWidth|Style|Color|TopWidth|LeftWidth))|ufferDepth|elow|ackground(?:Color|Image)))\b/
249
token : ["storage.type", "punctuation.operator", "support.function.firebug"],
250
regex : /(console)(\.)(warn|info|log|error|time|timeEnd|assert)\b/
252
token : keywordMapper,
255
token : "keyword.operator",
256
regex : /--|\+\+|[!$%&*+\-~]|===|==|=|!=|!==|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\|\||\?\:|\*=|%=|\+=|\-=|&=|\^=/,
259
token : "punctuation.operator",
260
regex : /\?|\:|\,|\;|\./,
263
token : "paren.lparen",
267
token : "paren.rparen",
270
token : "keyword.operator",
279
DocCommentHighlightRules.getStartRule("doc-start"),
281
token : "comment", // multi line comment
283
next : "comment_regex_allowed"
289
token: "string.regexp",
304
token: "regexp.keyword.operator",
305
regex: "\\\\(?:u[\\da-fA-F]{4}|x[\\da-fA-F]{2}|.)"
307
token: "string.regexp",
312
regex: /\{\d+\b,?\d*\}[+*]|[+*$^?][+*]|[$^][?]|\?{3,}/
314
token : "constant.language.escape",
315
regex: /\(\?[:=!]|\)|\{\d+\b,?\d*\}|[+*]\?|[()$^+*?]/
317
token : "constant.language.delimiter",
320
token: "constant.language.escape",
322
next: "regex_character_class",
328
defaultToken: "string.regexp"
331
"regex_character_class": [
333
token: "regexp.keyword.operator",
334
regex: "\\\\(?:u[\\da-fA-F]{4}|x[\\da-fA-F]{2}|.)"
336
token: "constant.language.escape",
340
token: "constant.language.escape",
347
defaultToken: "string.regexp.charachterclass"
350
"function_arguments": [
352
token: "variable.parameter",
355
token: "punctuation.operator",
358
token: "punctuation.operator",
366
"comment_regex_allowed" : [
367
{token : "comment", regex : "\\*\\/", next : "start"},
368
{defaultToken : "comment"}
371
{token : "comment", regex : "\\*\\/", next : "no_regex"},
372
{defaultToken : "comment"}
376
token : "constant.language.escape",
387
defaultToken: "string"
392
token : "constant.language.escape",
403
defaultToken: "string"
408
this.embedRules(DocCommentHighlightRules, "doc-",
409
[ DocCommentHighlightRules.getEndRule("no_regex") ]);
412
oop.inherits(JavaScriptHighlightRules, TextHighlightRules);
414
exports.JavaScriptHighlightRules = JavaScriptHighlightRules;
417
define('ace/mode/doc_comment_highlight_rules', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/text_highlight_rules'], function(require, exports, module) {
420
var oop = require("../lib/oop");
421
var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
423
var DocCommentHighlightRules = function() {
427
token : "comment.doc.tag",
428
regex : "@[\\w\\d_]+" // TODO: fix email addresses
430
token : "comment.doc.tag",
433
defaultToken : "comment.doc"
438
oop.inherits(DocCommentHighlightRules, TextHighlightRules);
440
DocCommentHighlightRules.getStartRule = function(start) {
442
token : "comment.doc", // doc comment
443
regex : "\\/\\*(?=\\*)",
448
DocCommentHighlightRules.getEndRule = function (start) {
450
token : "comment.doc", // closing comment
457
exports.DocCommentHighlightRules = DocCommentHighlightRules;
461
define('ace/mode/matching_brace_outdent', ['require', 'exports', 'module' , 'ace/range'], function(require, exports, module) {
464
var Range = require("../range").Range;
466
var MatchingBraceOutdent = function() {};
470
this.checkOutdent = function(line, input) {
471
if (! /^\s+$/.test(line))
474
return /^\s*\}/.test(input);
477
this.autoOutdent = function(doc, row) {
478
var line = doc.getLine(row);
479
var match = line.match(/^(\s*\})/);
481
if (!match) return 0;
483
var column = match[1].length;
484
var openBracePos = doc.findMatchingBracket({row: row, column: column});
486
if (!openBracePos || openBracePos.row == row) return 0;
488
var indent = this.$getIndent(doc.getLine(openBracePos.row));
489
doc.replace(new Range(row, 0, row, column-1), indent);
492
this.$getIndent = function(line) {
493
return line.match(/^\s*/)[0];
496
}).call(MatchingBraceOutdent.prototype);
498
exports.MatchingBraceOutdent = MatchingBraceOutdent;
501
define('ace/mode/behaviour/cstyle', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/behaviour', 'ace/token_iterator', 'ace/lib/lang'], function(require, exports, module) {
504
var oop = require("../../lib/oop");
505
var Behaviour = require("../behaviour").Behaviour;
506
var TokenIterator = require("../../token_iterator").TokenIterator;
507
var lang = require("../../lib/lang");
509
var SAFE_INSERT_IN_TOKENS =
510
["text", "paren.rparen", "punctuation.operator"];
511
var SAFE_INSERT_BEFORE_TOKENS =
512
["text", "paren.rparen", "punctuation.operator", "comment"];
515
var autoInsertedBrackets = 0;
516
var autoInsertedRow = -1;
517
var autoInsertedLineEnd = "";
518
var maybeInsertedBrackets = 0;
519
var maybeInsertedRow = -1;
520
var maybeInsertedLineStart = "";
521
var maybeInsertedLineEnd = "";
523
var CstyleBehaviour = function () {
525
CstyleBehaviour.isSaneInsertion = function(editor, session) {
526
var cursor = editor.getCursorPosition();
527
var iterator = new TokenIterator(session, cursor.row, cursor.column);
528
if (!this.$matchTokenType(iterator.getCurrentToken() || "text", SAFE_INSERT_IN_TOKENS)) {
529
var iterator2 = new TokenIterator(session, cursor.row, cursor.column + 1);
530
if (!this.$matchTokenType(iterator2.getCurrentToken() || "text", SAFE_INSERT_IN_TOKENS))
533
iterator.stepForward();
534
return iterator.getCurrentTokenRow() !== cursor.row ||
535
this.$matchTokenType(iterator.getCurrentToken() || "text", SAFE_INSERT_BEFORE_TOKENS);
538
CstyleBehaviour.$matchTokenType = function(token, types) {
539
return types.indexOf(token.type || token) > -1;
542
CstyleBehaviour.recordAutoInsert = function(editor, session, bracket) {
543
var cursor = editor.getCursorPosition();
544
var line = session.doc.getLine(cursor.row);
545
if (!this.isAutoInsertedClosing(cursor, line, autoInsertedLineEnd[0]))
546
autoInsertedBrackets = 0;
547
autoInsertedRow = cursor.row;
548
autoInsertedLineEnd = bracket + line.substr(cursor.column);
549
autoInsertedBrackets++;
552
CstyleBehaviour.recordMaybeInsert = function(editor, session, bracket) {
553
var cursor = editor.getCursorPosition();
554
var line = session.doc.getLine(cursor.row);
555
if (!this.isMaybeInsertedClosing(cursor, line))
556
maybeInsertedBrackets = 0;
557
maybeInsertedRow = cursor.row;
558
maybeInsertedLineStart = line.substr(0, cursor.column) + bracket;
559
maybeInsertedLineEnd = line.substr(cursor.column);
560
maybeInsertedBrackets++;
563
CstyleBehaviour.isAutoInsertedClosing = function(cursor, line, bracket) {
564
return autoInsertedBrackets > 0 &&
565
cursor.row === autoInsertedRow &&
566
bracket === autoInsertedLineEnd[0] &&
567
line.substr(cursor.column) === autoInsertedLineEnd;
570
CstyleBehaviour.isMaybeInsertedClosing = function(cursor, line) {
571
return maybeInsertedBrackets > 0 &&
572
cursor.row === maybeInsertedRow &&
573
line.substr(cursor.column) === maybeInsertedLineEnd &&
574
line.substr(0, cursor.column) == maybeInsertedLineStart;
577
CstyleBehaviour.popAutoInsertedClosing = function() {
578
autoInsertedLineEnd = autoInsertedLineEnd.substr(1);
579
autoInsertedBrackets--;
582
CstyleBehaviour.clearMaybeInsertedClosing = function() {
583
maybeInsertedBrackets = 0;
584
maybeInsertedRow = -1;
587
this.add("braces", "insertion", function (state, action, editor, session, text) {
588
var cursor = editor.getCursorPosition();
589
var line = session.doc.getLine(cursor.row);
591
var selection = editor.getSelectionRange();
592
var selected = session.doc.getTextRange(selection);
593
if (selected !== "" && selected !== "{" && editor.getWrapBehavioursEnabled()) {
595
text: '{' + selected + '}',
598
} else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
599
if (/[\]\}\)]/.test(line[cursor.column])) {
600
CstyleBehaviour.recordAutoInsert(editor, session, "}");
606
CstyleBehaviour.recordMaybeInsert(editor, session, "{");
613
} else if (text == '}') {
614
var rightChar = line.substring(cursor.column, cursor.column + 1);
615
if (rightChar == '}') {
616
var matching = session.$findOpeningBracket('}', {column: cursor.column + 1, row: cursor.row});
617
if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) {
618
CstyleBehaviour.popAutoInsertedClosing();
625
} else if (text == "\n" || text == "\r\n") {
627
if (CstyleBehaviour.isMaybeInsertedClosing(cursor, line)) {
628
closing = lang.stringRepeat("}", maybeInsertedBrackets);
629
CstyleBehaviour.clearMaybeInsertedClosing();
631
var rightChar = line.substring(cursor.column, cursor.column + 1);
632
if (rightChar == '}' || closing !== "") {
633
var openBracePos = session.findMatchingBracket({row: cursor.row, column: cursor.column}, '}');
637
var indent = this.getNextLineIndent(state, line.substring(0, cursor.column), session.getTabString());
638
var next_indent = this.$getIndent(line);
641
text: '\n' + indent + '\n' + next_indent + closing,
642
selection: [1, indent.length, 1, indent.length]
648
this.add("braces", "deletion", function (state, action, editor, session, range) {
649
var selected = session.doc.getTextRange(range);
650
if (!range.isMultiLine() && selected == '{') {
651
var line = session.doc.getLine(range.start.row);
652
var rightChar = line.substring(range.end.column, range.end.column + 1);
653
if (rightChar == '}') {
657
maybeInsertedBrackets--;
662
this.add("parens", "insertion", function (state, action, editor, session, text) {
664
var selection = editor.getSelectionRange();
665
var selected = session.doc.getTextRange(selection);
666
if (selected !== "" && editor.getWrapBehavioursEnabled()) {
668
text: '(' + selected + ')',
671
} else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
672
CstyleBehaviour.recordAutoInsert(editor, session, ")");
678
} else if (text == ')') {
679
var cursor = editor.getCursorPosition();
680
var line = session.doc.getLine(cursor.row);
681
var rightChar = line.substring(cursor.column, cursor.column + 1);
682
if (rightChar == ')') {
683
var matching = session.$findOpeningBracket(')', {column: cursor.column + 1, row: cursor.row});
684
if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) {
685
CstyleBehaviour.popAutoInsertedClosing();
695
this.add("parens", "deletion", function (state, action, editor, session, range) {
696
var selected = session.doc.getTextRange(range);
697
if (!range.isMultiLine() && selected == '(') {
698
var line = session.doc.getLine(range.start.row);
699
var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
700
if (rightChar == ')') {
707
this.add("brackets", "insertion", function (state, action, editor, session, text) {
709
var selection = editor.getSelectionRange();
710
var selected = session.doc.getTextRange(selection);
711
if (selected !== "" && editor.getWrapBehavioursEnabled()) {
713
text: '[' + selected + ']',
716
} else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
717
CstyleBehaviour.recordAutoInsert(editor, session, "]");
723
} else if (text == ']') {
724
var cursor = editor.getCursorPosition();
725
var line = session.doc.getLine(cursor.row);
726
var rightChar = line.substring(cursor.column, cursor.column + 1);
727
if (rightChar == ']') {
728
var matching = session.$findOpeningBracket(']', {column: cursor.column + 1, row: cursor.row});
729
if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) {
730
CstyleBehaviour.popAutoInsertedClosing();
740
this.add("brackets", "deletion", function (state, action, editor, session, range) {
741
var selected = session.doc.getTextRange(range);
742
if (!range.isMultiLine() && selected == '[') {
743
var line = session.doc.getLine(range.start.row);
744
var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
745
if (rightChar == ']') {
752
this.add("string_dquotes", "insertion", function (state, action, editor, session, text) {
753
if (text == '"' || text == "'") {
755
var selection = editor.getSelectionRange();
756
var selected = session.doc.getTextRange(selection);
757
if (selected !== "" && selected !== "'" && selected != '"' && editor.getWrapBehavioursEnabled()) {
759
text: quote + selected + quote,
763
var cursor = editor.getCursorPosition();
764
var line = session.doc.getLine(cursor.row);
765
var leftChar = line.substring(cursor.column-1, cursor.column);
766
if (leftChar == '\\') {
769
var tokens = session.getTokens(selection.start.row);
771
var quotepos = -1; // Track whether we're inside an open quote.
773
for (var x = 0; x < tokens.length; x++) {
775
if (token.type == "string") {
777
} else if (quotepos < 0) {
778
quotepos = token.value.indexOf(quote);
780
if ((token.value.length + col) > selection.start.column) {
783
col += tokens[x].value.length;
785
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)))) {
786
if (!CstyleBehaviour.isSaneInsertion(editor, session))
792
} else if (token && token.type === "string") {
793
var rightChar = line.substring(cursor.column, cursor.column + 1);
794
if (rightChar == quote) {
805
this.add("string_dquotes", "deletion", function (state, action, editor, session, range) {
806
var selected = session.doc.getTextRange(range);
807
if (!range.isMultiLine() && (selected == '"' || selected == "'")) {
808
var line = session.doc.getLine(range.start.row);
809
var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
810
if (rightChar == selected) {
819
oop.inherits(CstyleBehaviour, Behaviour);
821
exports.CstyleBehaviour = CstyleBehaviour;
824
define('ace/mode/folding/cstyle', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/range', 'ace/mode/folding/fold_mode'], function(require, exports, module) {
827
var oop = require("../../lib/oop");
828
var Range = require("../../range").Range;
829
var BaseFoldMode = require("./fold_mode").FoldMode;
831
var FoldMode = exports.FoldMode = function(commentRegex) {
833
this.foldingStartMarker = new RegExp(
834
this.foldingStartMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.start)
836
this.foldingStopMarker = new RegExp(
837
this.foldingStopMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.end)
841
oop.inherits(FoldMode, BaseFoldMode);
845
this.foldingStartMarker = /(\{|\[)[^\}\]]*$|^\s*(\/\*)/;
846
this.foldingStopMarker = /^[^\[\{]*(\}|\])|^[\s\*]*(\*\/)/;
848
this.getFoldWidgetRange = function(session, foldStyle, row) {
849
var line = session.getLine(row);
850
var match = line.match(this.foldingStartMarker);
855
return this.openingBracketBlock(session, match[1], row, i);
857
return session.getCommentFoldRange(row, i + match[0].length, 1);
860
if (foldStyle !== "markbeginend")
863
var match = line.match(this.foldingStopMarker);
865
var i = match.index + match[0].length;
868
return this.closingBracketBlock(session, match[1], row, i);
870
return session.getCommentFoldRange(row, i, -1);
874
}).call(FoldMode.prototype);