You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

mode-javascript.js 39KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024
  1. /* ***** BEGIN LICENSE BLOCK *****
  2. * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  3. *
  4. * The contents of this file are subject to the Mozilla Public License Version
  5. * 1.1 (the "License"); you may not use this file except in compliance with
  6. * the License. You may obtain a copy of the License at
  7. * http://www.mozilla.org/MPL/
  8. *
  9. * Software distributed under the License is distributed on an "AS IS" basis,
  10. * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  11. * for the specific language governing rights and limitations under the
  12. * License.
  13. *
  14. * The Original Code is Ajax.org Code Editor (ACE).
  15. *
  16. * The Initial Developer of the Original Code is
  17. * Ajax.org B.V.
  18. * Portions created by the Initial Developer are Copyright (C) 2010
  19. * the Initial Developer. All Rights Reserved.
  20. *
  21. * Contributor(s):
  22. * Fabian Jakobs <fabian AT ajax DOT org>
  23. *
  24. * Alternatively, the contents of this file may be used under the terms of
  25. * either the GNU General Public License Version 2 or later (the "GPL"), or
  26. * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  27. * in which case the provisions of the GPL or the LGPL are applicable instead
  28. * of those above. If you wish to allow use of your version of this file only
  29. * under the terms of either the GPL or the LGPL, and not to allow others to
  30. * use your version of this file under the terms of the MPL, indicate your
  31. * decision by deleting the provisions above and replace them with the notice
  32. * and other provisions required by the GPL or the LGPL. If you do not delete
  33. * the provisions above, a recipient may use your version of this file under
  34. * the terms of any one of the MPL, the GPL or the LGPL.
  35. *
  36. * ***** END LICENSE BLOCK ***** */
  37. ace.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) {
  38. var oop = require("../lib/oop");
  39. var TextMode = require("./text").Mode;
  40. var Tokenizer = require("../tokenizer").Tokenizer;
  41. var JavaScriptHighlightRules = require("./javascript_highlight_rules").JavaScriptHighlightRules;
  42. var MatchingBraceOutdent = require("./matching_brace_outdent").MatchingBraceOutdent;
  43. var Range = require("../range").Range;
  44. var WorkerClient = require("../worker/worker_client").WorkerClient;
  45. var CstyleBehaviour = require("./behaviour/cstyle").CstyleBehaviour;
  46. var CStyleFoldMode = require("./folding/cstyle").FoldMode;
  47. var Mode = function() {
  48. this.$tokenizer = new Tokenizer(new JavaScriptHighlightRules().getRules());
  49. this.$outdent = new MatchingBraceOutdent();
  50. this.$behaviour = new CstyleBehaviour();
  51. this.foldingRules = new CStyleFoldMode();
  52. };
  53. oop.inherits(Mode, TextMode);
  54. (function() {
  55. this.toggleCommentLines = function(state, doc, startRow, endRow) {
  56. var outdent = true;
  57. var re = /^(\s*)\/\//;
  58. for (var i=startRow; i<= endRow; i++) {
  59. if (!re.test(doc.getLine(i))) {
  60. outdent = false;
  61. break;
  62. }
  63. }
  64. if (outdent) {
  65. var deleteRange = new Range(0, 0, 0, 0);
  66. for (var i=startRow; i<= endRow; i++)
  67. {
  68. var line = doc.getLine(i);
  69. var m = line.match(re);
  70. deleteRange.start.row = i;
  71. deleteRange.end.row = i;
  72. deleteRange.end.column = m[0].length;
  73. doc.replace(deleteRange, m[1]);
  74. }
  75. }
  76. else {
  77. doc.indentRows(startRow, endRow, "//");
  78. }
  79. };
  80. this.getNextLineIndent = function(state, line, tab) {
  81. var indent = this.$getIndent(line);
  82. var tokenizedLine = this.$tokenizer.getLineTokens(line, state);
  83. var tokens = tokenizedLine.tokens;
  84. var endState = tokenizedLine.state;
  85. if (tokens.length && tokens[tokens.length-1].type == "comment") {
  86. return indent;
  87. }
  88. if (state == "start" || state == "regex_allowed") {
  89. var match = line.match(/^.*(?:\bcase\b.*\:|[\{\(\[])\s*$/);
  90. if (match) {
  91. indent += tab;
  92. }
  93. } else if (state == "doc-start") {
  94. if (endState == "start" || state == "regex_allowed") {
  95. return "";
  96. }
  97. var match = line.match(/^\s*(\/?)\*/);
  98. if (match) {
  99. if (match[1]) {
  100. indent += " ";
  101. }
  102. indent += "* ";
  103. }
  104. }
  105. return indent;
  106. };
  107. this.checkOutdent = function(state, line, input) {
  108. return this.$outdent.checkOutdent(line, input);
  109. };
  110. this.autoOutdent = function(state, doc, row) {
  111. this.$outdent.autoOutdent(doc, row);
  112. };
  113. this.createWorker = function(session) {
  114. var worker = new WorkerClient(["ace"], "worker-javascript.js", "ace/mode/javascript_worker", "JavaScriptWorker");
  115. worker.attachToDocument(session.getDocument());
  116. worker.on("jslint", function(results) {
  117. var errors = [];
  118. for (var i=0; i<results.data.length; i++) {
  119. var error = results.data[i];
  120. if (error)
  121. errors.push({
  122. row: error.line-1,
  123. column: error.character-1,
  124. text: error.reason,
  125. type: "warning",
  126. lint: error
  127. });
  128. }
  129. session.setAnnotations(errors);
  130. });
  131. worker.on("narcissus", function(e) {
  132. session.setAnnotations([e.data]);
  133. });
  134. worker.on("terminate", function() {
  135. session.clearAnnotations();
  136. });
  137. return worker;
  138. };
  139. }).call(Mode.prototype);
  140. exports.Mode = Mode;
  141. });
  142. ace.define('ace/mode/javascript_highlight_rules', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/lib/lang', 'ace/unicode', 'ace/mode/doc_comment_highlight_rules', 'ace/mode/text_highlight_rules'], function(require, exports, module) {
  143. var oop = require("../lib/oop");
  144. var lang = require("../lib/lang");
  145. var unicode = require("../unicode");
  146. var DocCommentHighlightRules = require("./doc_comment_highlight_rules").DocCommentHighlightRules;
  147. var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
  148. var JavaScriptHighlightRules = function() {
  149. // see: https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects
  150. var globals = lang.arrayToMap(
  151. // Constructors
  152. ("Array|Boolean|Date|Function|Iterator|Number|Object|RegExp|String|Proxy|" +
  153. // E4X
  154. "Namespace|QName|XML|XMLList|" +
  155. "ArrayBuffer|Float32Array|Float64Array|Int16Array|Int32Array|Int8Array|" +
  156. "Uint16Array|Uint32Array|Uint8Array|Uint8ClampedArray|" +
  157. // Errors
  158. "Error|EvalError|InternalError|RangeError|ReferenceError|StopIteration|" +
  159. "SyntaxError|TypeError|URIError|" +
  160. // Non-constructor functions
  161. "decodeURI|decodeURIComponent|encodeURI|encodeURIComponent|eval|isFinite|" +
  162. "isNaN|parseFloat|parseInt|" +
  163. // Other
  164. "JSON|Math|" +
  165. // Pseudo
  166. "this|arguments|prototype|window|document"
  167. ).split("|")
  168. );
  169. var keywords = lang.arrayToMap(
  170. ("break|case|catch|continue|default|delete|do|else|finally|for|function|" +
  171. "if|in|instanceof|new|return|switch|throw|try|typeof|let|var|while|with|" +
  172. "const|yield|import|get|set").split("|")
  173. );
  174. // keywords which can be followed by regular expressions
  175. var kwBeforeRe = "case|do|else|finally|in|instanceof|return|throw|try|typeof|yield";
  176. var deprecated = lang.arrayToMap(
  177. ("__parent__|__count__|escape|unescape|with|__proto__").split("|")
  178. );
  179. var definitions = lang.arrayToMap(("const|let|var|function").split("|"));
  180. var buildinConstants = lang.arrayToMap(
  181. ("null|Infinity|NaN|undefined").split("|")
  182. );
  183. var futureReserved = lang.arrayToMap(
  184. ("class|enum|extends|super|export|implements|private|" +
  185. "public|interface|package|protected|static").split("|")
  186. );
  187. // TODO: Unicode escape sequences
  188. var identifierRe = "[" + unicode.packages.L + "\\$_]["
  189. + unicode.packages.L
  190. + unicode.packages.Mn + unicode.packages.Mc
  191. + unicode.packages.Nd
  192. + unicode.packages.Pc + "\\$_]*\\b";
  193. var escapedRe = "\\\\(?:x[0-9a-fA-F]{2}|" + // hex
  194. "u[0-9a-fA-F]{4}|" + // unicode
  195. "[0-2][0-7]{0,2}|" + // oct
  196. "3[0-6][0-7]?|" + // oct
  197. "37[0-7]?|" + // oct
  198. "[4-7][0-7]?|" + //oct
  199. ".)";
  200. // regexp must not have capturing parentheses. Use (?:) instead.
  201. // regexps are ordered -> the first match is used
  202. this.$rules = {
  203. "start" : [
  204. {
  205. token : "comment",
  206. regex : /\/\/.*$/
  207. },
  208. DocCommentHighlightRules.getStartRule("doc-start"),
  209. {
  210. token : "comment", // multi line comment
  211. merge : true,
  212. regex : /\/\*/,
  213. next : "comment"
  214. }, {
  215. token : "string",
  216. regex : "'(?=.)",
  217. next : "qstring"
  218. }, {
  219. token : "string",
  220. regex : '"(?=.)',
  221. next : "qqstring"
  222. }, {
  223. token : "constant.numeric", // hex
  224. regex : /0[xX][0-9a-fA-F]+\b/
  225. }, {
  226. token : "constant.numeric", // float
  227. regex : /[+-]?\d+(?:(?:\.\d*)?(?:[eE][+-]?\d+)?)?\b/
  228. }, { // match stuff like: Sound.prototype.play = function() { }
  229. token : [
  230. "storage.type",
  231. "punctuation.operator",
  232. "support.function",
  233. "punctuation.operator",
  234. "entity.name.function",
  235. "text",
  236. "keyword.operator",
  237. "text",
  238. "storage.type",
  239. "text",
  240. "paren.lparen"
  241. ],
  242. regex : "(" + identifierRe + ")(\\.)(prototype)(\\.)(" + identifierRe +")(\\s*)(=)(\\s*)(function)(\\s*)(\\()",
  243. next: "function_arguments"
  244. }, { // match stuff like: Sound.prototype.play = myfunc
  245. token : [
  246. "storage.type",
  247. "punctuation.operator",
  248. "support.function",
  249. "punctuation.operator",
  250. "entity.name.function",
  251. "text",
  252. "keyword.operator",
  253. "text"
  254. ],
  255. regex : "(" + identifierRe + ")(\\.)(prototype)(\\.)(" + identifierRe +")(\\s*)(=)(\\s*)",
  256. next: "function_arguments"
  257. }, { // match stuff like: Sound.play = function() { }
  258. token : [
  259. "storage.type",
  260. "punctuation.operator",
  261. "entity.name.function",
  262. "text",
  263. "keyword.operator",
  264. "text",
  265. "storage.type",
  266. "text",
  267. "paren.lparen"
  268. ],
  269. regex : "(" + identifierRe + ")(\\.)(" + identifierRe +")(\\s*)(=)(\\s*)(function)(\\s*)(\\()",
  270. next: "function_arguments"
  271. }, { // match stuff like: play = function() { }
  272. token : [
  273. "entity.name.function",
  274. "text",
  275. "keyword.operator",
  276. "text",
  277. "storage.type",
  278. "text",
  279. "paren.lparen"
  280. ],
  281. regex : "(" + identifierRe +")(\\s*)(=)(\\s*)(function)(\\s*)(\\()",
  282. next: "function_arguments"
  283. }, { // match stuff like: Sound.play = function play() { }
  284. token : [
  285. "storage.type",
  286. "punctuation.operator",
  287. "entity.name.function",
  288. "text",
  289. "keyword.operator",
  290. "text",
  291. "storage.type",
  292. "text",
  293. "entity.name.function",
  294. "text",
  295. "paren.lparen"
  296. ],
  297. regex : "(" + identifierRe + ")(\\.)(" + identifierRe +")(\\s*)(=)(\\s*)(function)(\\s+)(\\w+)(\\s*)(\\()",
  298. next: "function_arguments"
  299. }, { // match regular function like: function myFunc(arg) { }
  300. token : [
  301. "storage.type",
  302. "text",
  303. "entity.name.function",
  304. "text",
  305. "paren.lparen"
  306. ],
  307. regex : "(function)(\\s+)(" + identifierRe + ")(\\s*)(\\()",
  308. next: "function_arguments"
  309. }, { // match stuff like: foobar: function() { }
  310. token : [
  311. "entity.name.function",
  312. "text",
  313. "punctuation.operator",
  314. "text",
  315. "storage.type",
  316. "text",
  317. "paren.lparen"
  318. ],
  319. regex : "(" + identifierRe + ")(\\s*)(:)(\\s*)(function)(\\s*)(\\()",
  320. next: "function_arguments"
  321. }, { // Attempt to match : function() { } (this is for issues with 'foo': function() { })
  322. token : [
  323. "text",
  324. "text",
  325. "storage.type",
  326. "text",
  327. "paren.lparen"
  328. ],
  329. regex : "(:)(\\s*)(function)(\\s*)(\\()",
  330. next: "function_arguments"
  331. }, {
  332. token : "constant.language.boolean",
  333. regex : /(?:true|false)\b/
  334. }, {
  335. token : "keyword",
  336. regex : "(?:" + kwBeforeRe + ")\\b",
  337. next : "regex_allowed"
  338. }, {
  339. token : ["punctuation.operator", "support.function"],
  340. 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(?=\()/
  341. }, {
  342. token : ["punctuation.operator", "support.function.dom"],
  343. 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(?=\()/
  344. }, {
  345. token : ["punctuation.operator", "support.constant"],
  346. 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/
  347. }, {
  348. token : ["storage.type", "punctuation.operator", "support.function.firebug"],
  349. regex : /(console)(\.)(warn|info|log|error|time|timeEnd|assert)\b/
  350. }, {
  351. token : function(value) {
  352. if (globals.hasOwnProperty(value))
  353. return "variable.language";
  354. else if (deprecated.hasOwnProperty(value))
  355. return "invalid.deprecated";
  356. else if (definitions.hasOwnProperty(value))
  357. return "storage.type";
  358. else if (keywords.hasOwnProperty(value))
  359. return "keyword";
  360. else if (buildinConstants.hasOwnProperty(value))
  361. return "constant.language";
  362. else if (futureReserved.hasOwnProperty(value))
  363. return "invalid.illegal";
  364. else if (value == "debugger")
  365. return "invalid.deprecated";
  366. else
  367. return "identifier";
  368. },
  369. regex : identifierRe
  370. }, {
  371. token : "keyword.operator",
  372. regex : /!|\$|%|&|\*|\-\-|\-|\+\+|\+|~|===|==|=|!=|!==|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\|\||\?\:|\*=|%=|\+=|\-=|&=|\^=|\b(?:in|instanceof|new|delete|typeof|void)/,
  373. next : "regex_allowed"
  374. }, {
  375. token : "punctuation.operator",
  376. regex : /\?|\:|\,|\;|\./,
  377. next : "regex_allowed"
  378. }, {
  379. token : "paren.lparen",
  380. regex : /[\[({]/,
  381. next : "regex_allowed"
  382. }, {
  383. token : "paren.rparen",
  384. regex : /[\])}]/
  385. }, {
  386. token : "keyword.operator",
  387. regex : /\/=?/,
  388. next : "regex_allowed"
  389. }, {
  390. token: "comment",
  391. regex: /^#!.*$/
  392. }, {
  393. token : "text",
  394. regex : /\s+/
  395. }
  396. ],
  397. // regular expressions are only allowed after certain tokens. This
  398. // makes sure we don't mix up regexps with the divison operator
  399. "regex_allowed": [
  400. DocCommentHighlightRules.getStartRule("doc-start"),
  401. {
  402. token : "comment", // multi line comment
  403. merge : true,
  404. regex : "\\/\\*",
  405. next : "comment_regex_allowed"
  406. }, {
  407. token : "comment",
  408. regex : "\\/\\/.*$"
  409. }, {
  410. token: "string.regexp",
  411. regex: "\\/",
  412. next: "regex",
  413. merge: true
  414. }, {
  415. token : "text",
  416. regex : "\\s+"
  417. }, {
  418. // immediately return to the start mode without matching
  419. // anything
  420. token: "empty",
  421. regex: "",
  422. next: "start"
  423. }
  424. ],
  425. "regex": [
  426. {
  427. token: "regexp.keyword.operator",
  428. regex: "\\\\(?:u[\\da-fA-F]{4}|x[\\da-fA-F]{2}|.)"
  429. }, {
  430. // flag
  431. token: "string.regexp",
  432. regex: "/\\w*",
  433. next: "start",
  434. merge: true
  435. }, {
  436. token: "string.regexp",
  437. regex: "[^\\\\/\\[]+",
  438. merge: true
  439. }, {
  440. token: "string.regexp.charachterclass",
  441. regex: "\\[",
  442. next: "regex_character_class",
  443. merge: true
  444. }, {
  445. token: "empty",
  446. regex: "",
  447. next: "start"
  448. }
  449. ],
  450. "regex_character_class": [
  451. {
  452. token: "regexp.keyword.operator",
  453. regex: "\\\\(?:u[\\da-fA-F]{4}|x[\\da-fA-F]{2}|.)"
  454. }, {
  455. token: "string.regexp.charachterclass",
  456. regex: "]",
  457. next: "regex",
  458. merge: true
  459. }, {
  460. token: "string.regexp.charachterclass",
  461. regex: "[^\\\\\\]]+",
  462. merge: true
  463. }, {
  464. token: "empty",
  465. regex: "",
  466. next: "start"
  467. }
  468. ],
  469. "function_arguments": [
  470. {
  471. token: "variable.parameter",
  472. regex: identifierRe,
  473. }, {
  474. token: "punctuation.operator",
  475. regex: "[, ]+",
  476. merge: true
  477. }, {
  478. token: "punctuation.operator",
  479. regex: "$",
  480. merge: true
  481. }, {
  482. token: "empty",
  483. regex: "",
  484. next: "start"
  485. }
  486. ],
  487. "comment_regex_allowed" : [
  488. {
  489. token : "comment", // closing comment
  490. regex : ".*?\\*\\/",
  491. merge : true,
  492. next : "regex_allowed"
  493. }, {
  494. token : "comment", // comment spanning whole line
  495. merge : true,
  496. regex : ".+"
  497. }
  498. ],
  499. "comment" : [
  500. {
  501. token : "comment", // closing comment
  502. regex : ".*?\\*\\/",
  503. merge : true,
  504. next : "start"
  505. }, {
  506. token : "comment", // comment spanning whole line
  507. merge : true,
  508. regex : ".+"
  509. }
  510. ],
  511. "qqstring" : [
  512. {
  513. token : "constant.language.escape",
  514. regex : escapedRe
  515. }, {
  516. token : "string",
  517. regex : '[^"\\\\]+',
  518. merge : true
  519. }, {
  520. token : "string",
  521. regex : "\\\\$",
  522. next : "qqstring",
  523. merge : true
  524. }, {
  525. token : "string",
  526. regex : '"|$',
  527. next : "start",
  528. merge : true
  529. }
  530. ],
  531. "qstring" : [
  532. {
  533. token : "constant.language.escape",
  534. regex : escapedRe
  535. }, {
  536. token : "string",
  537. regex : "[^'\\\\]+",
  538. merge : true
  539. }, {
  540. token : "string",
  541. regex : "\\\\$",
  542. next : "qstring",
  543. merge : true
  544. }, {
  545. token : "string",
  546. regex : "'|$",
  547. next : "start",
  548. merge : true
  549. }
  550. ]
  551. };
  552. this.embedRules(DocCommentHighlightRules, "doc-",
  553. [ DocCommentHighlightRules.getEndRule("start") ]);
  554. };
  555. oop.inherits(JavaScriptHighlightRules, TextHighlightRules);
  556. exports.JavaScriptHighlightRules = JavaScriptHighlightRules;
  557. });
  558. ace.define('ace/mode/doc_comment_highlight_rules', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/text_highlight_rules'], function(require, exports, module) {
  559. var oop = require("../lib/oop");
  560. var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
  561. var DocCommentHighlightRules = function() {
  562. this.$rules = {
  563. "start" : [ {
  564. token : "comment.doc.tag",
  565. regex : "@[\\w\\d_]+" // TODO: fix email addresses
  566. }, {
  567. token : "comment.doc",
  568. merge : true,
  569. regex : "\\s+"
  570. }, {
  571. token : "comment.doc",
  572. merge : true,
  573. regex : "TODO"
  574. }, {
  575. token : "comment.doc",
  576. merge : true,
  577. regex : "[^@\\*]+"
  578. }, {
  579. token : "comment.doc",
  580. merge : true,
  581. regex : "."
  582. }]
  583. };
  584. };
  585. oop.inherits(DocCommentHighlightRules, TextHighlightRules);
  586. DocCommentHighlightRules.getStartRule = function(start) {
  587. return {
  588. token : "comment.doc", // doc comment
  589. merge : true,
  590. regex : "\\/\\*(?=\\*)",
  591. next : start
  592. };
  593. };
  594. DocCommentHighlightRules.getEndRule = function (start) {
  595. return {
  596. token : "comment.doc", // closing comment
  597. merge : true,
  598. regex : "\\*\\/",
  599. next : start
  600. };
  601. };
  602. exports.DocCommentHighlightRules = DocCommentHighlightRules;
  603. });
  604. ace.define('ace/mode/matching_brace_outdent', ['require', 'exports', 'module' , 'ace/range'], function(require, exports, module) {
  605. var Range = require("../range").Range;
  606. var MatchingBraceOutdent = function() {};
  607. (function() {
  608. this.checkOutdent = function(line, input) {
  609. if (! /^\s+$/.test(line))
  610. return false;
  611. return /^\s*\}/.test(input);
  612. };
  613. this.autoOutdent = function(doc, row) {
  614. var line = doc.getLine(row);
  615. var match = line.match(/^(\s*\})/);
  616. if (!match) return 0;
  617. var column = match[1].length;
  618. var openBracePos = doc.findMatchingBracket({row: row, column: column});
  619. if (!openBracePos || openBracePos.row == row) return 0;
  620. var indent = this.$getIndent(doc.getLine(openBracePos.row));
  621. doc.replace(new Range(row, 0, row, column-1), indent);
  622. };
  623. this.$getIndent = function(line) {
  624. var match = line.match(/^(\s+)/);
  625. if (match) {
  626. return match[1];
  627. }
  628. return "";
  629. };
  630. }).call(MatchingBraceOutdent.prototype);
  631. exports.MatchingBraceOutdent = MatchingBraceOutdent;
  632. });
  633. ace.define('ace/mode/behaviour/cstyle', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/behaviour'], function(require, exports, module) {
  634. var oop = require("../../lib/oop");
  635. var Behaviour = require("../behaviour").Behaviour;
  636. var CstyleBehaviour = function () {
  637. this.add("braces", "insertion", function (state, action, editor, session, text) {
  638. if (text == '{') {
  639. var selection = editor.getSelectionRange();
  640. var selected = session.doc.getTextRange(selection);
  641. if (selected !== "") {
  642. return {
  643. text: '{' + selected + '}',
  644. selection: false
  645. };
  646. } else {
  647. return {
  648. text: '{}',
  649. selection: [1, 1]
  650. };
  651. }
  652. } else if (text == '}') {
  653. var cursor = editor.getCursorPosition();
  654. var line = session.doc.getLine(cursor.row);
  655. var rightChar = line.substring(cursor.column, cursor.column + 1);
  656. if (rightChar == '}') {
  657. var matching = session.$findOpeningBracket('}', {column: cursor.column + 1, row: cursor.row});
  658. if (matching !== null) {
  659. return {
  660. text: '',
  661. selection: [1, 1]
  662. };
  663. }
  664. }
  665. } else if (text == "\n") {
  666. var cursor = editor.getCursorPosition();
  667. var line = session.doc.getLine(cursor.row);
  668. var rightChar = line.substring(cursor.column, cursor.column + 1);
  669. if (rightChar == '}') {
  670. var openBracePos = session.findMatchingBracket({row: cursor.row, column: cursor.column + 1});
  671. if (!openBracePos)
  672. return null;
  673. var indent = this.getNextLineIndent(state, line.substring(0, line.length - 1), session.getTabString());
  674. var next_indent = this.$getIndent(session.doc.getLine(openBracePos.row));
  675. return {
  676. text: '\n' + indent + '\n' + next_indent,
  677. selection: [1, indent.length, 1, indent.length]
  678. };
  679. }
  680. }
  681. });
  682. this.add("braces", "deletion", function (state, action, editor, session, range) {
  683. var selected = session.doc.getTextRange(range);
  684. if (!range.isMultiLine() && selected == '{') {
  685. var line = session.doc.getLine(range.start.row);
  686. var rightChar = line.substring(range.end.column, range.end.column + 1);
  687. if (rightChar == '}') {
  688. range.end.column++;
  689. return range;
  690. }
  691. }
  692. });
  693. this.add("parens", "insertion", function (state, action, editor, session, text) {
  694. if (text == '(') {
  695. var selection = editor.getSelectionRange();
  696. var selected = session.doc.getTextRange(selection);
  697. if (selected !== "") {
  698. return {
  699. text: '(' + selected + ')',
  700. selection: false
  701. };
  702. } else {
  703. return {
  704. text: '()',
  705. selection: [1, 1]
  706. };
  707. }
  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) {
  715. return {
  716. text: '',
  717. selection: [1, 1]
  718. };
  719. }
  720. }
  721. }
  722. });
  723. this.add("parens", "deletion", function (state, action, editor, session, range) {
  724. var selected = session.doc.getTextRange(range);
  725. if (!range.isMultiLine() && selected == '(') {
  726. var line = session.doc.getLine(range.start.row);
  727. var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
  728. if (rightChar == ')') {
  729. range.end.column++;
  730. return range;
  731. }
  732. }
  733. });
  734. this.add("string_dquotes", "insertion", function (state, action, editor, session, text) {
  735. if (text == '"' || text == "'") {
  736. var quote = text;
  737. var selection = editor.getSelectionRange();
  738. var selected = session.doc.getTextRange(selection);
  739. if (selected !== "") {
  740. return {
  741. text: quote + selected + quote,
  742. selection: false
  743. };
  744. } else {
  745. var cursor = editor.getCursorPosition();
  746. var line = session.doc.getLine(cursor.row);
  747. var leftChar = line.substring(cursor.column-1, cursor.column);
  748. // We're escaped.
  749. if (leftChar == '\\') {
  750. return null;
  751. }
  752. // Find what token we're inside.
  753. var tokens = session.getTokens(selection.start.row);
  754. var col = 0, token;
  755. var quotepos = -1; // Track whether we're inside an open quote.
  756. for (var x = 0; x < tokens.length; x++) {
  757. token = tokens[x];
  758. if (token.type == "string") {
  759. quotepos = -1;
  760. } else if (quotepos < 0) {
  761. quotepos = token.value.indexOf(quote);
  762. }
  763. if ((token.value.length + col) > selection.start.column) {
  764. break;
  765. }
  766. col += tokens[x].value.length;
  767. }
  768. // Try and be smart about when we auto insert.
  769. 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)))) {
  770. return {
  771. text: quote + quote,
  772. selection: [1,1]
  773. };
  774. } else if (token && token.type === "string") {
  775. // Ignore input and move right one if we're typing over the closing quote.
  776. var rightChar = line.substring(cursor.column, cursor.column + 1);
  777. if (rightChar == quote) {
  778. return {
  779. text: '',
  780. selection: [1, 1]
  781. };
  782. }
  783. }
  784. }
  785. }
  786. });
  787. this.add("string_dquotes", "deletion", function (state, action, editor, session, range) {
  788. var selected = session.doc.getTextRange(range);
  789. if (!range.isMultiLine() && (selected == '"' || selected == "'")) {
  790. var line = session.doc.getLine(range.start.row);
  791. var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
  792. if (rightChar == '"') {
  793. range.end.column++;
  794. return range;
  795. }
  796. }
  797. });
  798. };
  799. oop.inherits(CstyleBehaviour, Behaviour);
  800. exports.CstyleBehaviour = CstyleBehaviour;
  801. });
  802. ace.define('ace/mode/folding/cstyle', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/range', 'ace/mode/folding/fold_mode'], function(require, exports, module) {
  803. var oop = require("../../lib/oop");
  804. var Range = require("../../range").Range;
  805. var BaseFoldMode = require("./fold_mode").FoldMode;
  806. var FoldMode = exports.FoldMode = function() {};
  807. oop.inherits(FoldMode, BaseFoldMode);
  808. (function() {
  809. this.foldingStartMarker = /(\{|\[)[^\}\]]*$|^\s*(\/\*)/;
  810. this.foldingStopMarker = /^[^\[\{]*(\}|\])|^[\s\*]*(\*\/)/;
  811. this.getFoldWidgetRange = function(session, foldStyle, row) {
  812. var line = session.getLine(row);
  813. var match = line.match(this.foldingStartMarker);
  814. if (match) {
  815. var i = match.index;
  816. if (match[1])
  817. return this.openingBracketBlock(session, match[1], row, i);
  818. var range = session.getCommentFoldRange(row, i + match[0].length);
  819. range.end.column -= 2;
  820. return range;
  821. }
  822. if (foldStyle !== "markbeginend")
  823. return;
  824. var match = line.match(this.foldingStopMarker);
  825. if (match) {
  826. var i = match.index + match[0].length;
  827. if (match[2]) {
  828. var range = session.getCommentFoldRange(row, i);
  829. range.end.column -= 2;
  830. return range;
  831. }
  832. var end = {row: row, column: i};
  833. var start = session.$findOpeningBracket(match[1], end);
  834. if (!start)
  835. return;
  836. start.column++;
  837. end.column--;
  838. return Range.fromPoints(start, end);
  839. }
  840. };
  841. }).call(FoldMode.prototype);
  842. });
  843. ace.define('ace/mode/folding/fold_mode', ['require', 'exports', 'module' , 'ace/range'], function(require, exports, module) {
  844. var Range = require("../../range").Range;
  845. var FoldMode = exports.FoldMode = function() {};
  846. (function() {
  847. this.foldingStartMarker = null;
  848. this.foldingStopMarker = null;
  849. // must return "" if there's no fold, to enable caching
  850. this.getFoldWidget = function(session, foldStyle, row) {
  851. var line = session.getLine(row);
  852. if (this.foldingStartMarker.test(line))
  853. return "start";
  854. if (foldStyle == "markbeginend"
  855. && this.foldingStopMarker
  856. && this.foldingStopMarker.test(line))
  857. return "end";
  858. return "";
  859. };
  860. this.getFoldWidgetRange = function(session, foldStyle, row) {
  861. return null;
  862. };
  863. this.indentationBlock = function(session, row, column) {
  864. var re = /^\s*/;
  865. var startRow = row;
  866. var endRow = row;
  867. var line = session.getLine(row);
  868. var startColumn = column || line.length;
  869. var startLevel = line.match(re)[0].length;
  870. var maxRow = session.getLength()
  871. while (++row < maxRow) {
  872. line = session.getLine(row);
  873. var level = line.match(re)[0].length;
  874. if (level == line.length)
  875. continue;
  876. if (level <= startLevel)
  877. break;
  878. endRow = row;
  879. }
  880. if (endRow > startRow) {
  881. var endColumn = session.getLine(endRow).length;
  882. return new Range(startRow, startColumn, endRow, endColumn);
  883. }
  884. };
  885. this.openingBracketBlock = function(session, bracket, row, column, typeRe, allowBlankLine) {
  886. var start = {row: row, column: column + 1};
  887. var end = session.$findClosingBracket(bracket, start, typeRe, allowBlankLine);
  888. if (!end)
  889. return;
  890. var fw = session.foldWidgets[end.row];
  891. if (fw == null)
  892. fw = this.getFoldWidget(session, end.row);
  893. if (fw == "start") {
  894. end.row --;
  895. end.column = session.getLine(end.row).length;
  896. }
  897. return Range.fromPoints(start, end);
  898. };
  899. }).call(FoldMode.prototype);
  900. });