blob: 282b0a38230874c711b5f5a3e88caaa243738db5 [file] [log] [blame]
Chinthakayala,Sheshashailavas(sc2914)8f6a6c42018-06-27 16:11:44 +00001define("ace/mode/doc_comment_highlight_rules",["require","exports","module","ace/lib/oop","ace/mode/text_highlight_rules"], function(require, exports, module) {
2"use strict";
3
4var oop = require("../lib/oop");
5var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
6
7var DocCommentHighlightRules = function() {
8 this.$rules = {
9 "start" : [ {
10 token : "comment.doc.tag",
11 regex : "@[\\w\\d_]+" // TODO: fix email addresses
12 },
13 DocCommentHighlightRules.getTagRule(),
14 {
15 defaultToken : "comment.doc",
16 caseInsensitive: true
17 }]
18 };
19};
20
21oop.inherits(DocCommentHighlightRules, TextHighlightRules);
22
23DocCommentHighlightRules.getTagRule = function(start) {
24 return {
25 token : "comment.doc.tag.storage.type",
26 regex : "\\b(?:TODO|FIXME|XXX|HACK)\\b"
27 };
28};
29
30DocCommentHighlightRules.getStartRule = function(start) {
31 return {
32 token : "comment.doc", // doc comment
33 regex : "\\/\\*(?=\\*)",
34 next : start
35 };
36};
37
38DocCommentHighlightRules.getEndRule = function (start) {
39 return {
40 token : "comment.doc", // closing comment
41 regex : "\\*\\/",
42 next : start
43 };
44};
45
46
47exports.DocCommentHighlightRules = DocCommentHighlightRules;
48
49});
50
51define("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) {
52"use strict";
53
54var oop = require("../lib/oop");
55var DocCommentHighlightRules = require("./doc_comment_highlight_rules").DocCommentHighlightRules;
56var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
57var identifierRe = "[a-zA-Z\\$_\u00a1-\uffff][a-zA-Z\\d\\$_\u00a1-\uffff]*";
58
59var JavaScriptHighlightRules = function(options) {
60 var keywordMapper = this.createKeywordMapper({
61 "variable.language":
62 "Array|Boolean|Date|Function|Iterator|Number|Object|RegExp|String|Proxy|" + // Constructors
63 "Namespace|QName|XML|XMLList|" + // E4X
64 "ArrayBuffer|Float32Array|Float64Array|Int16Array|Int32Array|Int8Array|" +
65 "Uint16Array|Uint32Array|Uint8Array|Uint8ClampedArray|" +
66 "Error|EvalError|InternalError|RangeError|ReferenceError|StopIteration|" + // Errors
67 "SyntaxError|TypeError|URIError|" +
68 "decodeURI|decodeURIComponent|encodeURI|encodeURIComponent|eval|isFinite|" + // Non-constructor functions
69 "isNaN|parseFloat|parseInt|" +
70 "JSON|Math|" + // Other
71 "this|arguments|prototype|window|document" , // Pseudo
72 "keyword":
73 "const|yield|import|get|set|async|await|" +
74 "break|case|catch|continue|default|delete|do|else|finally|for|function|" +
75 "if|in|of|instanceof|new|return|switch|throw|try|typeof|let|var|while|with|debugger|" +
76 "__parent__|__count__|escape|unescape|with|__proto__|" +
77 "class|enum|extends|super|export|implements|private|public|interface|package|protected|static",
78 "storage.type":
79 "const|let|var|function",
80 "constant.language":
81 "null|Infinity|NaN|undefined",
82 "support.function":
83 "alert",
84 "constant.language.boolean": "true|false"
85 }, "identifier");
86 var kwBeforeRe = "case|do|else|finally|in|instanceof|return|throw|try|typeof|yield|void";
87
88 var escapedRe = "\\\\(?:x[0-9a-fA-F]{2}|" + // hex
89 "u[0-9a-fA-F]{4}|" + // unicode
90 "u{[0-9a-fA-F]{1,6}}|" + // es6 unicode
91 "[0-2][0-7]{0,2}|" + // oct
92 "3[0-7][0-7]?|" + // oct
93 "[4-7][0-7]?|" + //oct
94 ".)";
95
96 this.$rules = {
97 "no_regex" : [
98 DocCommentHighlightRules.getStartRule("doc-start"),
99 comments("no_regex"),
100 {
101 token : "string",
102 regex : "'(?=.)",
103 next : "qstring"
104 }, {
105 token : "string",
106 regex : '"(?=.)',
107 next : "qqstring"
108 }, {
109 token : "constant.numeric", // hexadecimal, octal and binary
110 regex : /0(?:[xX][0-9a-fA-F]+|[oO][0-7]+|[bB][01]+)\b/
111 }, {
112 token : "constant.numeric", // decimal integers and floats
113 regex : /(?:\d\d*(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+\b)?/
114 }, {
115 token : [
116 "storage.type", "punctuation.operator", "support.function",
117 "punctuation.operator", "entity.name.function", "text","keyword.operator"
118 ],
119 regex : "(" + identifierRe + ")(\\.)(prototype)(\\.)(" + identifierRe +")(\\s*)(=)",
120 next: "function_arguments"
121 }, {
122 token : [
123 "storage.type", "punctuation.operator", "entity.name.function", "text",
124 "keyword.operator", "text", "storage.type", "text", "paren.lparen"
125 ],
126 regex : "(" + identifierRe + ")(\\.)(" + identifierRe +")(\\s*)(=)(\\s*)(function)(\\s*)(\\()",
127 next: "function_arguments"
128 }, {
129 token : [
130 "entity.name.function", "text", "keyword.operator", "text", "storage.type",
131 "text", "paren.lparen"
132 ],
133 regex : "(" + identifierRe +")(\\s*)(=)(\\s*)(function)(\\s*)(\\()",
134 next: "function_arguments"
135 }, {
136 token : [
137 "storage.type", "punctuation.operator", "entity.name.function", "text",
138 "keyword.operator", "text",
139 "storage.type", "text", "entity.name.function", "text", "paren.lparen"
140 ],
141 regex : "(" + identifierRe + ")(\\.)(" + identifierRe +")(\\s*)(=)(\\s*)(function)(\\s+)(\\w+)(\\s*)(\\()",
142 next: "function_arguments"
143 }, {
144 token : [
145 "storage.type", "text", "entity.name.function", "text", "paren.lparen"
146 ],
147 regex : "(function)(\\s+)(" + identifierRe + ")(\\s*)(\\()",
148 next: "function_arguments"
149 }, {
150 token : [
151 "entity.name.function", "text", "punctuation.operator",
152 "text", "storage.type", "text", "paren.lparen"
153 ],
154 regex : "(" + identifierRe + ")(\\s*)(:)(\\s*)(function)(\\s*)(\\()",
155 next: "function_arguments"
156 }, {
157 token : [
158 "text", "text", "storage.type", "text", "paren.lparen"
159 ],
160 regex : "(:)(\\s*)(function)(\\s*)(\\()",
161 next: "function_arguments"
162 }, {
163 token : "keyword",
164 regex : "from(?=\\s*('|\"))"
165 }, {
166 token : "keyword",
167 regex : "(?:" + kwBeforeRe + ")\\b",
168 next : "start"
169 }, {
170 token : ["support.constant"],
171 regex : /that\b/
172 }, {
173 token : ["storage.type", "punctuation.operator", "support.function.firebug"],
174 regex : /(console)(\.)(warn|info|log|error|time|trace|timeEnd|assert)\b/
175 }, {
176 token : keywordMapper,
177 regex : identifierRe
178 }, {
179 token : "punctuation.operator",
180 regex : /[.](?![.])/,
181 next : "property"
182 }, {
183 token : "storage.type",
184 regex : /=>/
185 }, {
186 token : "keyword.operator",
187 regex : /--|\+\+|\.{3}|===|==|=|!=|!==|<+=?|>+=?|!|&&|\|\||\?:|[!$%&*+\-~\/^]=?/,
188 next : "start"
189 }, {
190 token : "punctuation.operator",
191 regex : /[?:,;.]/,
192 next : "start"
193 }, {
194 token : "paren.lparen",
195 regex : /[\[({]/,
196 next : "start"
197 }, {
198 token : "paren.rparen",
199 regex : /[\])}]/
200 }, {
201 token: "comment",
202 regex: /^#!.*$/
203 }
204 ],
205 property: [{
206 token : "text",
207 regex : "\\s+"
208 }, {
209 token : [
210 "storage.type", "punctuation.operator", "entity.name.function", "text",
211 "keyword.operator", "text",
212 "storage.type", "text", "entity.name.function", "text", "paren.lparen"
213 ],
214 regex : "(" + identifierRe + ")(\\.)(" + identifierRe +")(\\s*)(=)(\\s*)(function)(?:(\\s+)(\\w+))?(\\s*)(\\()",
215 next: "function_arguments"
216 }, {
217 token : "punctuation.operator",
218 regex : /[.](?![.])/
219 }, {
220 token : "support.function",
221 regex : /(s(?:h(?:ift|ow(?:Mod(?:elessDialog|alDialog)|Help))|croll(?:X|By(?:Pages|Lines)?|Y|To)?|t(?:op|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(?=\()/
222 }, {
223 token : "support.function.dom",
224 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|ClassName)|ById)|Attribute(?:Node)?)|blur)\b(?=\()/
225 }, {
226 token : "support.constant",
227 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/
228 }, {
229 token : "identifier",
230 regex : identifierRe
231 }, {
232 regex: "",
233 token: "empty",
234 next: "no_regex"
235 }
236 ],
237 "start": [
238 DocCommentHighlightRules.getStartRule("doc-start"),
239 comments("start"),
240 {
241 token: "string.regexp",
242 regex: "\\/",
243 next: "regex"
244 }, {
245 token : "text",
246 regex : "\\s+|^$",
247 next : "start"
248 }, {
249 token: "empty",
250 regex: "",
251 next: "no_regex"
252 }
253 ],
254 "regex": [
255 {
256 token: "regexp.keyword.operator",
257 regex: "\\\\(?:u[\\da-fA-F]{4}|x[\\da-fA-F]{2}|.)"
258 }, {
259 token: "string.regexp",
260 regex: "/[sxngimy]*",
261 next: "no_regex"
262 }, {
263 token : "invalid",
264 regex: /\{\d+\b,?\d*\}[+*]|[+*$^?][+*]|[$^][?]|\?{3,}/
265 }, {
266 token : "constant.language.escape",
267 regex: /\(\?[:=!]|\)|\{\d+\b,?\d*\}|[+*]\?|[()$^+*?.]/
268 }, {
269 token : "constant.language.delimiter",
270 regex: /\|/
271 }, {
272 token: "constant.language.escape",
273 regex: /\[\^?/,
274 next: "regex_character_class"
275 }, {
276 token: "empty",
277 regex: "$",
278 next: "no_regex"
279 }, {
280 defaultToken: "string.regexp"
281 }
282 ],
283 "regex_character_class": [
284 {
285 token: "regexp.charclass.keyword.operator",
286 regex: "\\\\(?:u[\\da-fA-F]{4}|x[\\da-fA-F]{2}|.)"
287 }, {
288 token: "constant.language.escape",
289 regex: "]",
290 next: "regex"
291 }, {
292 token: "constant.language.escape",
293 regex: "-"
294 }, {
295 token: "empty",
296 regex: "$",
297 next: "no_regex"
298 }, {
299 defaultToken: "string.regexp.charachterclass"
300 }
301 ],
302 "function_arguments": [
303 {
304 token: "variable.parameter",
305 regex: identifierRe
306 }, {
307 token: "punctuation.operator",
308 regex: "[, ]+"
309 }, {
310 token: "punctuation.operator",
311 regex: "$"
312 }, {
313 token: "empty",
314 regex: "",
315 next: "no_regex"
316 }
317 ],
318 "qqstring" : [
319 {
320 token : "constant.language.escape",
321 regex : escapedRe
322 }, {
323 token : "string",
324 regex : "\\\\$",
325 consumeLineEnd : true
326 }, {
327 token : "string",
328 regex : '"|$',
329 next : "no_regex"
330 }, {
331 defaultToken: "string"
332 }
333 ],
334 "qstring" : [
335 {
336 token : "constant.language.escape",
337 regex : escapedRe
338 }, {
339 token : "string",
340 regex : "\\\\$",
341 consumeLineEnd : true
342 }, {
343 token : "string",
344 regex : "'|$",
345 next : "no_regex"
346 }, {
347 defaultToken: "string"
348 }
349 ]
350 };
351
352
353 if (!options || !options.noES6) {
354 this.$rules.no_regex.unshift({
355 regex: "[{}]", onMatch: function(val, state, stack) {
356 this.next = val == "{" ? this.nextState : "";
357 if (val == "{" && stack.length) {
358 stack.unshift("start", state);
359 }
360 else if (val == "}" && stack.length) {
361 stack.shift();
362 this.next = stack.shift();
363 if (this.next.indexOf("string") != -1 || this.next.indexOf("jsx") != -1)
364 return "paren.quasi.end";
365 }
366 return val == "{" ? "paren.lparen" : "paren.rparen";
367 },
368 nextState: "start"
369 }, {
370 token : "string.quasi.start",
371 regex : /`/,
372 push : [{
373 token : "constant.language.escape",
374 regex : escapedRe
375 }, {
376 token : "paren.quasi.start",
377 regex : /\${/,
378 push : "start"
379 }, {
380 token : "string.quasi.end",
381 regex : /`/,
382 next : "pop"
383 }, {
384 defaultToken: "string.quasi"
385 }]
386 });
387
388 if (!options || options.jsx != false)
389 JSX.call(this);
390 }
391
392 this.embedRules(DocCommentHighlightRules, "doc-",
393 [ DocCommentHighlightRules.getEndRule("no_regex") ]);
394
395 this.normalizeRules();
396};
397
398oop.inherits(JavaScriptHighlightRules, TextHighlightRules);
399
400function JSX() {
401 var tagRegex = identifierRe.replace("\\d", "\\d\\-");
402 var jsxTag = {
403 onMatch : function(val, state, stack) {
404 var offset = val.charAt(1) == "/" ? 2 : 1;
405 if (offset == 1) {
406 if (state != this.nextState)
407 stack.unshift(this.next, this.nextState, 0);
408 else
409 stack.unshift(this.next);
410 stack[2]++;
411 } else if (offset == 2) {
412 if (state == this.nextState) {
413 stack[1]--;
414 if (!stack[1] || stack[1] < 0) {
415 stack.shift();
416 stack.shift();
417 }
418 }
419 }
420 return [{
421 type: "meta.tag.punctuation." + (offset == 1 ? "" : "end-") + "tag-open.xml",
422 value: val.slice(0, offset)
423 }, {
424 type: "meta.tag.tag-name.xml",
425 value: val.substr(offset)
426 }];
427 },
428 regex : "</?" + tagRegex + "",
429 next: "jsxAttributes",
430 nextState: "jsx"
431 };
432 this.$rules.start.unshift(jsxTag);
433 var jsxJsRule = {
434 regex: "{",
435 token: "paren.quasi.start",
436 push: "start"
437 };
438 this.$rules.jsx = [
439 jsxJsRule,
440 jsxTag,
441 {include : "reference"},
442 {defaultToken: "string"}
443 ];
444 this.$rules.jsxAttributes = [{
445 token : "meta.tag.punctuation.tag-close.xml",
446 regex : "/?>",
447 onMatch : function(value, currentState, stack) {
448 if (currentState == stack[0])
449 stack.shift();
450 if (value.length == 2) {
451 if (stack[0] == this.nextState)
452 stack[1]--;
453 if (!stack[1] || stack[1] < 0) {
454 stack.splice(0, 2);
455 }
456 }
457 this.next = stack[0] || "start";
458 return [{type: this.token, value: value}];
459 },
460 nextState: "jsx"
461 },
462 jsxJsRule,
463 comments("jsxAttributes"),
464 {
465 token : "entity.other.attribute-name.xml",
466 regex : tagRegex
467 }, {
468 token : "keyword.operator.attribute-equals.xml",
469 regex : "="
470 }, {
471 token : "text.tag-whitespace.xml",
472 regex : "\\s+"
473 }, {
474 token : "string.attribute-value.xml",
475 regex : "'",
476 stateName : "jsx_attr_q",
477 push : [
478 {token : "string.attribute-value.xml", regex: "'", next: "pop"},
479 {include : "reference"},
480 {defaultToken : "string.attribute-value.xml"}
481 ]
482 }, {
483 token : "string.attribute-value.xml",
484 regex : '"',
485 stateName : "jsx_attr_qq",
486 push : [
487 {token : "string.attribute-value.xml", regex: '"', next: "pop"},
488 {include : "reference"},
489 {defaultToken : "string.attribute-value.xml"}
490 ]
491 },
492 jsxTag
493 ];
494 this.$rules.reference = [{
495 token : "constant.language.escape.reference.xml",
496 regex : "(?:&#[0-9]+;)|(?:&#x[0-9a-fA-F]+;)|(?:&[a-zA-Z0-9_:\\.-]+;)"
497 }];
498}
499
500function comments(next) {
501 return [
502 {
503 token : "comment", // multi line comment
504 regex : /\/\*/,
505 next: [
506 DocCommentHighlightRules.getTagRule(),
507 {token : "comment", regex : "\\*\\/", next : next || "pop"},
508 {defaultToken : "comment", caseInsensitive: true}
509 ]
510 }, {
511 token : "comment",
512 regex : "\\/\\/",
513 next: [
514 DocCommentHighlightRules.getTagRule(),
515 {token : "comment", regex : "$|^", next : next || "pop"},
516 {defaultToken : "comment", caseInsensitive: true}
517 ]
518 }
519 ];
520}
521exports.JavaScriptHighlightRules = JavaScriptHighlightRules;
522});
523
524define("ace/mode/matching_brace_outdent",["require","exports","module","ace/range"], function(require, exports, module) {
525"use strict";
526
527var Range = require("../range").Range;
528
529var MatchingBraceOutdent = function() {};
530
531(function() {
532
533 this.checkOutdent = function(line, input) {
534 if (! /^\s+$/.test(line))
535 return false;
536
537 return /^\s*\}/.test(input);
538 };
539
540 this.autoOutdent = function(doc, row) {
541 var line = doc.getLine(row);
542 var match = line.match(/^(\s*\})/);
543
544 if (!match) return 0;
545
546 var column = match[1].length;
547 var openBracePos = doc.findMatchingBracket({row: row, column: column});
548
549 if (!openBracePos || openBracePos.row == row) return 0;
550
551 var indent = this.$getIndent(doc.getLine(openBracePos.row));
552 doc.replace(new Range(row, 0, row, column-1), indent);
553 };
554
555 this.$getIndent = function(line) {
556 return line.match(/^\s*/)[0];
557 };
558
559}).call(MatchingBraceOutdent.prototype);
560
561exports.MatchingBraceOutdent = MatchingBraceOutdent;
562});
563
564define("ace/mode/folding/cstyle",["require","exports","module","ace/lib/oop","ace/range","ace/mode/folding/fold_mode"], function(require, exports, module) {
565"use strict";
566
567var oop = require("../../lib/oop");
568var Range = require("../../range").Range;
569var BaseFoldMode = require("./fold_mode").FoldMode;
570
571var FoldMode = exports.FoldMode = function(commentRegex) {
572 if (commentRegex) {
573 this.foldingStartMarker = new RegExp(
574 this.foldingStartMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.start)
575 );
576 this.foldingStopMarker = new RegExp(
577 this.foldingStopMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.end)
578 );
579 }
580};
581oop.inherits(FoldMode, BaseFoldMode);
582
583(function() {
584
585 this.foldingStartMarker = /([\{\[\(])[^\}\]\)]*$|^\s*(\/\*)/;
586 this.foldingStopMarker = /^[^\[\{\(]*([\}\]\)])|^[\s\*]*(\*\/)/;
587 this.singleLineBlockCommentRe= /^\s*(\/\*).*\*\/\s*$/;
588 this.tripleStarBlockCommentRe = /^\s*(\/\*\*\*).*\*\/\s*$/;
589 this.startRegionRe = /^\s*(\/\*|\/\/)#?region\b/;
590 this._getFoldWidgetBase = this.getFoldWidget;
591 this.getFoldWidget = function(session, foldStyle, row) {
592 var line = session.getLine(row);
593
594 if (this.singleLineBlockCommentRe.test(line)) {
595 if (!this.startRegionRe.test(line) && !this.tripleStarBlockCommentRe.test(line))
596 return "";
597 }
598
599 var fw = this._getFoldWidgetBase(session, foldStyle, row);
600
601 if (!fw && this.startRegionRe.test(line))
602 return "start"; // lineCommentRegionStart
603
604 return fw;
605 };
606
607 this.getFoldWidgetRange = function(session, foldStyle, row, forceMultiline) {
608 var line = session.getLine(row);
609
610 if (this.startRegionRe.test(line))
611 return this.getCommentRegionBlock(session, line, row);
612
613 var match = line.match(this.foldingStartMarker);
614 if (match) {
615 var i = match.index;
616
617 if (match[1])
618 return this.openingBracketBlock(session, match[1], row, i);
619
620 var range = session.getCommentFoldRange(row, i + match[0].length, 1);
621
622 if (range && !range.isMultiLine()) {
623 if (forceMultiline) {
624 range = this.getSectionRange(session, row);
625 } else if (foldStyle != "all")
626 range = null;
627 }
628
629 return range;
630 }
631
632 if (foldStyle === "markbegin")
633 return;
634
635 var match = line.match(this.foldingStopMarker);
636 if (match) {
637 var i = match.index + match[0].length;
638
639 if (match[1])
640 return this.closingBracketBlock(session, match[1], row, i);
641
642 return session.getCommentFoldRange(row, i, -1);
643 }
644 };
645
646 this.getSectionRange = function(session, row) {
647 var line = session.getLine(row);
648 var startIndent = line.search(/\S/);
649 var startRow = row;
650 var startColumn = line.length;
651 row = row + 1;
652 var endRow = row;
653 var maxRow = session.getLength();
654 while (++row < maxRow) {
655 line = session.getLine(row);
656 var indent = line.search(/\S/);
657 if (indent === -1)
658 continue;
659 if (startIndent > indent)
660 break;
661 var subRange = this.getFoldWidgetRange(session, "all", row);
662
663 if (subRange) {
664 if (subRange.start.row <= startRow) {
665 break;
666 } else if (subRange.isMultiLine()) {
667 row = subRange.end.row;
668 } else if (startIndent == indent) {
669 break;
670 }
671 }
672 endRow = row;
673 }
674
675 return new Range(startRow, startColumn, endRow, session.getLine(endRow).length);
676 };
677 this.getCommentRegionBlock = function(session, line, row) {
678 var startColumn = line.search(/\s*$/);
679 var maxRow = session.getLength();
680 var startRow = row;
681
682 var re = /^\s*(?:\/\*|\/\/|--)#?(end)?region\b/;
683 var depth = 1;
684 while (++row < maxRow) {
685 line = session.getLine(row);
686 var m = re.exec(line);
687 if (!m) continue;
688 if (m[1]) depth--;
689 else depth++;
690
691 if (!depth) break;
692 }
693
694 var endRow = row;
695 if (endRow > startRow) {
696 return new Range(startRow, startColumn, endRow, line.length);
697 }
698 };
699
700}).call(FoldMode.prototype);
701
702});
703
704define("ace/mode/javascript",["require","exports","module","ace/lib/oop","ace/mode/text","ace/mode/javascript_highlight_rules","ace/mode/matching_brace_outdent","ace/worker/worker_client","ace/mode/behaviour/cstyle","ace/mode/folding/cstyle"], function(require, exports, module) {
705"use strict";
706
707var oop = require("../lib/oop");
708var TextMode = require("./text").Mode;
709var JavaScriptHighlightRules = require("./javascript_highlight_rules").JavaScriptHighlightRules;
710var MatchingBraceOutdent = require("./matching_brace_outdent").MatchingBraceOutdent;
711var WorkerClient = require("../worker/worker_client").WorkerClient;
712var CstyleBehaviour = require("./behaviour/cstyle").CstyleBehaviour;
713var CStyleFoldMode = require("./folding/cstyle").FoldMode;
714
715var Mode = function() {
716 this.HighlightRules = JavaScriptHighlightRules;
717
718 this.$outdent = new MatchingBraceOutdent();
719 this.$behaviour = new CstyleBehaviour();
720 this.foldingRules = new CStyleFoldMode();
721};
722oop.inherits(Mode, TextMode);
723
724(function() {
725
726 this.lineCommentStart = "//";
727 this.blockComment = {start: "/*", end: "*/"};
728 this.$quotes = {'"': '"', "'": "'", "`": "`"};
729
730 this.getNextLineIndent = function(state, line, tab) {
731 var indent = this.$getIndent(line);
732
733 var tokenizedLine = this.getTokenizer().getLineTokens(line, state);
734 var tokens = tokenizedLine.tokens;
735 var endState = tokenizedLine.state;
736
737 if (tokens.length && tokens[tokens.length-1].type == "comment") {
738 return indent;
739 }
740
741 if (state == "start" || state == "no_regex") {
742 var match = line.match(/^.*(?:\bcase\b.*:|[\{\(\[])\s*$/);
743 if (match) {
744 indent += tab;
745 }
746 } else if (state == "doc-start") {
747 if (endState == "start" || endState == "no_regex") {
748 return "";
749 }
750 var match = line.match(/^\s*(\/?)\*/);
751 if (match) {
752 if (match[1]) {
753 indent += " ";
754 }
755 indent += "* ";
756 }
757 }
758
759 return indent;
760 };
761
762 this.checkOutdent = function(state, line, input) {
763 return this.$outdent.checkOutdent(line, input);
764 };
765
766 this.autoOutdent = function(state, doc, row) {
767 this.$outdent.autoOutdent(doc, row);
768 };
769
770 this.createWorker = function(session) {
771 var worker = new WorkerClient(["ace"], "ace/mode/javascript_worker", "JavaScriptWorker");
772 worker.attachToDocument(session.getDocument());
773
774 worker.on("annotate", function(results) {
775 session.setAnnotations(results.data);
776 });
777
778 worker.on("terminate", function() {
779 session.clearAnnotations();
780 });
781
782 return worker;
783 };
784
785 this.$id = "ace/mode/javascript";
786}).call(Mode.prototype);
787
788exports.Mode = Mode;
789});