mode-javascript.js 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140
  1. ace.define("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. var oop = require("../lib/oop");
  4. var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
  5. var DocCommentHighlightRules = function() {
  6. this.$rules = {
  7. "start" : [ {
  8. token : "comment.doc.tag",
  9. regex : "@[\\w\\d_]+" // TODO: fix email addresses
  10. },
  11. DocCommentHighlightRules.getTagRule(),
  12. {
  13. defaultToken : "comment.doc",
  14. caseInsensitive: true
  15. }]
  16. };
  17. };
  18. oop.inherits(DocCommentHighlightRules, TextHighlightRules);
  19. DocCommentHighlightRules.getTagRule = function(start) {
  20. return {
  21. token : "comment.doc.tag.storage.type",
  22. regex : "\\b(?:TODO|FIXME|XXX|HACK)\\b"
  23. };
  24. }
  25. DocCommentHighlightRules.getStartRule = function(start) {
  26. return {
  27. token : "comment.doc", // doc comment
  28. regex : "\\/\\*(?=\\*)",
  29. next : start
  30. };
  31. };
  32. DocCommentHighlightRules.getEndRule = function (start) {
  33. return {
  34. token : "comment.doc", // closing comment
  35. regex : "\\*\\/",
  36. next : start
  37. };
  38. };
  39. exports.DocCommentHighlightRules = DocCommentHighlightRules;
  40. });
  41. ace.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) {
  42. "use strict";
  43. var oop = require("../lib/oop");
  44. var DocCommentHighlightRules = require("./doc_comment_highlight_rules").DocCommentHighlightRules;
  45. var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
  46. var identifierRe = "[a-zA-Z\\$_\u00a1-\uffff][a-zA-Z\\d\\$_\u00a1-\uffff]*\\b";
  47. var JavaScriptHighlightRules = function(options) {
  48. var keywordMapper = this.createKeywordMapper({
  49. "variable.language":
  50. "Array|Boolean|Date|Function|Iterator|Number|Object|RegExp|String|Proxy|" + // Constructors
  51. "Namespace|QName|XML|XMLList|" + // E4X
  52. "ArrayBuffer|Float32Array|Float64Array|Int16Array|Int32Array|Int8Array|" +
  53. "Uint16Array|Uint32Array|Uint8Array|Uint8ClampedArray|" +
  54. "Error|EvalError|InternalError|RangeError|ReferenceError|StopIteration|" + // Errors
  55. "SyntaxError|TypeError|URIError|" +
  56. "decodeURI|decodeURIComponent|encodeURI|encodeURIComponent|eval|isFinite|" + // Non-constructor functions
  57. "isNaN|parseFloat|parseInt|" +
  58. "JSON|Math|" + // Other
  59. "this|arguments|prototype|window|document" , // Pseudo
  60. "keyword":
  61. "const|yield|import|get|set|" +
  62. "break|case|catch|continue|default|delete|do|else|finally|for|function|" +
  63. "if|in|instanceof|new|return|switch|throw|try|typeof|let|var|while|with|debugger|" +
  64. "__parent__|__count__|escape|unescape|with|__proto__|" +
  65. "class|enum|extends|super|export|implements|private|public|interface|package|protected|static",
  66. "storage.type":
  67. "const|let|var|function",
  68. "constant.language":
  69. "null|Infinity|NaN|undefined",
  70. "support.function":
  71. "alert",
  72. "constant.language.boolean": "true|false"
  73. }, "identifier");
  74. var kwBeforeRe = "case|do|else|finally|in|instanceof|return|throw|try|typeof|yield|void";
  75. var escapedRe = "\\\\(?:x[0-9a-fA-F]{2}|" + // hex
  76. "u[0-9a-fA-F]{4}|" + // unicode
  77. "u{[0-9a-fA-F]{1,6}}|" + // es6 unicode
  78. "[0-2][0-7]{0,2}|" + // oct
  79. "3[0-7][0-7]?|" + // oct
  80. "[4-7][0-7]?|" + //oct
  81. ".)";
  82. this.$rules = {
  83. "no_regex" : [
  84. DocCommentHighlightRules.getStartRule("doc-start"),
  85. comments("no_regex"),
  86. {
  87. token : "string",
  88. regex : "'(?=.)",
  89. next : "qstring"
  90. }, {
  91. token : "string",
  92. regex : '"(?=.)',
  93. next : "qqstring"
  94. }, {
  95. token : "constant.numeric", // hex
  96. regex : /0(?:[xX][0-9a-fA-F]+|[bB][01]+)\b/
  97. }, {
  98. token : "constant.numeric", // float
  99. regex : /[+-]?\d[\d_]*(?:(?:\.\d*)?(?:[eE][+-]?\d+)?)?\b/
  100. }, {
  101. token : [
  102. "storage.type", "punctuation.operator", "support.function",
  103. "punctuation.operator", "entity.name.function", "text","keyword.operator"
  104. ],
  105. regex : "(" + identifierRe + ")(\\.)(prototype)(\\.)(" + identifierRe +")(\\s*)(=)",
  106. next: "function_arguments"
  107. }, {
  108. token : [
  109. "storage.type", "punctuation.operator", "entity.name.function", "text",
  110. "keyword.operator", "text", "storage.type", "text", "paren.lparen"
  111. ],
  112. regex : "(" + identifierRe + ")(\\.)(" + identifierRe +")(\\s*)(=)(\\s*)(function)(\\s*)(\\()",
  113. next: "function_arguments"
  114. }, {
  115. token : [
  116. "entity.name.function", "text", "keyword.operator", "text", "storage.type",
  117. "text", "paren.lparen"
  118. ],
  119. regex : "(" + identifierRe +")(\\s*)(=)(\\s*)(function)(\\s*)(\\()",
  120. next: "function_arguments"
  121. }, {
  122. token : [
  123. "storage.type", "punctuation.operator", "entity.name.function", "text",
  124. "keyword.operator", "text",
  125. "storage.type", "text", "entity.name.function", "text", "paren.lparen"
  126. ],
  127. regex : "(" + identifierRe + ")(\\.)(" + identifierRe +")(\\s*)(=)(\\s*)(function)(\\s+)(\\w+)(\\s*)(\\()",
  128. next: "function_arguments"
  129. }, {
  130. token : [
  131. "storage.type", "text", "entity.name.function", "text", "paren.lparen"
  132. ],
  133. regex : "(function)(\\s+)(" + identifierRe + ")(\\s*)(\\()",
  134. next: "function_arguments"
  135. }, {
  136. token : [
  137. "entity.name.function", "text", "punctuation.operator",
  138. "text", "storage.type", "text", "paren.lparen"
  139. ],
  140. regex : "(" + identifierRe + ")(\\s*)(:)(\\s*)(function)(\\s*)(\\()",
  141. next: "function_arguments"
  142. }, {
  143. token : [
  144. "text", "text", "storage.type", "text", "paren.lparen"
  145. ],
  146. regex : "(:)(\\s*)(function)(\\s*)(\\()",
  147. next: "function_arguments"
  148. }, {
  149. token : "keyword",
  150. regex : "(?:" + kwBeforeRe + ")\\b",
  151. next : "start"
  152. }, {
  153. token : ["support.constant"],
  154. regex : /that\b/
  155. }, {
  156. token : ["storage.type", "punctuation.operator", "support.function.firebug"],
  157. regex : /(console)(\.)(warn|info|log|error|time|trace|timeEnd|assert)\b/
  158. }, {
  159. token : keywordMapper,
  160. regex : identifierRe
  161. }, {
  162. token : "punctuation.operator",
  163. regex : /[.](?![.])/,
  164. next : "property"
  165. }, {
  166. token : "keyword.operator",
  167. regex : /--|\+\+|\.{3}|===|==|=|!=|!==|<+=?|>+=?|!|&&|\|\||\?\:|[!$%&*+\-~\/^]=?/,
  168. next : "start"
  169. }, {
  170. token : "punctuation.operator",
  171. regex : /[?:,;.]/,
  172. next : "start"
  173. }, {
  174. token : "paren.lparen",
  175. regex : /[\[({]/,
  176. next : "start"
  177. }, {
  178. token : "paren.rparen",
  179. regex : /[\])}]/
  180. }, {
  181. token: "comment",
  182. regex: /^#!.*$/
  183. }
  184. ],
  185. property: [{
  186. token : "text",
  187. regex : "\\s+"
  188. }, {
  189. token : [
  190. "storage.type", "punctuation.operator", "entity.name.function", "text",
  191. "keyword.operator", "text",
  192. "storage.type", "text", "entity.name.function", "text", "paren.lparen"
  193. ],
  194. regex : "(" + identifierRe + ")(\\.)(" + identifierRe +")(\\s*)(=)(\\s*)(function)(?:(\\s+)(\\w+))?(\\s*)(\\()",
  195. next: "function_arguments"
  196. }, {
  197. token : "punctuation.operator",
  198. regex : /[.](?![.])/
  199. }, {
  200. token : "support.function",
  201. 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(?=\()/
  202. }, {
  203. token : "support.function.dom",
  204. 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(?=\()/
  205. }, {
  206. token : "support.constant",
  207. 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/
  208. }, {
  209. token : "identifier",
  210. regex : identifierRe
  211. }, {
  212. regex: "",
  213. token: "empty",
  214. next: "no_regex"
  215. }
  216. ],
  217. "start": [
  218. DocCommentHighlightRules.getStartRule("doc-start"),
  219. comments("start"),
  220. {
  221. token: "string.regexp",
  222. regex: "\\/",
  223. next: "regex"
  224. }, {
  225. token : "text",
  226. regex : "\\s+|^$",
  227. next : "start"
  228. }, {
  229. token: "empty",
  230. regex: "",
  231. next: "no_regex"
  232. }
  233. ],
  234. "regex": [
  235. {
  236. token: "regexp.keyword.operator",
  237. regex: "\\\\(?:u[\\da-fA-F]{4}|x[\\da-fA-F]{2}|.)"
  238. }, {
  239. token: "string.regexp",
  240. regex: "/[sxngimy]*",
  241. next: "no_regex"
  242. }, {
  243. token : "invalid",
  244. regex: /\{\d+\b,?\d*\}[+*]|[+*$^?][+*]|[$^][?]|\?{3,}/
  245. }, {
  246. token : "constant.language.escape",
  247. regex: /\(\?[:=!]|\)|\{\d+\b,?\d*\}|[+*]\?|[()$^+*?.]/
  248. }, {
  249. token : "constant.language.delimiter",
  250. regex: /\|/
  251. }, {
  252. token: "constant.language.escape",
  253. regex: /\[\^?/,
  254. next: "regex_character_class"
  255. }, {
  256. token: "empty",
  257. regex: "$",
  258. next: "no_regex"
  259. }, {
  260. defaultToken: "string.regexp"
  261. }
  262. ],
  263. "regex_character_class": [
  264. {
  265. token: "regexp.charclass.keyword.operator",
  266. regex: "\\\\(?:u[\\da-fA-F]{4}|x[\\da-fA-F]{2}|.)"
  267. }, {
  268. token: "constant.language.escape",
  269. regex: "]",
  270. next: "regex"
  271. }, {
  272. token: "constant.language.escape",
  273. regex: "-"
  274. }, {
  275. token: "empty",
  276. regex: "$",
  277. next: "no_regex"
  278. }, {
  279. defaultToken: "string.regexp.charachterclass"
  280. }
  281. ],
  282. "function_arguments": [
  283. {
  284. token: "variable.parameter",
  285. regex: identifierRe
  286. }, {
  287. token: "punctuation.operator",
  288. regex: "[, ]+"
  289. }, {
  290. token: "punctuation.operator",
  291. regex: "$"
  292. }, {
  293. token: "empty",
  294. regex: "",
  295. next: "no_regex"
  296. }
  297. ],
  298. "qqstring" : [
  299. {
  300. token : "constant.language.escape",
  301. regex : escapedRe
  302. }, {
  303. token : "string",
  304. regex : "\\\\$",
  305. next : "qqstring"
  306. }, {
  307. token : "string",
  308. regex : '"|$',
  309. next : "no_regex"
  310. }, {
  311. defaultToken: "string"
  312. }
  313. ],
  314. "qstring" : [
  315. {
  316. token : "constant.language.escape",
  317. regex : escapedRe
  318. }, {
  319. token : "string",
  320. regex : "\\\\$",
  321. next : "qstring"
  322. }, {
  323. token : "string",
  324. regex : "'|$",
  325. next : "no_regex"
  326. }, {
  327. defaultToken: "string"
  328. }
  329. ]
  330. };
  331. if (!options || !options.noES6) {
  332. this.$rules.no_regex.unshift({
  333. regex: "[{}]", onMatch: function(val, state, stack) {
  334. this.next = val == "{" ? this.nextState : "";
  335. if (val == "{" && stack.length) {
  336. stack.unshift("start", state);
  337. }
  338. else if (val == "}" && stack.length) {
  339. stack.shift();
  340. this.next = stack.shift();
  341. if (this.next.indexOf("string") != -1 || this.next.indexOf("jsx") != -1)
  342. return "paren.quasi.end";
  343. }
  344. return val == "{" ? "paren.lparen" : "paren.rparen";
  345. },
  346. nextState: "start"
  347. }, {
  348. token : "string.quasi.start",
  349. regex : /`/,
  350. push : [{
  351. token : "constant.language.escape",
  352. regex : escapedRe
  353. }, {
  354. token : "paren.quasi.start",
  355. regex : /\${/,
  356. push : "start"
  357. }, {
  358. token : "string.quasi.end",
  359. regex : /`/,
  360. next : "pop"
  361. }, {
  362. defaultToken: "string.quasi"
  363. }]
  364. });
  365. if (!options || !options.noJSX)
  366. JSX.call(this);
  367. }
  368. this.embedRules(DocCommentHighlightRules, "doc-",
  369. [ DocCommentHighlightRules.getEndRule("no_regex") ]);
  370. this.normalizeRules();
  371. };
  372. oop.inherits(JavaScriptHighlightRules, TextHighlightRules);
  373. function JSX() {
  374. var tagRegex = identifierRe.replace("\\d", "\\d\\-");
  375. var jsxTag = {
  376. onMatch : function(val, state, stack) {
  377. var offset = val.charAt(1) == "/" ? 2 : 1;
  378. if (offset == 1) {
  379. if (state != this.nextState)
  380. stack.unshift(this.next, this.nextState, 0);
  381. else
  382. stack.unshift(this.next);
  383. stack[2]++;
  384. } else if (offset == 2) {
  385. if (state == this.nextState) {
  386. stack[1]--;
  387. if (!stack[1] || stack[1] < 0) {
  388. stack.shift();
  389. stack.shift();
  390. }
  391. }
  392. }
  393. return [{
  394. type: "meta.tag.punctuation." + (offset == 1 ? "" : "end-") + "tag-open.xml",
  395. value: val.slice(0, offset)
  396. }, {
  397. type: "meta.tag.tag-name.xml",
  398. value: val.substr(offset)
  399. }];
  400. },
  401. regex : "</?" + tagRegex + "",
  402. next: "jsxAttributes",
  403. nextState: "jsx"
  404. };
  405. this.$rules.start.unshift(jsxTag);
  406. var jsxJsRule = {
  407. regex: "{",
  408. token: "paren.quasi.start",
  409. push: "start"
  410. };
  411. this.$rules.jsx = [
  412. jsxJsRule,
  413. jsxTag,
  414. {include : "reference"},
  415. {defaultToken: "string"}
  416. ];
  417. this.$rules.jsxAttributes = [{
  418. token : "meta.tag.punctuation.tag-close.xml",
  419. regex : "/?>",
  420. onMatch : function(value, currentState, stack) {
  421. if (currentState == stack[0])
  422. stack.shift();
  423. if (value.length == 2) {
  424. if (stack[0] == this.nextState)
  425. stack[1]--;
  426. if (!stack[1] || stack[1] < 0) {
  427. stack.splice(0, 2);
  428. }
  429. }
  430. this.next = stack[0] || "start";
  431. return [{type: this.token, value: value}];
  432. },
  433. nextState: "jsx"
  434. },
  435. jsxJsRule,
  436. comments("jsxAttributes"),
  437. {
  438. token : "entity.other.attribute-name.xml",
  439. regex : tagRegex
  440. }, {
  441. token : "keyword.operator.attribute-equals.xml",
  442. regex : "="
  443. }, {
  444. token : "text.tag-whitespace.xml",
  445. regex : "\\s+"
  446. }, {
  447. token : "string.attribute-value.xml",
  448. regex : "'",
  449. stateName : "jsx_attr_q",
  450. push : [
  451. {token : "string.attribute-value.xml", regex: "'", next: "pop"},
  452. {include : "reference"},
  453. {defaultToken : "string.attribute-value.xml"}
  454. ]
  455. }, {
  456. token : "string.attribute-value.xml",
  457. regex : '"',
  458. stateName : "jsx_attr_qq",
  459. push : [
  460. {token : "string.attribute-value.xml", regex: '"', next: "pop"},
  461. {include : "reference"},
  462. {defaultToken : "string.attribute-value.xml"}
  463. ]
  464. },
  465. jsxTag
  466. ];
  467. this.$rules.reference = [{
  468. token : "constant.language.escape.reference.xml",
  469. regex : "(?:&#[0-9]+;)|(?:&#x[0-9a-fA-F]+;)|(?:&[a-zA-Z0-9_:\\.-]+;)"
  470. }];
  471. }
  472. function comments(next) {
  473. return [
  474. {
  475. token : "comment", // multi line comment
  476. regex : /\/\*/,
  477. next: [
  478. DocCommentHighlightRules.getTagRule(),
  479. {token : "comment", regex : "\\*\\/", next : next || "pop"},
  480. {defaultToken : "comment", caseInsensitive: true}
  481. ]
  482. }, {
  483. token : "comment",
  484. regex : "\\/\\/",
  485. next: [
  486. DocCommentHighlightRules.getTagRule(),
  487. {token : "comment", regex : "$|^", next : next || "pop"},
  488. {defaultToken : "comment", caseInsensitive: true}
  489. ]
  490. }
  491. ];
  492. }
  493. exports.JavaScriptHighlightRules = JavaScriptHighlightRules;
  494. });
  495. ace.define("ace/mode/matching_brace_outdent",["require","exports","module","ace/range"], function(require, exports, module) {
  496. "use strict";
  497. var Range = require("../range").Range;
  498. var MatchingBraceOutdent = function() {};
  499. (function() {
  500. this.checkOutdent = function(line, input) {
  501. if (! /^\s+$/.test(line))
  502. return false;
  503. return /^\s*\}/.test(input);
  504. };
  505. this.autoOutdent = function(doc, row) {
  506. var line = doc.getLine(row);
  507. var match = line.match(/^(\s*\})/);
  508. if (!match) return 0;
  509. var column = match[1].length;
  510. var openBracePos = doc.findMatchingBracket({row: row, column: column});
  511. if (!openBracePos || openBracePos.row == row) return 0;
  512. var indent = this.$getIndent(doc.getLine(openBracePos.row));
  513. doc.replace(new Range(row, 0, row, column-1), indent);
  514. };
  515. this.$getIndent = function(line) {
  516. return line.match(/^\s*/)[0];
  517. };
  518. }).call(MatchingBraceOutdent.prototype);
  519. exports.MatchingBraceOutdent = MatchingBraceOutdent;
  520. });
  521. ace.define("ace/mode/behaviour/cstyle",["require","exports","module","ace/lib/oop","ace/mode/behaviour","ace/token_iterator","ace/lib/lang"], function(require, exports, module) {
  522. "use strict";
  523. var oop = require("../../lib/oop");
  524. var Behaviour = require("../behaviour").Behaviour;
  525. var TokenIterator = require("../../token_iterator").TokenIterator;
  526. var lang = require("../../lib/lang");
  527. var SAFE_INSERT_IN_TOKENS =
  528. ["text", "paren.rparen", "punctuation.operator"];
  529. var SAFE_INSERT_BEFORE_TOKENS =
  530. ["text", "paren.rparen", "punctuation.operator", "comment"];
  531. var context;
  532. var contextCache = {};
  533. var initContext = function(editor) {
  534. var id = -1;
  535. if (editor.multiSelect) {
  536. id = editor.selection.index;
  537. if (contextCache.rangeCount != editor.multiSelect.rangeCount)
  538. contextCache = {rangeCount: editor.multiSelect.rangeCount};
  539. }
  540. if (contextCache[id])
  541. return context = contextCache[id];
  542. context = contextCache[id] = {
  543. autoInsertedBrackets: 0,
  544. autoInsertedRow: -1,
  545. autoInsertedLineEnd: "",
  546. maybeInsertedBrackets: 0,
  547. maybeInsertedRow: -1,
  548. maybeInsertedLineStart: "",
  549. maybeInsertedLineEnd: ""
  550. };
  551. };
  552. var getWrapped = function(selection, selected, opening, closing) {
  553. var rowDiff = selection.end.row - selection.start.row;
  554. return {
  555. text: opening + selected + closing,
  556. selection: [
  557. 0,
  558. selection.start.column + 1,
  559. rowDiff,
  560. selection.end.column + (rowDiff ? 0 : 1)
  561. ]
  562. };
  563. };
  564. var CstyleBehaviour = function() {
  565. this.add("braces", "insertion", function(state, action, editor, session, text) {
  566. var cursor = editor.getCursorPosition();
  567. var line = session.doc.getLine(cursor.row);
  568. if (text == '{') {
  569. initContext(editor);
  570. var selection = editor.getSelectionRange();
  571. var selected = session.doc.getTextRange(selection);
  572. if (selected !== "" && selected !== "{" && editor.getWrapBehavioursEnabled()) {
  573. return getWrapped(selection, selected, '{', '}');
  574. } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
  575. if (/[\]\}\)]/.test(line[cursor.column]) || editor.inMultiSelectMode) {
  576. CstyleBehaviour.recordAutoInsert(editor, session, "}");
  577. return {
  578. text: '{}',
  579. selection: [1, 1]
  580. };
  581. } else {
  582. CstyleBehaviour.recordMaybeInsert(editor, session, "{");
  583. return {
  584. text: '{',
  585. selection: [1, 1]
  586. };
  587. }
  588. }
  589. } else if (text == '}') {
  590. initContext(editor);
  591. var rightChar = line.substring(cursor.column, cursor.column + 1);
  592. if (rightChar == '}') {
  593. var matching = session.$findOpeningBracket('}', {column: cursor.column + 1, row: cursor.row});
  594. if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) {
  595. CstyleBehaviour.popAutoInsertedClosing();
  596. return {
  597. text: '',
  598. selection: [1, 1]
  599. };
  600. }
  601. }
  602. } else if (text == "\n" || text == "\r\n") {
  603. initContext(editor);
  604. var closing = "";
  605. if (CstyleBehaviour.isMaybeInsertedClosing(cursor, line)) {
  606. closing = lang.stringRepeat("}", context.maybeInsertedBrackets);
  607. CstyleBehaviour.clearMaybeInsertedClosing();
  608. }
  609. var rightChar = line.substring(cursor.column, cursor.column + 1);
  610. if (rightChar === '}') {
  611. var openBracePos = session.findMatchingBracket({row: cursor.row, column: cursor.column+1}, '}');
  612. if (!openBracePos)
  613. return null;
  614. var next_indent = this.$getIndent(session.getLine(openBracePos.row));
  615. } else if (closing) {
  616. var next_indent = this.$getIndent(line);
  617. } else {
  618. CstyleBehaviour.clearMaybeInsertedClosing();
  619. return;
  620. }
  621. var indent = next_indent + session.getTabString();
  622. return {
  623. text: '\n' + indent + '\n' + next_indent + closing,
  624. selection: [1, indent.length, 1, indent.length]
  625. };
  626. } else {
  627. CstyleBehaviour.clearMaybeInsertedClosing();
  628. }
  629. });
  630. this.add("braces", "deletion", function(state, action, editor, session, range) {
  631. var selected = session.doc.getTextRange(range);
  632. if (!range.isMultiLine() && selected == '{') {
  633. initContext(editor);
  634. var line = session.doc.getLine(range.start.row);
  635. var rightChar = line.substring(range.end.column, range.end.column + 1);
  636. if (rightChar == '}') {
  637. range.end.column++;
  638. return range;
  639. } else {
  640. context.maybeInsertedBrackets--;
  641. }
  642. }
  643. });
  644. this.add("parens", "insertion", function(state, action, editor, session, text) {
  645. if (text == '(') {
  646. initContext(editor);
  647. var selection = editor.getSelectionRange();
  648. var selected = session.doc.getTextRange(selection);
  649. if (selected !== "" && editor.getWrapBehavioursEnabled()) {
  650. return getWrapped(selection, selected, '(', ')');
  651. } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
  652. CstyleBehaviour.recordAutoInsert(editor, session, ")");
  653. return {
  654. text: '()',
  655. selection: [1, 1]
  656. };
  657. }
  658. } else if (text == ')') {
  659. initContext(editor);
  660. var cursor = editor.getCursorPosition();
  661. var line = session.doc.getLine(cursor.row);
  662. var rightChar = line.substring(cursor.column, cursor.column + 1);
  663. if (rightChar == ')') {
  664. var matching = session.$findOpeningBracket(')', {column: cursor.column + 1, row: cursor.row});
  665. if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) {
  666. CstyleBehaviour.popAutoInsertedClosing();
  667. return {
  668. text: '',
  669. selection: [1, 1]
  670. };
  671. }
  672. }
  673. }
  674. });
  675. this.add("parens", "deletion", function(state, action, editor, session, range) {
  676. var selected = session.doc.getTextRange(range);
  677. if (!range.isMultiLine() && selected == '(') {
  678. initContext(editor);
  679. var line = session.doc.getLine(range.start.row);
  680. var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
  681. if (rightChar == ')') {
  682. range.end.column++;
  683. return range;
  684. }
  685. }
  686. });
  687. this.add("brackets", "insertion", function(state, action, editor, session, text) {
  688. if (text == '[') {
  689. initContext(editor);
  690. var selection = editor.getSelectionRange();
  691. var selected = session.doc.getTextRange(selection);
  692. if (selected !== "" && editor.getWrapBehavioursEnabled()) {
  693. return getWrapped(selection, selected, '[', ']');
  694. } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
  695. CstyleBehaviour.recordAutoInsert(editor, session, "]");
  696. return {
  697. text: '[]',
  698. selection: [1, 1]
  699. };
  700. }
  701. } else if (text == ']') {
  702. initContext(editor);
  703. var cursor = editor.getCursorPosition();
  704. var line = session.doc.getLine(cursor.row);
  705. var rightChar = line.substring(cursor.column, cursor.column + 1);
  706. if (rightChar == ']') {
  707. var matching = session.$findOpeningBracket(']', {column: cursor.column + 1, row: cursor.row});
  708. if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) {
  709. CstyleBehaviour.popAutoInsertedClosing();
  710. return {
  711. text: '',
  712. selection: [1, 1]
  713. };
  714. }
  715. }
  716. }
  717. });
  718. this.add("brackets", "deletion", function(state, action, editor, session, range) {
  719. var selected = session.doc.getTextRange(range);
  720. if (!range.isMultiLine() && selected == '[') {
  721. initContext(editor);
  722. var line = session.doc.getLine(range.start.row);
  723. var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
  724. if (rightChar == ']') {
  725. range.end.column++;
  726. return range;
  727. }
  728. }
  729. });
  730. this.add("string_dquotes", "insertion", function(state, action, editor, session, text) {
  731. if (text == '"' || text == "'") {
  732. initContext(editor);
  733. var quote = text;
  734. var selection = editor.getSelectionRange();
  735. var selected = session.doc.getTextRange(selection);
  736. if (selected !== "" && selected !== "'" && selected != '"' && editor.getWrapBehavioursEnabled()) {
  737. return getWrapped(selection, selected, quote, quote);
  738. } else if (!selected) {
  739. var cursor = editor.getCursorPosition();
  740. var line = session.doc.getLine(cursor.row);
  741. var leftChar = line.substring(cursor.column-1, cursor.column);
  742. var rightChar = line.substring(cursor.column, cursor.column + 1);
  743. var token = session.getTokenAt(cursor.row, cursor.column);
  744. var rightToken = session.getTokenAt(cursor.row, cursor.column + 1);
  745. if (leftChar == "\\" && token && /escape/.test(token.type))
  746. return null;
  747. var stringBefore = token && /string|escape/.test(token.type);
  748. var stringAfter = !rightToken || /string|escape/.test(rightToken.type);
  749. var pair;
  750. if (rightChar == quote) {
  751. pair = stringBefore !== stringAfter;
  752. } else {
  753. if (stringBefore && !stringAfter)
  754. return null; // wrap string with different quote
  755. if (stringBefore && stringAfter)
  756. return null; // do not pair quotes inside strings
  757. var wordRe = session.$mode.tokenRe;
  758. wordRe.lastIndex = 0;
  759. var isWordBefore = wordRe.test(leftChar);
  760. wordRe.lastIndex = 0;
  761. var isWordAfter = wordRe.test(leftChar);
  762. if (isWordBefore || isWordAfter)
  763. return null; // before or after alphanumeric
  764. if (rightChar && !/[\s;,.})\]\\]/.test(rightChar))
  765. return null; // there is rightChar and it isn't closing
  766. pair = true;
  767. }
  768. return {
  769. text: pair ? quote + quote : "",
  770. selection: [1,1]
  771. };
  772. }
  773. }
  774. });
  775. this.add("string_dquotes", "deletion", function(state, action, editor, session, range) {
  776. var selected = session.doc.getTextRange(range);
  777. if (!range.isMultiLine() && (selected == '"' || selected == "'")) {
  778. initContext(editor);
  779. var line = session.doc.getLine(range.start.row);
  780. var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
  781. if (rightChar == selected) {
  782. range.end.column++;
  783. return range;
  784. }
  785. }
  786. });
  787. };
  788. CstyleBehaviour.isSaneInsertion = function(editor, session) {
  789. var cursor = editor.getCursorPosition();
  790. var iterator = new TokenIterator(session, cursor.row, cursor.column);
  791. if (!this.$matchTokenType(iterator.getCurrentToken() || "text", SAFE_INSERT_IN_TOKENS)) {
  792. var iterator2 = new TokenIterator(session, cursor.row, cursor.column + 1);
  793. if (!this.$matchTokenType(iterator2.getCurrentToken() || "text", SAFE_INSERT_IN_TOKENS))
  794. return false;
  795. }
  796. iterator.stepForward();
  797. return iterator.getCurrentTokenRow() !== cursor.row ||
  798. this.$matchTokenType(iterator.getCurrentToken() || "text", SAFE_INSERT_BEFORE_TOKENS);
  799. };
  800. CstyleBehaviour.$matchTokenType = function(token, types) {
  801. return types.indexOf(token.type || token) > -1;
  802. };
  803. CstyleBehaviour.recordAutoInsert = function(editor, session, bracket) {
  804. var cursor = editor.getCursorPosition();
  805. var line = session.doc.getLine(cursor.row);
  806. if (!this.isAutoInsertedClosing(cursor, line, context.autoInsertedLineEnd[0]))
  807. context.autoInsertedBrackets = 0;
  808. context.autoInsertedRow = cursor.row;
  809. context.autoInsertedLineEnd = bracket + line.substr(cursor.column);
  810. context.autoInsertedBrackets++;
  811. };
  812. CstyleBehaviour.recordMaybeInsert = function(editor, session, bracket) {
  813. var cursor = editor.getCursorPosition();
  814. var line = session.doc.getLine(cursor.row);
  815. if (!this.isMaybeInsertedClosing(cursor, line))
  816. context.maybeInsertedBrackets = 0;
  817. context.maybeInsertedRow = cursor.row;
  818. context.maybeInsertedLineStart = line.substr(0, cursor.column) + bracket;
  819. context.maybeInsertedLineEnd = line.substr(cursor.column);
  820. context.maybeInsertedBrackets++;
  821. };
  822. CstyleBehaviour.isAutoInsertedClosing = function(cursor, line, bracket) {
  823. return context.autoInsertedBrackets > 0 &&
  824. cursor.row === context.autoInsertedRow &&
  825. bracket === context.autoInsertedLineEnd[0] &&
  826. line.substr(cursor.column) === context.autoInsertedLineEnd;
  827. };
  828. CstyleBehaviour.isMaybeInsertedClosing = function(cursor, line) {
  829. return context.maybeInsertedBrackets > 0 &&
  830. cursor.row === context.maybeInsertedRow &&
  831. line.substr(cursor.column) === context.maybeInsertedLineEnd &&
  832. line.substr(0, cursor.column) == context.maybeInsertedLineStart;
  833. };
  834. CstyleBehaviour.popAutoInsertedClosing = function() {
  835. context.autoInsertedLineEnd = context.autoInsertedLineEnd.substr(1);
  836. context.autoInsertedBrackets--;
  837. };
  838. CstyleBehaviour.clearMaybeInsertedClosing = function() {
  839. if (context) {
  840. context.maybeInsertedBrackets = 0;
  841. context.maybeInsertedRow = -1;
  842. }
  843. };
  844. oop.inherits(CstyleBehaviour, Behaviour);
  845. exports.CstyleBehaviour = CstyleBehaviour;
  846. });
  847. ace.define("ace/mode/folding/cstyle",["require","exports","module","ace/lib/oop","ace/range","ace/mode/folding/fold_mode"], function(require, exports, module) {
  848. "use strict";
  849. var oop = require("../../lib/oop");
  850. var Range = require("../../range").Range;
  851. var BaseFoldMode = require("./fold_mode").FoldMode;
  852. var FoldMode = exports.FoldMode = function(commentRegex) {
  853. if (commentRegex) {
  854. this.foldingStartMarker = new RegExp(
  855. this.foldingStartMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.start)
  856. );
  857. this.foldingStopMarker = new RegExp(
  858. this.foldingStopMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.end)
  859. );
  860. }
  861. };
  862. oop.inherits(FoldMode, BaseFoldMode);
  863. (function() {
  864. this.foldingStartMarker = /(\{|\[)[^\}\]]*$|^\s*(\/\*)/;
  865. this.foldingStopMarker = /^[^\[\{]*(\}|\])|^[\s\*]*(\*\/)/;
  866. this.singleLineBlockCommentRe= /^\s*(\/\*).*\*\/\s*$/;
  867. this.tripleStarBlockCommentRe = /^\s*(\/\*\*\*).*\*\/\s*$/;
  868. this.startRegionRe = /^\s*(\/\*|\/\/)#?region\b/;
  869. this._getFoldWidgetBase = this.getFoldWidget;
  870. this.getFoldWidget = function(session, foldStyle, row) {
  871. var line = session.getLine(row);
  872. if (this.singleLineBlockCommentRe.test(line)) {
  873. if (!this.startRegionRe.test(line) && !this.tripleStarBlockCommentRe.test(line))
  874. return "";
  875. }
  876. var fw = this._getFoldWidgetBase(session, foldStyle, row);
  877. if (!fw && this.startRegionRe.test(line))
  878. return "start"; // lineCommentRegionStart
  879. return fw;
  880. };
  881. this.getFoldWidgetRange = function(session, foldStyle, row, forceMultiline) {
  882. var line = session.getLine(row);
  883. if (this.startRegionRe.test(line))
  884. return this.getCommentRegionBlock(session, line, row);
  885. var match = line.match(this.foldingStartMarker);
  886. if (match) {
  887. var i = match.index;
  888. if (match[1])
  889. return this.openingBracketBlock(session, match[1], row, i);
  890. var range = session.getCommentFoldRange(row, i + match[0].length, 1);
  891. if (range && !range.isMultiLine()) {
  892. if (forceMultiline) {
  893. range = this.getSectionRange(session, row);
  894. } else if (foldStyle != "all")
  895. range = null;
  896. }
  897. return range;
  898. }
  899. if (foldStyle === "markbegin")
  900. return;
  901. var match = line.match(this.foldingStopMarker);
  902. if (match) {
  903. var i = match.index + match[0].length;
  904. if (match[1])
  905. return this.closingBracketBlock(session, match[1], row, i);
  906. return session.getCommentFoldRange(row, i, -1);
  907. }
  908. };
  909. this.getSectionRange = function(session, row) {
  910. var line = session.getLine(row);
  911. var startIndent = line.search(/\S/);
  912. var startRow = row;
  913. var startColumn = line.length;
  914. row = row + 1;
  915. var endRow = row;
  916. var maxRow = session.getLength();
  917. while (++row < maxRow) {
  918. line = session.getLine(row);
  919. var indent = line.search(/\S/);
  920. if (indent === -1)
  921. continue;
  922. if (startIndent > indent)
  923. break;
  924. var subRange = this.getFoldWidgetRange(session, "all", row);
  925. if (subRange) {
  926. if (subRange.start.row <= startRow) {
  927. break;
  928. } else if (subRange.isMultiLine()) {
  929. row = subRange.end.row;
  930. } else if (startIndent == indent) {
  931. break;
  932. }
  933. }
  934. endRow = row;
  935. }
  936. return new Range(startRow, startColumn, endRow, session.getLine(endRow).length);
  937. };
  938. this.getCommentRegionBlock = function(session, line, row) {
  939. var startColumn = line.search(/\s*$/);
  940. var maxRow = session.getLength();
  941. var startRow = row;
  942. var re = /^\s*(?:\/\*|\/\/|--)#?(end)?region\b/;
  943. var depth = 1;
  944. while (++row < maxRow) {
  945. line = session.getLine(row);
  946. var m = re.exec(line);
  947. if (!m) continue;
  948. if (m[1]) depth--;
  949. else depth++;
  950. if (!depth) break;
  951. }
  952. var endRow = row;
  953. if (endRow > startRow) {
  954. return new Range(startRow, startColumn, endRow, line.length);
  955. }
  956. };
  957. }).call(FoldMode.prototype);
  958. });
  959. ace.define("ace/mode/javascript",["require","exports","module","ace/lib/oop","ace/mode/text","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) {
  960. "use strict";
  961. var oop = require("../lib/oop");
  962. var TextMode = require("./text").Mode;
  963. var JavaScriptHighlightRules = require("./javascript_highlight_rules").JavaScriptHighlightRules;
  964. var MatchingBraceOutdent = require("./matching_brace_outdent").MatchingBraceOutdent;
  965. var Range = require("../range").Range;
  966. var WorkerClient = require("../worker/worker_client").WorkerClient;
  967. var CstyleBehaviour = require("./behaviour/cstyle").CstyleBehaviour;
  968. var CStyleFoldMode = require("./folding/cstyle").FoldMode;
  969. var Mode = function() {
  970. this.HighlightRules = JavaScriptHighlightRules;
  971. this.$outdent = new MatchingBraceOutdent();
  972. this.$behaviour = new CstyleBehaviour();
  973. this.foldingRules = new CStyleFoldMode();
  974. };
  975. oop.inherits(Mode, TextMode);
  976. (function() {
  977. this.lineCommentStart = "//";
  978. this.blockComment = {start: "/*", end: "*/"};
  979. this.getNextLineIndent = function(state, line, tab) {
  980. var indent = this.$getIndent(line);
  981. var tokenizedLine = this.getTokenizer().getLineTokens(line, state);
  982. var tokens = tokenizedLine.tokens;
  983. var endState = tokenizedLine.state;
  984. if (tokens.length && tokens[tokens.length-1].type == "comment") {
  985. return indent;
  986. }
  987. if (state == "start" || state == "no_regex") {
  988. var match = line.match(/^.*(?:\bcase\b.*\:|[\{\(\[])\s*$/);
  989. if (match) {
  990. indent += tab;
  991. }
  992. } else if (state == "doc-start") {
  993. if (endState == "start" || endState == "no_regex") {
  994. return "";
  995. }
  996. var match = line.match(/^\s*(\/?)\*/);
  997. if (match) {
  998. if (match[1]) {
  999. indent += " ";
  1000. }
  1001. indent += "* ";
  1002. }
  1003. }
  1004. return indent;
  1005. };
  1006. this.checkOutdent = function(state, line, input) {
  1007. return this.$outdent.checkOutdent(line, input);
  1008. };
  1009. this.autoOutdent = function(state, doc, row) {
  1010. this.$outdent.autoOutdent(doc, row);
  1011. };
  1012. this.createWorker = function(session) {
  1013. var worker = new WorkerClient(["ace"], "ace/mode/javascript_worker", "JavaScriptWorker");
  1014. worker.attachToDocument(session.getDocument());
  1015. worker.on("annotate", function(results) {
  1016. session.setAnnotations(results.data);
  1017. });
  1018. worker.on("terminate", function() {
  1019. session.clearAnnotations();
  1020. });
  1021. return worker;
  1022. };
  1023. this.$id = "ace/mode/javascript";
  1024. }).call(Mode.prototype);
  1025. exports.Mode = Mode;
  1026. });