1
/* ***** BEGIN LICENSE BLOCK *****
2
* Distributed under the BSD license:
4
* Copyright (c) 2012, 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/typescript', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/javascript', 'ace/tokenizer', 'ace/mode/typescript_highlight_rules', 'ace/mode/behaviour/cstyle', 'ace/mode/folding/cstyle', 'ace/mode/matching_brace_outdent'], function(require, exports, module) {
34
var oop = require("../lib/oop");
35
var jsMode = require("./javascript").Mode;
36
var Tokenizer = require("../tokenizer").Tokenizer;
37
var TypeScriptHighlightRules = require("./typescript_highlight_rules").TypeScriptHighlightRules;
38
var CstyleBehaviour = require("./behaviour/cstyle").CstyleBehaviour;
39
var CStyleFoldMode = require("./folding/cstyle").FoldMode;
40
var MatchingBraceOutdent = require("./matching_brace_outdent").MatchingBraceOutdent;
42
var Mode = function() {
43
var highlighter = new TypeScriptHighlightRules();
45
this.$tokenizer = new Tokenizer(highlighter.getRules());
46
this.$outdent = new MatchingBraceOutdent();
47
this.$behaviour = new CstyleBehaviour();
48
this.foldingRules = new CStyleFoldMode();
50
oop.inherits(Mode, jsMode);
53
this.createWorker = function(session) {
56
}).call(Mode.prototype);
61
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) {
64
var oop = require("../lib/oop");
65
var TextMode = require("./text").Mode;
66
var Tokenizer = require("../tokenizer").Tokenizer;
67
var JavaScriptHighlightRules = require("./javascript_highlight_rules").JavaScriptHighlightRules;
68
var MatchingBraceOutdent = require("./matching_brace_outdent").MatchingBraceOutdent;
69
var Range = require("../range").Range;
70
var WorkerClient = require("../worker/worker_client").WorkerClient;
71
var CstyleBehaviour = require("./behaviour/cstyle").CstyleBehaviour;
72
var CStyleFoldMode = require("./folding/cstyle").FoldMode;
74
var Mode = function() {
75
this.$tokenizer = new Tokenizer(new JavaScriptHighlightRules().getRules());
76
this.$outdent = new MatchingBraceOutdent();
77
this.$behaviour = new CstyleBehaviour();
78
this.foldingRules = new CStyleFoldMode();
80
oop.inherits(Mode, TextMode);
84
this.lineCommentStart = "//";
85
this.blockComment = {start: "/*", end: "*/"};
87
this.getNextLineIndent = function(state, line, tab) {
88
var indent = this.$getIndent(line);
90
var tokenizedLine = this.$tokenizer.getLineTokens(line, state);
91
var tokens = tokenizedLine.tokens;
92
var endState = tokenizedLine.state;
94
if (tokens.length && tokens[tokens.length-1].type == "comment") {
98
if (state == "start" || state == "no_regex") {
99
var match = line.match(/^.*(?:\bcase\b.*\:|[\{\(\[])\s*$/);
103
} else if (state == "doc-start") {
104
if (endState == "start" || endState == "no_regex") {
107
var match = line.match(/^\s*(\/?)\*/);
119
this.checkOutdent = function(state, line, input) {
120
return this.$outdent.checkOutdent(line, input);
123
this.autoOutdent = function(state, doc, row) {
124
this.$outdent.autoOutdent(doc, row);
127
this.createWorker = function(session) {
128
var worker = new WorkerClient(["ace"], "ace/mode/javascript_worker", "JavaScriptWorker");
129
worker.attachToDocument(session.getDocument());
131
worker.on("jslint", function(results) {
132
session.setAnnotations(results.data);
135
worker.on("terminate", function() {
136
session.clearAnnotations();
142
}).call(Mode.prototype);
147
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) {
150
var oop = require("../lib/oop");
151
var DocCommentHighlightRules = require("./doc_comment_highlight_rules").DocCommentHighlightRules;
152
var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
154
var JavaScriptHighlightRules = function() {
155
var keywordMapper = this.createKeywordMapper({
157
"Array|Boolean|Date|Function|Iterator|Number|Object|RegExp|String|Proxy|" + // Constructors
158
"Namespace|QName|XML|XMLList|" + // E4X
159
"ArrayBuffer|Float32Array|Float64Array|Int16Array|Int32Array|Int8Array|" +
160
"Uint16Array|Uint32Array|Uint8Array|Uint8ClampedArray|" +
161
"Error|EvalError|InternalError|RangeError|ReferenceError|StopIteration|" + // Errors
162
"SyntaxError|TypeError|URIError|" +
163
"decodeURI|decodeURIComponent|encodeURI|encodeURIComponent|eval|isFinite|" + // Non-constructor functions
164
"isNaN|parseFloat|parseInt|" +
165
"JSON|Math|" + // Other
166
"this|arguments|prototype|window|document" , // Pseudo
168
"const|yield|import|get|set|" +
169
"break|case|catch|continue|default|delete|do|else|finally|for|function|" +
170
"if|in|instanceof|new|return|switch|throw|try|typeof|let|var|while|with|debugger|" +
171
"__parent__|__count__|escape|unescape|with|__proto__|" +
172
"class|enum|extends|super|export|implements|private|public|interface|package|protected|static",
174
"const|let|var|function",
176
"null|Infinity|NaN|undefined",
179
"constant.language.boolean": "true|false"
181
var kwBeforeRe = "case|do|else|finally|in|instanceof|return|throw|try|typeof|yield|void";
182
var identifierRe = "[a-zA-Z\\$_\u00a1-\uffff][a-zA-Z\\d\\$_\u00a1-\uffff]*\\b";
184
var escapedRe = "\\\\(?:x[0-9a-fA-F]{2}|" + // hex
185
"u[0-9a-fA-F]{4}|" + // unicode
186
"[0-2][0-7]{0,2}|" + // oct
187
"3[0-6][0-7]?|" + // oct
189
"[4-7][0-7]?|" + //oct
198
DocCommentHighlightRules.getStartRule("doc-start"),
200
token : "comment", // multi line comment
212
token : "constant.numeric", // hex
213
regex : /0[xX][0-9a-fA-F]+\b/
215
token : "constant.numeric", // float
216
regex : /[+-]?\d+(?:(?:\.\d*)?(?:[eE][+-]?\d+)?)?\b/
219
"storage.type", "punctuation.operator", "support.function",
220
"punctuation.operator", "entity.name.function", "text","keyword.operator"
222
regex : "(" + identifierRe + ")(\\.)(prototype)(\\.)(" + identifierRe +")(\\s*)(=)",
223
next: "function_arguments"
226
"storage.type", "punctuation.operator", "entity.name.function", "text",
227
"keyword.operator", "text", "storage.type", "text", "paren.lparen"
229
regex : "(" + identifierRe + ")(\\.)(" + identifierRe +")(\\s*)(=)(\\s*)(function)(\\s*)(\\()",
230
next: "function_arguments"
233
"entity.name.function", "text", "keyword.operator", "text", "storage.type",
234
"text", "paren.lparen"
236
regex : "(" + identifierRe +")(\\s*)(=)(\\s*)(function)(\\s*)(\\()",
237
next: "function_arguments"
240
"storage.type", "punctuation.operator", "entity.name.function", "text",
241
"keyword.operator", "text",
242
"storage.type", "text", "entity.name.function", "text", "paren.lparen"
244
regex : "(" + identifierRe + ")(\\.)(" + identifierRe +")(\\s*)(=)(\\s*)(function)(\\s+)(\\w+)(\\s*)(\\()",
245
next: "function_arguments"
248
"storage.type", "text", "entity.name.function", "text", "paren.lparen"
250
regex : "(function)(\\s+)(" + identifierRe + ")(\\s*)(\\()",
251
next: "function_arguments"
254
"entity.name.function", "text", "punctuation.operator",
255
"text", "storage.type", "text", "paren.lparen"
257
regex : "(" + identifierRe + ")(\\s*)(:)(\\s*)(function)(\\s*)(\\()",
258
next: "function_arguments"
261
"text", "text", "storage.type", "text", "paren.lparen"
263
regex : "(:)(\\s*)(function)(\\s*)(\\()",
264
next: "function_arguments"
267
regex : "(?:" + kwBeforeRe + ")\\b",
270
token : ["punctuation.operator", "support.function"],
271
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(?=\()/
273
token : ["punctuation.operator", "support.function.dom"],
274
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(?=\()/
276
token : ["punctuation.operator", "support.constant"],
277
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/
279
token : ["storage.type", "punctuation.operator", "support.function.firebug"],
280
regex : /(console)(\.)(warn|info|log|error|time|timeEnd|assert)\b/
282
token : keywordMapper,
285
token : "keyword.operator",
286
regex : /--|\+\+|[!$%&*+\-~]|===|==|=|!=|!==|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\|\||\?\:|\*=|%=|\+=|\-=|&=|\^=/,
289
token : "punctuation.operator",
290
regex : /\?|\:|\,|\;|\./,
293
token : "paren.lparen",
297
token : "paren.rparen",
300
token : "keyword.operator",
309
DocCommentHighlightRules.getStartRule("doc-start"),
311
token : "comment", // multi line comment
313
next : "comment_regex_allowed"
319
token: "string.regexp",
334
token: "regexp.keyword.operator",
335
regex: "\\\\(?:u[\\da-fA-F]{4}|x[\\da-fA-F]{2}|.)"
337
token: "string.regexp",
342
regex: /\{\d+\b,?\d*\}[+*]|[+*$^?][+*]|[$^][?]|\?{3,}/
344
token : "constant.language.escape",
345
regex: /\(\?[:=!]|\)|\{\d+\b,?\d*\}|[+*]\?|[()$^+*?]/
347
token : "constant.language.delimiter",
350
token: "constant.language.escape",
352
next: "regex_character_class",
358
defaultToken: "string.regexp"
361
"regex_character_class": [
363
token: "regexp.keyword.operator",
364
regex: "\\\\(?:u[\\da-fA-F]{4}|x[\\da-fA-F]{2}|.)"
366
token: "constant.language.escape",
370
token: "constant.language.escape",
377
defaultToken: "string.regexp.charachterclass"
380
"function_arguments": [
382
token: "variable.parameter",
385
token: "punctuation.operator",
388
token: "punctuation.operator",
396
"comment_regex_allowed" : [
397
{token : "comment", regex : "\\*\\/", next : "start"},
398
{defaultToken : "comment"}
401
{token : "comment", regex : "\\*\\/", next : "no_regex"},
402
{defaultToken : "comment"}
406
token : "constant.language.escape",
417
defaultToken: "string"
422
token : "constant.language.escape",
433
defaultToken: "string"
438
this.embedRules(DocCommentHighlightRules, "doc-",
439
[ DocCommentHighlightRules.getEndRule("no_regex") ]);
442
oop.inherits(JavaScriptHighlightRules, TextHighlightRules);
444
exports.JavaScriptHighlightRules = JavaScriptHighlightRules;
447
define('ace/mode/doc_comment_highlight_rules', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/text_highlight_rules'], function(require, exports, module) {
450
var oop = require("../lib/oop");
451
var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
453
var DocCommentHighlightRules = function() {
457
token : "comment.doc.tag",
458
regex : "@[\\w\\d_]+" // TODO: fix email addresses
460
token : "comment.doc.tag",
463
defaultToken : "comment.doc"
468
oop.inherits(DocCommentHighlightRules, TextHighlightRules);
470
DocCommentHighlightRules.getStartRule = function(start) {
472
token : "comment.doc", // doc comment
473
regex : "\\/\\*(?=\\*)",
478
DocCommentHighlightRules.getEndRule = function (start) {
480
token : "comment.doc", // closing comment
487
exports.DocCommentHighlightRules = DocCommentHighlightRules;
491
define('ace/mode/matching_brace_outdent', ['require', 'exports', 'module' , 'ace/range'], function(require, exports, module) {
494
var Range = require("../range").Range;
496
var MatchingBraceOutdent = function() {};
500
this.checkOutdent = function(line, input) {
501
if (! /^\s+$/.test(line))
504
return /^\s*\}/.test(input);
507
this.autoOutdent = function(doc, row) {
508
var line = doc.getLine(row);
509
var match = line.match(/^(\s*\})/);
511
if (!match) return 0;
513
var column = match[1].length;
514
var openBracePos = doc.findMatchingBracket({row: row, column: column});
516
if (!openBracePos || openBracePos.row == row) return 0;
518
var indent = this.$getIndent(doc.getLine(openBracePos.row));
519
doc.replace(new Range(row, 0, row, column-1), indent);
522
this.$getIndent = function(line) {
523
return line.match(/^\s*/)[0];
526
}).call(MatchingBraceOutdent.prototype);
528
exports.MatchingBraceOutdent = MatchingBraceOutdent;
531
define('ace/mode/behaviour/cstyle', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/behaviour', 'ace/token_iterator', 'ace/lib/lang'], function(require, exports, module) {
534
var oop = require("../../lib/oop");
535
var Behaviour = require("../behaviour").Behaviour;
536
var TokenIterator = require("../../token_iterator").TokenIterator;
537
var lang = require("../../lib/lang");
539
var SAFE_INSERT_IN_TOKENS =
540
["text", "paren.rparen", "punctuation.operator"];
541
var SAFE_INSERT_BEFORE_TOKENS =
542
["text", "paren.rparen", "punctuation.operator", "comment"];
545
var autoInsertedBrackets = 0;
546
var autoInsertedRow = -1;
547
var autoInsertedLineEnd = "";
548
var maybeInsertedBrackets = 0;
549
var maybeInsertedRow = -1;
550
var maybeInsertedLineStart = "";
551
var maybeInsertedLineEnd = "";
553
var CstyleBehaviour = function () {
555
CstyleBehaviour.isSaneInsertion = function(editor, session) {
556
var cursor = editor.getCursorPosition();
557
var iterator = new TokenIterator(session, cursor.row, cursor.column);
558
if (!this.$matchTokenType(iterator.getCurrentToken() || "text", SAFE_INSERT_IN_TOKENS)) {
559
var iterator2 = new TokenIterator(session, cursor.row, cursor.column + 1);
560
if (!this.$matchTokenType(iterator2.getCurrentToken() || "text", SAFE_INSERT_IN_TOKENS))
563
iterator.stepForward();
564
return iterator.getCurrentTokenRow() !== cursor.row ||
565
this.$matchTokenType(iterator.getCurrentToken() || "text", SAFE_INSERT_BEFORE_TOKENS);
568
CstyleBehaviour.$matchTokenType = function(token, types) {
569
return types.indexOf(token.type || token) > -1;
572
CstyleBehaviour.recordAutoInsert = function(editor, session, bracket) {
573
var cursor = editor.getCursorPosition();
574
var line = session.doc.getLine(cursor.row);
575
if (!this.isAutoInsertedClosing(cursor, line, autoInsertedLineEnd[0]))
576
autoInsertedBrackets = 0;
577
autoInsertedRow = cursor.row;
578
autoInsertedLineEnd = bracket + line.substr(cursor.column);
579
autoInsertedBrackets++;
582
CstyleBehaviour.recordMaybeInsert = function(editor, session, bracket) {
583
var cursor = editor.getCursorPosition();
584
var line = session.doc.getLine(cursor.row);
585
if (!this.isMaybeInsertedClosing(cursor, line))
586
maybeInsertedBrackets = 0;
587
maybeInsertedRow = cursor.row;
588
maybeInsertedLineStart = line.substr(0, cursor.column) + bracket;
589
maybeInsertedLineEnd = line.substr(cursor.column);
590
maybeInsertedBrackets++;
593
CstyleBehaviour.isAutoInsertedClosing = function(cursor, line, bracket) {
594
return autoInsertedBrackets > 0 &&
595
cursor.row === autoInsertedRow &&
596
bracket === autoInsertedLineEnd[0] &&
597
line.substr(cursor.column) === autoInsertedLineEnd;
600
CstyleBehaviour.isMaybeInsertedClosing = function(cursor, line) {
601
return maybeInsertedBrackets > 0 &&
602
cursor.row === maybeInsertedRow &&
603
line.substr(cursor.column) === maybeInsertedLineEnd &&
604
line.substr(0, cursor.column) == maybeInsertedLineStart;
607
CstyleBehaviour.popAutoInsertedClosing = function() {
608
autoInsertedLineEnd = autoInsertedLineEnd.substr(1);
609
autoInsertedBrackets--;
612
CstyleBehaviour.clearMaybeInsertedClosing = function() {
613
maybeInsertedBrackets = 0;
614
maybeInsertedRow = -1;
617
this.add("braces", "insertion", function (state, action, editor, session, text) {
618
var cursor = editor.getCursorPosition();
619
var line = session.doc.getLine(cursor.row);
621
var selection = editor.getSelectionRange();
622
var selected = session.doc.getTextRange(selection);
623
if (selected !== "" && selected !== "{" && editor.getWrapBehavioursEnabled()) {
625
text: '{' + selected + '}',
628
} else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
629
if (/[\]\}\)]/.test(line[cursor.column])) {
630
CstyleBehaviour.recordAutoInsert(editor, session, "}");
636
CstyleBehaviour.recordMaybeInsert(editor, session, "{");
643
} else if (text == '}') {
644
var rightChar = line.substring(cursor.column, cursor.column + 1);
645
if (rightChar == '}') {
646
var matching = session.$findOpeningBracket('}', {column: cursor.column + 1, row: cursor.row});
647
if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) {
648
CstyleBehaviour.popAutoInsertedClosing();
655
} else if (text == "\n" || text == "\r\n") {
657
if (CstyleBehaviour.isMaybeInsertedClosing(cursor, line)) {
658
closing = lang.stringRepeat("}", maybeInsertedBrackets);
659
CstyleBehaviour.clearMaybeInsertedClosing();
661
var rightChar = line.substring(cursor.column, cursor.column + 1);
662
if (rightChar == '}' || closing !== "") {
663
var openBracePos = session.findMatchingBracket({row: cursor.row, column: cursor.column}, '}');
667
var indent = this.getNextLineIndent(state, line.substring(0, cursor.column), session.getTabString());
668
var next_indent = this.$getIndent(line);
671
text: '\n' + indent + '\n' + next_indent + closing,
672
selection: [1, indent.length, 1, indent.length]
678
this.add("braces", "deletion", function (state, action, editor, session, range) {
679
var selected = session.doc.getTextRange(range);
680
if (!range.isMultiLine() && selected == '{') {
681
var line = session.doc.getLine(range.start.row);
682
var rightChar = line.substring(range.end.column, range.end.column + 1);
683
if (rightChar == '}') {
687
maybeInsertedBrackets--;
692
this.add("parens", "insertion", function (state, action, editor, session, text) {
694
var selection = editor.getSelectionRange();
695
var selected = session.doc.getTextRange(selection);
696
if (selected !== "" && editor.getWrapBehavioursEnabled()) {
698
text: '(' + selected + ')',
701
} else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
702
CstyleBehaviour.recordAutoInsert(editor, session, ")");
708
} else if (text == ')') {
709
var cursor = editor.getCursorPosition();
710
var line = session.doc.getLine(cursor.row);
711
var rightChar = line.substring(cursor.column, cursor.column + 1);
712
if (rightChar == ')') {
713
var matching = session.$findOpeningBracket(')', {column: cursor.column + 1, row: cursor.row});
714
if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) {
715
CstyleBehaviour.popAutoInsertedClosing();
725
this.add("parens", "deletion", function (state, action, editor, session, range) {
726
var selected = session.doc.getTextRange(range);
727
if (!range.isMultiLine() && selected == '(') {
728
var line = session.doc.getLine(range.start.row);
729
var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
730
if (rightChar == ')') {
737
this.add("brackets", "insertion", function (state, action, editor, session, text) {
739
var selection = editor.getSelectionRange();
740
var selected = session.doc.getTextRange(selection);
741
if (selected !== "" && editor.getWrapBehavioursEnabled()) {
743
text: '[' + selected + ']',
746
} else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
747
CstyleBehaviour.recordAutoInsert(editor, session, "]");
753
} else if (text == ']') {
754
var cursor = editor.getCursorPosition();
755
var line = session.doc.getLine(cursor.row);
756
var rightChar = line.substring(cursor.column, cursor.column + 1);
757
if (rightChar == ']') {
758
var matching = session.$findOpeningBracket(']', {column: cursor.column + 1, row: cursor.row});
759
if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) {
760
CstyleBehaviour.popAutoInsertedClosing();
770
this.add("brackets", "deletion", function (state, action, editor, session, range) {
771
var selected = session.doc.getTextRange(range);
772
if (!range.isMultiLine() && selected == '[') {
773
var line = session.doc.getLine(range.start.row);
774
var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
775
if (rightChar == ']') {
782
this.add("string_dquotes", "insertion", function (state, action, editor, session, text) {
783
if (text == '"' || text == "'") {
785
var selection = editor.getSelectionRange();
786
var selected = session.doc.getTextRange(selection);
787
if (selected !== "" && selected !== "'" && selected != '"' && editor.getWrapBehavioursEnabled()) {
789
text: quote + selected + quote,
793
var cursor = editor.getCursorPosition();
794
var line = session.doc.getLine(cursor.row);
795
var leftChar = line.substring(cursor.column-1, cursor.column);
796
if (leftChar == '\\') {
799
var tokens = session.getTokens(selection.start.row);
801
var quotepos = -1; // Track whether we're inside an open quote.
803
for (var x = 0; x < tokens.length; x++) {
805
if (token.type == "string") {
807
} else if (quotepos < 0) {
808
quotepos = token.value.indexOf(quote);
810
if ((token.value.length + col) > selection.start.column) {
813
col += tokens[x].value.length;
815
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)))) {
816
if (!CstyleBehaviour.isSaneInsertion(editor, session))
822
} else if (token && token.type === "string") {
823
var rightChar = line.substring(cursor.column, cursor.column + 1);
824
if (rightChar == quote) {
835
this.add("string_dquotes", "deletion", function (state, action, editor, session, range) {
836
var selected = session.doc.getTextRange(range);
837
if (!range.isMultiLine() && (selected == '"' || selected == "'")) {
838
var line = session.doc.getLine(range.start.row);
839
var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
840
if (rightChar == selected) {
849
oop.inherits(CstyleBehaviour, Behaviour);
851
exports.CstyleBehaviour = CstyleBehaviour;
854
define('ace/mode/folding/cstyle', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/range', 'ace/mode/folding/fold_mode'], function(require, exports, module) {
857
var oop = require("../../lib/oop");
858
var Range = require("../../range").Range;
859
var BaseFoldMode = require("./fold_mode").FoldMode;
861
var FoldMode = exports.FoldMode = function(commentRegex) {
863
this.foldingStartMarker = new RegExp(
864
this.foldingStartMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.start)
866
this.foldingStopMarker = new RegExp(
867
this.foldingStopMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.end)
871
oop.inherits(FoldMode, BaseFoldMode);
875
this.foldingStartMarker = /(\{|\[)[^\}\]]*$|^\s*(\/\*)/;
876
this.foldingStopMarker = /^[^\[\{]*(\}|\])|^[\s\*]*(\*\/)/;
878
this.getFoldWidgetRange = function(session, foldStyle, row) {
879
var line = session.getLine(row);
880
var match = line.match(this.foldingStartMarker);
885
return this.openingBracketBlock(session, match[1], row, i);
887
return session.getCommentFoldRange(row, i + match[0].length, 1);
890
if (foldStyle !== "markbeginend")
893
var match = line.match(this.foldingStopMarker);
895
var i = match.index + match[0].length;
898
return this.closingBracketBlock(session, match[1], row, i);
900
return session.getCommentFoldRange(row, i, -1);
904
}).call(FoldMode.prototype);
909
define('ace/mode/typescript_highlight_rules', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/javascript_highlight_rules'], function(require, exports, module) {
912
var oop = require("../lib/oop");
913
var JavaScriptHighlightRules = require("./javascript_highlight_rules").JavaScriptHighlightRules;
915
var TypeScriptHighlightRules = function() {
919
token: ["keyword.operator.ts", "text", "variable.parameter.function.ts", "text"],
920
regex: "\\b(module)(\\s*)([a-zA-Z0-9_?.$][\\w?.$]*)(\\s*\\{)"
923
token: ["storage.type.variable.ts", "text", "keyword.other.ts", "text"],
924
regex: "(super)(\\s*\\()([a-zA-Z0-9,_?.$\\s]+\\s*)(\\))"
927
token: ["entity.name.function.ts","paren.lparen", "paren.rparen"],
928
regex: "([a-zA-Z_?.$][\\w?.$]*)(\\()(\\))"
931
token: ["variable.parameter.function.ts", "text", "variable.parameter.function.ts"],
932
regex: "([a-zA-Z0-9_?.$][\\w?.$]*)(\\s*:\\s*)([a-zA-Z0-9_?.$][\\w?.$]*)"
935
token: ["keyword.operator.ts"],
936
regex: "(?:\\b(constructor|declare|interface|as|AS|public|private|class|extends|export|super)\\b)"
939
token: ["storage.type.variable.ts"],
940
regex: "(?:\\b(this\\.|string\\b|bool\\b|number)\\b)"
943
token: ["keyword.operator.ts", "storage.type.variable.ts", "keyword.operator.ts", "storage.type.variable.ts"],
944
regex: "(class)(\\s+[a-zA-Z0-9_?.$][\\w?.$]*\\s+)(extends)(\\s+[a-zA-Z0-9_?.$][\\w?.$]*\\s+)?"
948
regex: "(?:super|export|class|extends|import)\\b"
952
var JSRules = new JavaScriptHighlightRules().getRules();
954
JSRules.start = tsRules.concat(JSRules.start);
955
this.$rules = JSRules;
958
oop.inherits(TypeScriptHighlightRules, JavaScriptHighlightRules);
960
exports.TypeScriptHighlightRules = TypeScriptHighlightRules;
b'\\ No newline at end of file'