mode-javascript.js 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963
  1. /* ***** BEGIN LICENSE BLOCK *****
  2. * Distributed under the BSD license:
  3. *
  4. * Copyright (c) 2010, Ajax.org B.V.
  5. * All rights reserved.
  6. *
  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.
  17. *
  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.
  28. *
  29. * ***** END LICENSE BLOCK ***** */
  30. 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) {
  31. var oop = require("../lib/oop");
  32. var TextMode = require("./text").Mode;
  33. var Tokenizer = require("../tokenizer").Tokenizer;
  34. var JavaScriptHighlightRules = require("./javascript_highlight_rules").JavaScriptHighlightRules;
  35. var MatchingBraceOutdent = require("./matching_brace_outdent").MatchingBraceOutdent;
  36. var Range = require("../range").Range;
  37. var WorkerClient = require("../worker/worker_client").WorkerClient;
  38. var CstyleBehaviour = require("./behaviour/cstyle").CstyleBehaviour;
  39. var CStyleFoldMode = require("./folding/cstyle").FoldMode;
  40. var Mode = function() {
  41. this.HighlightRules = JavaScriptHighlightRules;
  42. this.$outdent = new MatchingBraceOutdent();
  43. this.$behaviour = new CstyleBehaviour();
  44. this.foldingRules = new CStyleFoldMode();
  45. };
  46. oop.inherits(Mode, TextMode);
  47. (function() {
  48. this.lineCommentStart = "//";
  49. this.blockComment = {start: "/*", end: "*/"};
  50. this.getNextLineIndent = function(state, line, tab) {
  51. var indent = this.$getIndent(line);
  52. var tokenizedLine = this.getTokenizer().getLineTokens(line, state);
  53. var tokens = tokenizedLine.tokens;
  54. var endState = tokenizedLine.state;
  55. if (tokens.length && tokens[tokens.length-1].type == "comment") {
  56. return indent;
  57. }
  58. if (state == "start" || state == "no_regex") {
  59. var match = line.match(/^.*(?:\bcase\b.*\:|[\{\(\[])\s*$/);
  60. if (match) {
  61. indent += tab;
  62. }
  63. } else if (state == "doc-start") {
  64. if (endState == "start" || endState == "no_regex") {
  65. return "";
  66. }
  67. var match = line.match(/^\s*(\/?)\*/);
  68. if (match) {
  69. if (match[1]) {
  70. indent += " ";
  71. }
  72. indent += "* ";
  73. }
  74. }
  75. return indent;
  76. };
  77. this.checkOutdent = function(state, line, input) {
  78. return this.$outdent.checkOutdent(line, input);
  79. };
  80. this.autoOutdent = function(state, doc, row) {
  81. this.$outdent.autoOutdent(doc, row);
  82. };
  83. this.createWorker = function(session) {
  84. var worker = new WorkerClient(["ace"], "ace/mode/javascript_worker", "JavaScriptWorker");
  85. worker.attachToDocument(session.getDocument());
  86. worker.on("jslint", function(results) {
  87. session.setAnnotations(results.data);
  88. });
  89. worker.on("terminate", function() {
  90. session.clearAnnotations();
  91. });
  92. return worker;
  93. };
  94. this.$id = "ace/mode/javascript";
  95. }).call(Mode.prototype);
  96. exports.Mode = Mode;
  97. });
  98. 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) {
  99. var oop = require("../lib/oop");
  100. var DocCommentHighlightRules = require("./doc_comment_highlight_rules").DocCommentHighlightRules;
  101. var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
  102. var JavaScriptHighlightRules = function() {
  103. var keywordMapper = this.createKeywordMapper({
  104. "variable.language":
  105. "Array|Boolean|Date|Function|Iterator|Number|Object|RegExp|String|Proxy|" + // Constructors
  106. "Namespace|QName|XML|XMLList|" + // E4X
  107. "ArrayBuffer|Float32Array|Float64Array|Int16Array|Int32Array|Int8Array|" +
  108. "Uint16Array|Uint32Array|Uint8Array|Uint8ClampedArray|" +
  109. "Error|EvalError|InternalError|RangeError|ReferenceError|StopIteration|" + // Errors
  110. "SyntaxError|TypeError|URIError|" +
  111. "decodeURI|decodeURIComponent|encodeURI|encodeURIComponent|eval|isFinite|" + // Non-constructor functions
  112. "isNaN|parseFloat|parseInt|" +
  113. "JSON|Math|" + // Other
  114. "this|arguments|prototype|window|document" , // Pseudo
  115. "keyword":
  116. "const|yield|import|get|set|" +
  117. "break|case|catch|continue|default|delete|do|else|finally|for|function|" +
  118. "if|in|instanceof|new|return|switch|throw|try|typeof|let|var|while|with|debugger|" +
  119. "__parent__|__count__|escape|unescape|with|__proto__|" +
  120. "class|enum|extends|super|export|implements|private|public|interface|package|protected|static",
  121. "storage.type":
  122. "const|let|var|function",
  123. "constant.language":
  124. "null|Infinity|NaN|undefined",
  125. "support.function":
  126. "alert",
  127. "constant.language.boolean": "true|false"
  128. }, "identifier");
  129. var kwBeforeRe = "case|do|else|finally|in|instanceof|return|throw|try|typeof|yield|void";
  130. var identifierRe = "[a-zA-Z\\$_\u00a1-\uffff][a-zA-Z\\d\\$_\u00a1-\uffff]*\\b";
  131. var escapedRe = "\\\\(?:x[0-9a-fA-F]{2}|" + // hex
  132. "u[0-9a-fA-F]{4}|" + // unicode
  133. "[0-2][0-7]{0,2}|" + // oct
  134. "3[0-6][0-7]?|" + // oct
  135. "37[0-7]?|" + // oct
  136. "[4-7][0-7]?|" + //oct
  137. ".)";
  138. this.$rules = {
  139. "no_regex" : [
  140. {
  141. token : "comment",
  142. regex : "\\/\\/",
  143. next : "line_comment"
  144. },
  145. DocCommentHighlightRules.getStartRule("doc-start"),
  146. {
  147. token : "comment", // multi line comment
  148. regex : /\/\*/,
  149. next : "comment"
  150. }, {
  151. token : "string",
  152. regex : "'(?=.)",
  153. next : "qstring"
  154. }, {
  155. token : "string",
  156. regex : '"(?=.)',
  157. next : "qqstring"
  158. }, {
  159. token : "constant.numeric", // hex
  160. regex : /0[xX][0-9a-fA-F]+\b/
  161. }, {
  162. token : "constant.numeric", // float
  163. regex : /[+-]?\d+(?:(?:\.\d*)?(?:[eE][+-]?\d+)?)?\b/
  164. }, {
  165. token : [
  166. "storage.type", "punctuation.operator", "support.function",
  167. "punctuation.operator", "entity.name.function", "text","keyword.operator"
  168. ],
  169. regex : "(" + identifierRe + ")(\\.)(prototype)(\\.)(" + identifierRe +")(\\s*)(=)",
  170. next: "function_arguments"
  171. }, {
  172. token : [
  173. "storage.type", "punctuation.operator", "entity.name.function", "text",
  174. "keyword.operator", "text", "storage.type", "text", "paren.lparen"
  175. ],
  176. regex : "(" + identifierRe + ")(\\.)(" + identifierRe +")(\\s*)(=)(\\s*)(function)(\\s*)(\\()",
  177. next: "function_arguments"
  178. }, {
  179. token : [
  180. "entity.name.function", "text", "keyword.operator", "text", "storage.type",
  181. "text", "paren.lparen"
  182. ],
  183. regex : "(" + identifierRe +")(\\s*)(=)(\\s*)(function)(\\s*)(\\()",
  184. next: "function_arguments"
  185. }, {
  186. token : [
  187. "storage.type", "punctuation.operator", "entity.name.function", "text",
  188. "keyword.operator", "text",
  189. "storage.type", "text", "entity.name.function", "text", "paren.lparen"
  190. ],
  191. regex : "(" + identifierRe + ")(\\.)(" + identifierRe +")(\\s*)(=)(\\s*)(function)(\\s+)(\\w+)(\\s*)(\\()",
  192. next: "function_arguments"
  193. }, {
  194. token : [
  195. "storage.type", "text", "entity.name.function", "text", "paren.lparen"
  196. ],
  197. regex : "(function)(\\s+)(" + identifierRe + ")(\\s*)(\\()",
  198. next: "function_arguments"
  199. }, {
  200. token : [
  201. "entity.name.function", "text", "punctuation.operator",
  202. "text", "storage.type", "text", "paren.lparen"
  203. ],
  204. regex : "(" + identifierRe + ")(\\s*)(:)(\\s*)(function)(\\s*)(\\()",
  205. next: "function_arguments"
  206. }, {
  207. token : [
  208. "text", "text", "storage.type", "text", "paren.lparen"
  209. ],
  210. regex : "(:)(\\s*)(function)(\\s*)(\\()",
  211. next: "function_arguments"
  212. }, {
  213. token : "keyword",
  214. regex : "(?:" + kwBeforeRe + ")\\b",
  215. next : "start"
  216. }, {
  217. token : ["punctuation.operator", "support.function"],
  218. 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(?=\()/
  219. }, {
  220. token : ["punctuation.operator", "support.function.dom"],
  221. 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(?=\()/
  222. }, {
  223. token : ["punctuation.operator", "support.constant"],
  224. 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/
  225. }, {
  226. token : ["storage.type", "punctuation.operator", "support.function.firebug"],
  227. regex : /(console)(\.)(warn|info|log|error|time|timeEnd|assert)\b/
  228. }, {
  229. token : keywordMapper,
  230. regex : identifierRe
  231. }, {
  232. token : "keyword.operator",
  233. regex : /--|\+\+|[!$%&*+\-~]|===|==|=|!=|!==|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\|\||\?\:|\*=|%=|\+=|\-=|&=|\^=/,
  234. next : "start"
  235. }, {
  236. token : "punctuation.operator",
  237. regex : /\?|\:|\,|\;|\./,
  238. next : "start"
  239. }, {
  240. token : "paren.lparen",
  241. regex : /[\[({]/,
  242. next : "start"
  243. }, {
  244. token : "paren.rparen",
  245. regex : /[\])}]/
  246. }, {
  247. token : "keyword.operator",
  248. regex : /\/=?/,
  249. next : "start"
  250. }, {
  251. token: "comment",
  252. regex: /^#!.*$/
  253. }
  254. ],
  255. "start": [
  256. DocCommentHighlightRules.getStartRule("doc-start"),
  257. {
  258. token : "comment", // multi line comment
  259. regex : "\\/\\*",
  260. next : "comment_regex_allowed"
  261. }, {
  262. token : "comment",
  263. regex : "\\/\\/",
  264. next : "line_comment_regex_allowed"
  265. }, {
  266. token: "string.regexp",
  267. regex: "\\/",
  268. next: "regex"
  269. }, {
  270. token : "text",
  271. regex : "\\s+|^$",
  272. next : "start"
  273. }, {
  274. token: "empty",
  275. regex: "",
  276. next: "no_regex"
  277. }
  278. ],
  279. "regex": [
  280. {
  281. token: "regexp.keyword.operator",
  282. regex: "\\\\(?:u[\\da-fA-F]{4}|x[\\da-fA-F]{2}|.)"
  283. }, {
  284. token: "string.regexp",
  285. regex: "/[sxngimy]*",
  286. next: "no_regex"
  287. }, {
  288. token : "invalid",
  289. regex: /\{\d+\b,?\d*\}[+*]|[+*$^?][+*]|[$^][?]|\?{3,}/
  290. }, {
  291. token : "constant.language.escape",
  292. regex: /\(\?[:=!]|\)|\{\d+\b,?\d*\}|[+*]\?|[()$^+*?.]/
  293. }, {
  294. token : "constant.language.delimiter",
  295. regex: /\|/
  296. }, {
  297. token: "constant.language.escape",
  298. regex: /\[\^?/,
  299. next: "regex_character_class"
  300. }, {
  301. token: "empty",
  302. regex: "$",
  303. next: "no_regex"
  304. }, {
  305. defaultToken: "string.regexp"
  306. }
  307. ],
  308. "regex_character_class": [
  309. {
  310. token: "regexp.keyword.operator",
  311. regex: "\\\\(?:u[\\da-fA-F]{4}|x[\\da-fA-F]{2}|.)"
  312. }, {
  313. token: "constant.language.escape",
  314. regex: "]",
  315. next: "regex"
  316. }, {
  317. token: "constant.language.escape",
  318. regex: "-"
  319. }, {
  320. token: "empty",
  321. regex: "$",
  322. next: "no_regex"
  323. }, {
  324. defaultToken: "string.regexp.charachterclass"
  325. }
  326. ],
  327. "function_arguments": [
  328. {
  329. token: "variable.parameter",
  330. regex: identifierRe
  331. }, {
  332. token: "punctuation.operator",
  333. regex: "[, ]+"
  334. }, {
  335. token: "punctuation.operator",
  336. regex: "$"
  337. }, {
  338. token: "empty",
  339. regex: "",
  340. next: "no_regex"
  341. }
  342. ],
  343. "comment_regex_allowed" : [
  344. {token : "comment", regex : "\\*\\/", next : "start"},
  345. {defaultToken : "comment"}
  346. ],
  347. "comment" : [
  348. {token : "comment", regex : "\\*\\/", next : "no_regex"},
  349. {defaultToken : "comment"}
  350. ],
  351. "line_comment_regex_allowed" : [
  352. {token : "comment", regex : "$|^", next : "start"},
  353. {defaultToken : "comment"}
  354. ],
  355. "line_comment" : [
  356. {token : "comment", regex : "$|^", next : "no_regex"},
  357. {defaultToken : "comment"}
  358. ],
  359. "qqstring" : [
  360. {
  361. token : "constant.language.escape",
  362. regex : escapedRe
  363. }, {
  364. token : "string",
  365. regex : "\\\\$",
  366. next : "qqstring"
  367. }, {
  368. token : "string",
  369. regex : '"|$',
  370. next : "no_regex"
  371. }, {
  372. defaultToken: "string"
  373. }
  374. ],
  375. "qstring" : [
  376. {
  377. token : "constant.language.escape",
  378. regex : escapedRe
  379. }, {
  380. token : "string",
  381. regex : "\\\\$",
  382. next : "qstring"
  383. }, {
  384. token : "string",
  385. regex : "'|$",
  386. next : "no_regex"
  387. }, {
  388. defaultToken: "string"
  389. }
  390. ]
  391. };
  392. this.embedRules(DocCommentHighlightRules, "doc-",
  393. [ DocCommentHighlightRules.getEndRule("no_regex") ]);
  394. };
  395. oop.inherits(JavaScriptHighlightRules, TextHighlightRules);
  396. exports.JavaScriptHighlightRules = JavaScriptHighlightRules;
  397. });
  398. define('ace/mode/doc_comment_highlight_rules', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/text_highlight_rules'], function(require, exports, module) {
  399. var oop = require("../lib/oop");
  400. var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
  401. var DocCommentHighlightRules = function() {
  402. this.$rules = {
  403. "start" : [ {
  404. token : "comment.doc.tag",
  405. regex : "@[\\w\\d_]+" // TODO: fix email addresses
  406. }, {
  407. token : "comment.doc.tag",
  408. regex : "\\bTODO\\b"
  409. }, {
  410. defaultToken : "comment.doc"
  411. }]
  412. };
  413. };
  414. oop.inherits(DocCommentHighlightRules, TextHighlightRules);
  415. DocCommentHighlightRules.getStartRule = function(start) {
  416. return {
  417. token : "comment.doc", // doc comment
  418. regex : "\\/\\*(?=\\*)",
  419. next : start
  420. };
  421. };
  422. DocCommentHighlightRules.getEndRule = function (start) {
  423. return {
  424. token : "comment.doc", // closing comment
  425. regex : "\\*\\/",
  426. next : start
  427. };
  428. };
  429. exports.DocCommentHighlightRules = DocCommentHighlightRules;
  430. });
  431. define('ace/mode/matching_brace_outdent', ['require', 'exports', 'module' , 'ace/range'], function(require, exports, module) {
  432. var Range = require("../range").Range;
  433. var MatchingBraceOutdent = function() {};
  434. (function() {
  435. this.checkOutdent = function(line, input) {
  436. if (! /^\s+$/.test(line))
  437. return false;
  438. return /^\s*\}/.test(input);
  439. };
  440. this.autoOutdent = function(doc, row) {
  441. var line = doc.getLine(row);
  442. var match = line.match(/^(\s*\})/);
  443. if (!match) return 0;
  444. var column = match[1].length;
  445. var openBracePos = doc.findMatchingBracket({row: row, column: column});
  446. if (!openBracePos || openBracePos.row == row) return 0;
  447. var indent = this.$getIndent(doc.getLine(openBracePos.row));
  448. doc.replace(new Range(row, 0, row, column-1), indent);
  449. };
  450. this.$getIndent = function(line) {
  451. return line.match(/^\s*/)[0];
  452. };
  453. }).call(MatchingBraceOutdent.prototype);
  454. exports.MatchingBraceOutdent = MatchingBraceOutdent;
  455. });
  456. define('ace/mode/behaviour/cstyle', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/behaviour', 'ace/token_iterator', 'ace/lib/lang'], function(require, exports, module) {
  457. var oop = require("../../lib/oop");
  458. var Behaviour = require("../behaviour").Behaviour;
  459. var TokenIterator = require("../../token_iterator").TokenIterator;
  460. var lang = require("../../lib/lang");
  461. var SAFE_INSERT_IN_TOKENS =
  462. ["text", "paren.rparen", "punctuation.operator"];
  463. var SAFE_INSERT_BEFORE_TOKENS =
  464. ["text", "paren.rparen", "punctuation.operator", "comment"];
  465. var context;
  466. var contextCache = {}
  467. var initContext = function(editor) {
  468. var id = -1;
  469. if (editor.multiSelect) {
  470. id = editor.selection.id;
  471. if (contextCache.rangeCount != editor.multiSelect.rangeCount)
  472. contextCache = {rangeCount: editor.multiSelect.rangeCount};
  473. }
  474. if (contextCache[id])
  475. return context = contextCache[id];
  476. context = contextCache[id] = {
  477. autoInsertedBrackets: 0,
  478. autoInsertedRow: -1,
  479. autoInsertedLineEnd: "",
  480. maybeInsertedBrackets: 0,
  481. maybeInsertedRow: -1,
  482. maybeInsertedLineStart: "",
  483. maybeInsertedLineEnd: ""
  484. };
  485. };
  486. var CstyleBehaviour = function() {
  487. this.add("braces", "insertion", function(state, action, editor, session, text) {
  488. var cursor = editor.getCursorPosition();
  489. var line = session.doc.getLine(cursor.row);
  490. if (text == '{') {
  491. initContext(editor);
  492. var selection = editor.getSelectionRange();
  493. var selected = session.doc.getTextRange(selection);
  494. if (selected !== "" && selected !== "{" && editor.getWrapBehavioursEnabled()) {
  495. return {
  496. text: '{' + selected + '}',
  497. selection: false
  498. };
  499. } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
  500. if (/[\]\}\)]/.test(line[cursor.column]) || editor.inMultiSelectMode) {
  501. CstyleBehaviour.recordAutoInsert(editor, session, "}");
  502. return {
  503. text: '{}',
  504. selection: [1, 1]
  505. };
  506. } else {
  507. CstyleBehaviour.recordMaybeInsert(editor, session, "{");
  508. return {
  509. text: '{',
  510. selection: [1, 1]
  511. };
  512. }
  513. }
  514. } else if (text == '}') {
  515. initContext(editor);
  516. var rightChar = line.substring(cursor.column, cursor.column + 1);
  517. if (rightChar == '}') {
  518. var matching = session.$findOpeningBracket('}', {column: cursor.column + 1, row: cursor.row});
  519. if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) {
  520. CstyleBehaviour.popAutoInsertedClosing();
  521. return {
  522. text: '',
  523. selection: [1, 1]
  524. };
  525. }
  526. }
  527. } else if (text == "\n" || text == "\r\n") {
  528. initContext(editor);
  529. var closing = "";
  530. if (CstyleBehaviour.isMaybeInsertedClosing(cursor, line)) {
  531. closing = lang.stringRepeat("}", context.maybeInsertedBrackets);
  532. CstyleBehaviour.clearMaybeInsertedClosing();
  533. }
  534. var rightChar = line.substring(cursor.column, cursor.column + 1);
  535. if (rightChar === '}') {
  536. var openBracePos = session.findMatchingBracket({row: cursor.row, column: cursor.column+1}, '}');
  537. if (!openBracePos)
  538. return null;
  539. var next_indent = this.$getIndent(session.getLine(openBracePos.row));
  540. } else if (closing) {
  541. var next_indent = this.$getIndent(line);
  542. } else {
  543. CstyleBehaviour.clearMaybeInsertedClosing();
  544. return;
  545. }
  546. var indent = next_indent + session.getTabString();
  547. return {
  548. text: '\n' + indent + '\n' + next_indent + closing,
  549. selection: [1, indent.length, 1, indent.length]
  550. };
  551. } else {
  552. CstyleBehaviour.clearMaybeInsertedClosing();
  553. }
  554. });
  555. this.add("braces", "deletion", function(state, action, editor, session, range) {
  556. var selected = session.doc.getTextRange(range);
  557. if (!range.isMultiLine() && selected == '{') {
  558. initContext(editor);
  559. var line = session.doc.getLine(range.start.row);
  560. var rightChar = line.substring(range.end.column, range.end.column + 1);
  561. if (rightChar == '}') {
  562. range.end.column++;
  563. return range;
  564. } else {
  565. context.maybeInsertedBrackets--;
  566. }
  567. }
  568. });
  569. this.add("parens", "insertion", function(state, action, editor, session, text) {
  570. if (text == '(') {
  571. initContext(editor);
  572. var selection = editor.getSelectionRange();
  573. var selected = session.doc.getTextRange(selection);
  574. if (selected !== "" && editor.getWrapBehavioursEnabled()) {
  575. return {
  576. text: '(' + selected + ')',
  577. selection: false
  578. };
  579. } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
  580. CstyleBehaviour.recordAutoInsert(editor, session, ")");
  581. return {
  582. text: '()',
  583. selection: [1, 1]
  584. };
  585. }
  586. } else if (text == ')') {
  587. initContext(editor);
  588. var cursor = editor.getCursorPosition();
  589. var line = session.doc.getLine(cursor.row);
  590. var rightChar = line.substring(cursor.column, cursor.column + 1);
  591. if (rightChar == ')') {
  592. var matching = session.$findOpeningBracket(')', {column: cursor.column + 1, row: cursor.row});
  593. if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) {
  594. CstyleBehaviour.popAutoInsertedClosing();
  595. return {
  596. text: '',
  597. selection: [1, 1]
  598. };
  599. }
  600. }
  601. }
  602. });
  603. this.add("parens", "deletion", function(state, action, editor, session, range) {
  604. var selected = session.doc.getTextRange(range);
  605. if (!range.isMultiLine() && selected == '(') {
  606. initContext(editor);
  607. var line = session.doc.getLine(range.start.row);
  608. var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
  609. if (rightChar == ')') {
  610. range.end.column++;
  611. return range;
  612. }
  613. }
  614. });
  615. this.add("brackets", "insertion", function(state, action, editor, session, text) {
  616. if (text == '[') {
  617. initContext(editor);
  618. var selection = editor.getSelectionRange();
  619. var selected = session.doc.getTextRange(selection);
  620. if (selected !== "" && editor.getWrapBehavioursEnabled()) {
  621. return {
  622. text: '[' + selected + ']',
  623. selection: false
  624. };
  625. } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
  626. CstyleBehaviour.recordAutoInsert(editor, session, "]");
  627. return {
  628. text: '[]',
  629. selection: [1, 1]
  630. };
  631. }
  632. } else if (text == ']') {
  633. initContext(editor);
  634. var cursor = editor.getCursorPosition();
  635. var line = session.doc.getLine(cursor.row);
  636. var rightChar = line.substring(cursor.column, cursor.column + 1);
  637. if (rightChar == ']') {
  638. var matching = session.$findOpeningBracket(']', {column: cursor.column + 1, row: cursor.row});
  639. if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) {
  640. CstyleBehaviour.popAutoInsertedClosing();
  641. return {
  642. text: '',
  643. selection: [1, 1]
  644. };
  645. }
  646. }
  647. }
  648. });
  649. this.add("brackets", "deletion", function(state, action, editor, session, range) {
  650. var selected = session.doc.getTextRange(range);
  651. if (!range.isMultiLine() && selected == '[') {
  652. initContext(editor);
  653. var line = session.doc.getLine(range.start.row);
  654. var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
  655. if (rightChar == ']') {
  656. range.end.column++;
  657. return range;
  658. }
  659. }
  660. });
  661. this.add("string_dquotes", "insertion", function(state, action, editor, session, text) {
  662. if (text == '"' || text == "'") {
  663. initContext(editor);
  664. var quote = text;
  665. var selection = editor.getSelectionRange();
  666. var selected = session.doc.getTextRange(selection);
  667. if (selected !== "" && selected !== "'" && selected != '"' && editor.getWrapBehavioursEnabled()) {
  668. return {
  669. text: quote + selected + quote,
  670. selection: false
  671. };
  672. } else {
  673. var cursor = editor.getCursorPosition();
  674. var line = session.doc.getLine(cursor.row);
  675. var leftChar = line.substring(cursor.column-1, cursor.column);
  676. if (leftChar == '\\') {
  677. return null;
  678. }
  679. var tokens = session.getTokens(selection.start.row);
  680. var col = 0, token;
  681. var quotepos = -1; // Track whether we're inside an open quote.
  682. for (var x = 0; x < tokens.length; x++) {
  683. token = tokens[x];
  684. if (token.type == "string") {
  685. quotepos = -1;
  686. } else if (quotepos < 0) {
  687. quotepos = token.value.indexOf(quote);
  688. }
  689. if ((token.value.length + col) > selection.start.column) {
  690. break;
  691. }
  692. col += tokens[x].value.length;
  693. }
  694. 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)))) {
  695. if (!CstyleBehaviour.isSaneInsertion(editor, session))
  696. return;
  697. return {
  698. text: quote + quote,
  699. selection: [1,1]
  700. };
  701. } else if (token && token.type === "string") {
  702. var rightChar = line.substring(cursor.column, cursor.column + 1);
  703. if (rightChar == quote) {
  704. return {
  705. text: '',
  706. selection: [1, 1]
  707. };
  708. }
  709. }
  710. }
  711. }
  712. });
  713. this.add("string_dquotes", "deletion", function(state, action, editor, session, range) {
  714. var selected = session.doc.getTextRange(range);
  715. if (!range.isMultiLine() && (selected == '"' || selected == "'")) {
  716. initContext(editor);
  717. var line = session.doc.getLine(range.start.row);
  718. var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
  719. if (rightChar == selected) {
  720. range.end.column++;
  721. return range;
  722. }
  723. }
  724. });
  725. };
  726. CstyleBehaviour.isSaneInsertion = function(editor, session) {
  727. var cursor = editor.getCursorPosition();
  728. var iterator = new TokenIterator(session, cursor.row, cursor.column);
  729. if (!this.$matchTokenType(iterator.getCurrentToken() || "text", SAFE_INSERT_IN_TOKENS)) {
  730. var iterator2 = new TokenIterator(session, cursor.row, cursor.column + 1);
  731. if (!this.$matchTokenType(iterator2.getCurrentToken() || "text", SAFE_INSERT_IN_TOKENS))
  732. return false;
  733. }
  734. iterator.stepForward();
  735. return iterator.getCurrentTokenRow() !== cursor.row ||
  736. this.$matchTokenType(iterator.getCurrentToken() || "text", SAFE_INSERT_BEFORE_TOKENS);
  737. };
  738. CstyleBehaviour.$matchTokenType = function(token, types) {
  739. return types.indexOf(token.type || token) > -1;
  740. };
  741. CstyleBehaviour.recordAutoInsert = function(editor, session, bracket) {
  742. var cursor = editor.getCursorPosition();
  743. var line = session.doc.getLine(cursor.row);
  744. if (!this.isAutoInsertedClosing(cursor, line, context.autoInsertedLineEnd[0]))
  745. context.autoInsertedBrackets = 0;
  746. context.autoInsertedRow = cursor.row;
  747. context.autoInsertedLineEnd = bracket + line.substr(cursor.column);
  748. context.autoInsertedBrackets++;
  749. };
  750. CstyleBehaviour.recordMaybeInsert = function(editor, session, bracket) {
  751. var cursor = editor.getCursorPosition();
  752. var line = session.doc.getLine(cursor.row);
  753. if (!this.isMaybeInsertedClosing(cursor, line))
  754. context.maybeInsertedBrackets = 0;
  755. context.maybeInsertedRow = cursor.row;
  756. context.maybeInsertedLineStart = line.substr(0, cursor.column) + bracket;
  757. context.maybeInsertedLineEnd = line.substr(cursor.column);
  758. context.maybeInsertedBrackets++;
  759. };
  760. CstyleBehaviour.isAutoInsertedClosing = function(cursor, line, bracket) {
  761. return context.autoInsertedBrackets > 0 &&
  762. cursor.row === context.autoInsertedRow &&
  763. bracket === context.autoInsertedLineEnd[0] &&
  764. line.substr(cursor.column) === context.autoInsertedLineEnd;
  765. };
  766. CstyleBehaviour.isMaybeInsertedClosing = function(cursor, line) {
  767. return context.maybeInsertedBrackets > 0 &&
  768. cursor.row === context.maybeInsertedRow &&
  769. line.substr(cursor.column) === context.maybeInsertedLineEnd &&
  770. line.substr(0, cursor.column) == context.maybeInsertedLineStart;
  771. };
  772. CstyleBehaviour.popAutoInsertedClosing = function() {
  773. context.autoInsertedLineEnd = context.autoInsertedLineEnd.substr(1);
  774. context.autoInsertedBrackets--;
  775. };
  776. CstyleBehaviour.clearMaybeInsertedClosing = function() {
  777. if (context) {
  778. context.maybeInsertedBrackets = 0;
  779. context.maybeInsertedRow = -1;
  780. }
  781. };
  782. oop.inherits(CstyleBehaviour, Behaviour);
  783. exports.CstyleBehaviour = CstyleBehaviour;
  784. });
  785. define('ace/mode/folding/cstyle', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/range', 'ace/mode/folding/fold_mode'], function(require, exports, module) {
  786. var oop = require("../../lib/oop");
  787. var Range = require("../../range").Range;
  788. var BaseFoldMode = require("./fold_mode").FoldMode;
  789. var FoldMode = exports.FoldMode = function(commentRegex) {
  790. if (commentRegex) {
  791. this.foldingStartMarker = new RegExp(
  792. this.foldingStartMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.start)
  793. );
  794. this.foldingStopMarker = new RegExp(
  795. this.foldingStopMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.end)
  796. );
  797. }
  798. };
  799. oop.inherits(FoldMode, BaseFoldMode);
  800. (function() {
  801. this.foldingStartMarker = /(\{|\[)[^\}\]]*$|^\s*(\/\*)/;
  802. this.foldingStopMarker = /^[^\[\{]*(\}|\])|^[\s\*]*(\*\/)/;
  803. this.getFoldWidgetRange = function(session, foldStyle, row, forceMultiline) {
  804. var line = session.getLine(row);
  805. var match = line.match(this.foldingStartMarker);
  806. if (match) {
  807. var i = match.index;
  808. if (match[1])
  809. return this.openingBracketBlock(session, match[1], row, i);
  810. var range = session.getCommentFoldRange(row, i + match[0].length, 1);
  811. if (range && !range.isMultiLine()) {
  812. if (forceMultiline) {
  813. range = this.getSectionRange(session, row);
  814. } else if (foldStyle != "all")
  815. range = null;
  816. }
  817. return range;
  818. }
  819. if (foldStyle === "markbegin")
  820. return;
  821. var match = line.match(this.foldingStopMarker);
  822. if (match) {
  823. var i = match.index + match[0].length;
  824. if (match[1])
  825. return this.closingBracketBlock(session, match[1], row, i);
  826. return session.getCommentFoldRange(row, i, -1);
  827. }
  828. };
  829. this.getSectionRange = function(session, row) {
  830. var line = session.getLine(row);
  831. var startIndent = line.search(/\S/);
  832. var startRow = row;
  833. var startColumn = line.length;
  834. row = row + 1;
  835. var endRow = row;
  836. var maxRow = session.getLength();
  837. while (++row < maxRow) {
  838. line = session.getLine(row);
  839. var indent = line.search(/\S/);
  840. if (indent === -1)
  841. continue;
  842. if (startIndent > indent)
  843. break;
  844. var subRange = this.getFoldWidgetRange(session, "all", row);
  845. if (subRange) {
  846. if (subRange.start.row <= startRow) {
  847. break;
  848. } else if (subRange.isMultiLine()) {
  849. row = subRange.end.row;
  850. } else if (startIndent == indent) {
  851. break;
  852. }
  853. }
  854. endRow = row;
  855. }
  856. return new Range(startRow, startColumn, endRow, session.getLine(endRow).length);
  857. };
  858. }).call(FoldMode.prototype);
  859. });