mode-sjs.js 36 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013
  1. ace.define("ace/mode/doc_comment_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",[], 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]*";
  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|async|await|" +
  62. "break|case|catch|continue|default|delete|do|else|finally|for|function|" +
  63. "if|in|of|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", // hexadecimal, octal and binary
  96. regex : /0(?:[xX][0-9a-fA-F]+|[oO][0-7]+|[bB][01]+)\b/
  97. }, {
  98. token : "constant.numeric", // decimal integers and floats
  99. regex : /(?:\d\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 : "from(?=\\s*('|\"))"
  151. }, {
  152. token : "keyword",
  153. regex : "(?:" + kwBeforeRe + ")\\b",
  154. next : "start"
  155. }, {
  156. token : ["support.constant"],
  157. regex : /that\b/
  158. }, {
  159. token : ["storage.type", "punctuation.operator", "support.function.firebug"],
  160. regex : /(console)(\.)(warn|info|log|error|time|trace|timeEnd|assert)\b/
  161. }, {
  162. token : keywordMapper,
  163. regex : identifierRe
  164. }, {
  165. token : "punctuation.operator",
  166. regex : /[.](?![.])/,
  167. next : "property"
  168. }, {
  169. token : "storage.type",
  170. regex : /=>/
  171. }, {
  172. token : "keyword.operator",
  173. regex : /--|\+\+|\.{3}|===|==|=|!=|!==|<+=?|>+=?|!|&&|\|\||\?:|[!$%&*+\-~\/^]=?/,
  174. next : "start"
  175. }, {
  176. token : "punctuation.operator",
  177. regex : /[?:,;.]/,
  178. next : "start"
  179. }, {
  180. token : "paren.lparen",
  181. regex : /[\[({]/,
  182. next : "start"
  183. }, {
  184. token : "paren.rparen",
  185. regex : /[\])}]/
  186. }, {
  187. token: "comment",
  188. regex: /^#!.*$/
  189. }
  190. ],
  191. property: [{
  192. token : "text",
  193. regex : "\\s+"
  194. }, {
  195. token : [
  196. "storage.type", "punctuation.operator", "entity.name.function", "text",
  197. "keyword.operator", "text",
  198. "storage.type", "text", "entity.name.function", "text", "paren.lparen"
  199. ],
  200. regex : "(" + identifierRe + ")(\\.)(" + identifierRe +")(\\s*)(=)(\\s*)(function)(?:(\\s+)(\\w+))?(\\s*)(\\()",
  201. next: "function_arguments"
  202. }, {
  203. token : "punctuation.operator",
  204. regex : /[.](?![.])/
  205. }, {
  206. token : "support.function",
  207. 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(?=\()/
  208. }, {
  209. token : "support.function.dom",
  210. 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(?=\()/
  211. }, {
  212. token : "support.constant",
  213. 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/
  214. }, {
  215. token : "identifier",
  216. regex : identifierRe
  217. }, {
  218. regex: "",
  219. token: "empty",
  220. next: "no_regex"
  221. }
  222. ],
  223. "start": [
  224. DocCommentHighlightRules.getStartRule("doc-start"),
  225. comments("start"),
  226. {
  227. token: "string.regexp",
  228. regex: "\\/",
  229. next: "regex"
  230. }, {
  231. token : "text",
  232. regex : "\\s+|^$",
  233. next : "start"
  234. }, {
  235. token: "empty",
  236. regex: "",
  237. next: "no_regex"
  238. }
  239. ],
  240. "regex": [
  241. {
  242. token: "regexp.keyword.operator",
  243. regex: "\\\\(?:u[\\da-fA-F]{4}|x[\\da-fA-F]{2}|.)"
  244. }, {
  245. token: "string.regexp",
  246. regex: "/[sxngimy]*",
  247. next: "no_regex"
  248. }, {
  249. token : "invalid",
  250. regex: /\{\d+\b,?\d*\}[+*]|[+*$^?][+*]|[$^][?]|\?{3,}/
  251. }, {
  252. token : "constant.language.escape",
  253. regex: /\(\?[:=!]|\)|\{\d+\b,?\d*\}|[+*]\?|[()$^+*?.]/
  254. }, {
  255. token : "constant.language.delimiter",
  256. regex: /\|/
  257. }, {
  258. token: "constant.language.escape",
  259. regex: /\[\^?/,
  260. next: "regex_character_class"
  261. }, {
  262. token: "empty",
  263. regex: "$",
  264. next: "no_regex"
  265. }, {
  266. defaultToken: "string.regexp"
  267. }
  268. ],
  269. "regex_character_class": [
  270. {
  271. token: "regexp.charclass.keyword.operator",
  272. regex: "\\\\(?:u[\\da-fA-F]{4}|x[\\da-fA-F]{2}|.)"
  273. }, {
  274. token: "constant.language.escape",
  275. regex: "]",
  276. next: "regex"
  277. }, {
  278. token: "constant.language.escape",
  279. regex: "-"
  280. }, {
  281. token: "empty",
  282. regex: "$",
  283. next: "no_regex"
  284. }, {
  285. defaultToken: "string.regexp.charachterclass"
  286. }
  287. ],
  288. "function_arguments": [
  289. {
  290. token: "variable.parameter",
  291. regex: identifierRe
  292. }, {
  293. token: "punctuation.operator",
  294. regex: "[, ]+"
  295. }, {
  296. token: "punctuation.operator",
  297. regex: "$"
  298. }, {
  299. token: "empty",
  300. regex: "",
  301. next: "no_regex"
  302. }
  303. ],
  304. "qqstring" : [
  305. {
  306. token : "constant.language.escape",
  307. regex : escapedRe
  308. }, {
  309. token : "string",
  310. regex : "\\\\$",
  311. consumeLineEnd : true
  312. }, {
  313. token : "string",
  314. regex : '"|$',
  315. next : "no_regex"
  316. }, {
  317. defaultToken: "string"
  318. }
  319. ],
  320. "qstring" : [
  321. {
  322. token : "constant.language.escape",
  323. regex : escapedRe
  324. }, {
  325. token : "string",
  326. regex : "\\\\$",
  327. consumeLineEnd : true
  328. }, {
  329. token : "string",
  330. regex : "'|$",
  331. next : "no_regex"
  332. }, {
  333. defaultToken: "string"
  334. }
  335. ]
  336. };
  337. if (!options || !options.noES6) {
  338. this.$rules.no_regex.unshift({
  339. regex: "[{}]", onMatch: function(val, state, stack) {
  340. this.next = val == "{" ? this.nextState : "";
  341. if (val == "{" && stack.length) {
  342. stack.unshift("start", state);
  343. }
  344. else if (val == "}" && stack.length) {
  345. stack.shift();
  346. this.next = stack.shift();
  347. if (this.next.indexOf("string") != -1 || this.next.indexOf("jsx") != -1)
  348. return "paren.quasi.end";
  349. }
  350. return val == "{" ? "paren.lparen" : "paren.rparen";
  351. },
  352. nextState: "start"
  353. }, {
  354. token : "string.quasi.start",
  355. regex : /`/,
  356. push : [{
  357. token : "constant.language.escape",
  358. regex : escapedRe
  359. }, {
  360. token : "paren.quasi.start",
  361. regex : /\${/,
  362. push : "start"
  363. }, {
  364. token : "string.quasi.end",
  365. regex : /`/,
  366. next : "pop"
  367. }, {
  368. defaultToken: "string.quasi"
  369. }]
  370. });
  371. if (!options || options.jsx != false)
  372. JSX.call(this);
  373. }
  374. this.embedRules(DocCommentHighlightRules, "doc-",
  375. [ DocCommentHighlightRules.getEndRule("no_regex") ]);
  376. this.normalizeRules();
  377. };
  378. oop.inherits(JavaScriptHighlightRules, TextHighlightRules);
  379. function JSX() {
  380. var tagRegex = identifierRe.replace("\\d", "\\d\\-");
  381. var jsxTag = {
  382. onMatch : function(val, state, stack) {
  383. var offset = val.charAt(1) == "/" ? 2 : 1;
  384. if (offset == 1) {
  385. if (state != this.nextState)
  386. stack.unshift(this.next, this.nextState, 0);
  387. else
  388. stack.unshift(this.next);
  389. stack[2]++;
  390. } else if (offset == 2) {
  391. if (state == this.nextState) {
  392. stack[1]--;
  393. if (!stack[1] || stack[1] < 0) {
  394. stack.shift();
  395. stack.shift();
  396. }
  397. }
  398. }
  399. return [{
  400. type: "meta.tag.punctuation." + (offset == 1 ? "" : "end-") + "tag-open.xml",
  401. value: val.slice(0, offset)
  402. }, {
  403. type: "meta.tag.tag-name.xml",
  404. value: val.substr(offset)
  405. }];
  406. },
  407. regex : "</?" + tagRegex + "",
  408. next: "jsxAttributes",
  409. nextState: "jsx"
  410. };
  411. this.$rules.start.unshift(jsxTag);
  412. var jsxJsRule = {
  413. regex: "{",
  414. token: "paren.quasi.start",
  415. push: "start"
  416. };
  417. this.$rules.jsx = [
  418. jsxJsRule,
  419. jsxTag,
  420. {include : "reference"},
  421. {defaultToken: "string"}
  422. ];
  423. this.$rules.jsxAttributes = [{
  424. token : "meta.tag.punctuation.tag-close.xml",
  425. regex : "/?>",
  426. onMatch : function(value, currentState, stack) {
  427. if (currentState == stack[0])
  428. stack.shift();
  429. if (value.length == 2) {
  430. if (stack[0] == this.nextState)
  431. stack[1]--;
  432. if (!stack[1] || stack[1] < 0) {
  433. stack.splice(0, 2);
  434. }
  435. }
  436. this.next = stack[0] || "start";
  437. return [{type: this.token, value: value}];
  438. },
  439. nextState: "jsx"
  440. },
  441. jsxJsRule,
  442. comments("jsxAttributes"),
  443. {
  444. token : "entity.other.attribute-name.xml",
  445. regex : tagRegex
  446. }, {
  447. token : "keyword.operator.attribute-equals.xml",
  448. regex : "="
  449. }, {
  450. token : "text.tag-whitespace.xml",
  451. regex : "\\s+"
  452. }, {
  453. token : "string.attribute-value.xml",
  454. regex : "'",
  455. stateName : "jsx_attr_q",
  456. push : [
  457. {token : "string.attribute-value.xml", regex: "'", next: "pop"},
  458. {include : "reference"},
  459. {defaultToken : "string.attribute-value.xml"}
  460. ]
  461. }, {
  462. token : "string.attribute-value.xml",
  463. regex : '"',
  464. stateName : "jsx_attr_qq",
  465. push : [
  466. {token : "string.attribute-value.xml", regex: '"', next: "pop"},
  467. {include : "reference"},
  468. {defaultToken : "string.attribute-value.xml"}
  469. ]
  470. },
  471. jsxTag
  472. ];
  473. this.$rules.reference = [{
  474. token : "constant.language.escape.reference.xml",
  475. regex : "(?:&#[0-9]+;)|(?:&#x[0-9a-fA-F]+;)|(?:&[a-zA-Z0-9_:\\.-]+;)"
  476. }];
  477. }
  478. function comments(next) {
  479. return [
  480. {
  481. token : "comment", // multi line comment
  482. regex : /\/\*/,
  483. next: [
  484. DocCommentHighlightRules.getTagRule(),
  485. {token : "comment", regex : "\\*\\/", next : next || "pop"},
  486. {defaultToken : "comment", caseInsensitive: true}
  487. ]
  488. }, {
  489. token : "comment",
  490. regex : "\\/\\/",
  491. next: [
  492. DocCommentHighlightRules.getTagRule(),
  493. {token : "comment", regex : "$|^", next : next || "pop"},
  494. {defaultToken : "comment", caseInsensitive: true}
  495. ]
  496. }
  497. ];
  498. }
  499. exports.JavaScriptHighlightRules = JavaScriptHighlightRules;
  500. });
  501. ace.define("ace/mode/matching_brace_outdent",[], function(require, exports, module) {
  502. "use strict";
  503. var Range = require("../range").Range;
  504. var MatchingBraceOutdent = function() {};
  505. (function() {
  506. this.checkOutdent = function(line, input) {
  507. if (! /^\s+$/.test(line))
  508. return false;
  509. return /^\s*\}/.test(input);
  510. };
  511. this.autoOutdent = function(doc, row) {
  512. var line = doc.getLine(row);
  513. var match = line.match(/^(\s*\})/);
  514. if (!match) return 0;
  515. var column = match[1].length;
  516. var openBracePos = doc.findMatchingBracket({row: row, column: column});
  517. if (!openBracePos || openBracePos.row == row) return 0;
  518. var indent = this.$getIndent(doc.getLine(openBracePos.row));
  519. doc.replace(new Range(row, 0, row, column-1), indent);
  520. };
  521. this.$getIndent = function(line) {
  522. return line.match(/^\s*/)[0];
  523. };
  524. }).call(MatchingBraceOutdent.prototype);
  525. exports.MatchingBraceOutdent = MatchingBraceOutdent;
  526. });
  527. ace.define("ace/mode/folding/cstyle",[], function(require, exports, module) {
  528. "use strict";
  529. var oop = require("../../lib/oop");
  530. var Range = require("../../range").Range;
  531. var BaseFoldMode = require("./fold_mode").FoldMode;
  532. var FoldMode = exports.FoldMode = function(commentRegex) {
  533. if (commentRegex) {
  534. this.foldingStartMarker = new RegExp(
  535. this.foldingStartMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.start)
  536. );
  537. this.foldingStopMarker = new RegExp(
  538. this.foldingStopMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.end)
  539. );
  540. }
  541. };
  542. oop.inherits(FoldMode, BaseFoldMode);
  543. (function() {
  544. this.foldingStartMarker = /([\{\[\(])[^\}\]\)]*$|^\s*(\/\*)/;
  545. this.foldingStopMarker = /^[^\[\{\(]*([\}\]\)])|^[\s\*]*(\*\/)/;
  546. this.singleLineBlockCommentRe= /^\s*(\/\*).*\*\/\s*$/;
  547. this.tripleStarBlockCommentRe = /^\s*(\/\*\*\*).*\*\/\s*$/;
  548. this.startRegionRe = /^\s*(\/\*|\/\/)#?region\b/;
  549. this._getFoldWidgetBase = this.getFoldWidget;
  550. this.getFoldWidget = function(session, foldStyle, row) {
  551. var line = session.getLine(row);
  552. if (this.singleLineBlockCommentRe.test(line)) {
  553. if (!this.startRegionRe.test(line) && !this.tripleStarBlockCommentRe.test(line))
  554. return "";
  555. }
  556. var fw = this._getFoldWidgetBase(session, foldStyle, row);
  557. if (!fw && this.startRegionRe.test(line))
  558. return "start"; // lineCommentRegionStart
  559. return fw;
  560. };
  561. this.getFoldWidgetRange = function(session, foldStyle, row, forceMultiline) {
  562. var line = session.getLine(row);
  563. if (this.startRegionRe.test(line))
  564. return this.getCommentRegionBlock(session, line, row);
  565. var match = line.match(this.foldingStartMarker);
  566. if (match) {
  567. var i = match.index;
  568. if (match[1])
  569. return this.openingBracketBlock(session, match[1], row, i);
  570. var range = session.getCommentFoldRange(row, i + match[0].length, 1);
  571. if (range && !range.isMultiLine()) {
  572. if (forceMultiline) {
  573. range = this.getSectionRange(session, row);
  574. } else if (foldStyle != "all")
  575. range = null;
  576. }
  577. return range;
  578. }
  579. if (foldStyle === "markbegin")
  580. return;
  581. var match = line.match(this.foldingStopMarker);
  582. if (match) {
  583. var i = match.index + match[0].length;
  584. if (match[1])
  585. return this.closingBracketBlock(session, match[1], row, i);
  586. return session.getCommentFoldRange(row, i, -1);
  587. }
  588. };
  589. this.getSectionRange = function(session, row) {
  590. var line = session.getLine(row);
  591. var startIndent = line.search(/\S/);
  592. var startRow = row;
  593. var startColumn = line.length;
  594. row = row + 1;
  595. var endRow = row;
  596. var maxRow = session.getLength();
  597. while (++row < maxRow) {
  598. line = session.getLine(row);
  599. var indent = line.search(/\S/);
  600. if (indent === -1)
  601. continue;
  602. if (startIndent > indent)
  603. break;
  604. var subRange = this.getFoldWidgetRange(session, "all", row);
  605. if (subRange) {
  606. if (subRange.start.row <= startRow) {
  607. break;
  608. } else if (subRange.isMultiLine()) {
  609. row = subRange.end.row;
  610. } else if (startIndent == indent) {
  611. break;
  612. }
  613. }
  614. endRow = row;
  615. }
  616. return new Range(startRow, startColumn, endRow, session.getLine(endRow).length);
  617. };
  618. this.getCommentRegionBlock = function(session, line, row) {
  619. var startColumn = line.search(/\s*$/);
  620. var maxRow = session.getLength();
  621. var startRow = row;
  622. var re = /^\s*(?:\/\*|\/\/|--)#?(end)?region\b/;
  623. var depth = 1;
  624. while (++row < maxRow) {
  625. line = session.getLine(row);
  626. var m = re.exec(line);
  627. if (!m) continue;
  628. if (m[1]) depth--;
  629. else depth++;
  630. if (!depth) break;
  631. }
  632. var endRow = row;
  633. if (endRow > startRow) {
  634. return new Range(startRow, startColumn, endRow, line.length);
  635. }
  636. };
  637. }).call(FoldMode.prototype);
  638. });
  639. ace.define("ace/mode/javascript",[], function(require, exports, module) {
  640. "use strict";
  641. var oop = require("../lib/oop");
  642. var TextMode = require("./text").Mode;
  643. var JavaScriptHighlightRules = require("./javascript_highlight_rules").JavaScriptHighlightRules;
  644. var MatchingBraceOutdent = require("./matching_brace_outdent").MatchingBraceOutdent;
  645. var WorkerClient = require("../worker/worker_client").WorkerClient;
  646. var CstyleBehaviour = require("./behaviour/cstyle").CstyleBehaviour;
  647. var CStyleFoldMode = require("./folding/cstyle").FoldMode;
  648. var Mode = function() {
  649. this.HighlightRules = JavaScriptHighlightRules;
  650. this.$outdent = new MatchingBraceOutdent();
  651. this.$behaviour = new CstyleBehaviour();
  652. this.foldingRules = new CStyleFoldMode();
  653. };
  654. oop.inherits(Mode, TextMode);
  655. (function() {
  656. this.lineCommentStart = "//";
  657. this.blockComment = {start: "/*", end: "*/"};
  658. this.$quotes = {'"': '"', "'": "'", "`": "`"};
  659. this.getNextLineIndent = function(state, line, tab) {
  660. var indent = this.$getIndent(line);
  661. var tokenizedLine = this.getTokenizer().getLineTokens(line, state);
  662. var tokens = tokenizedLine.tokens;
  663. var endState = tokenizedLine.state;
  664. if (tokens.length && tokens[tokens.length-1].type == "comment") {
  665. return indent;
  666. }
  667. if (state == "start" || state == "no_regex") {
  668. var match = line.match(/^.*(?:\bcase\b.*:|[\{\(\[])\s*$/);
  669. if (match) {
  670. indent += tab;
  671. }
  672. } else if (state == "doc-start") {
  673. if (endState == "start" || endState == "no_regex") {
  674. return "";
  675. }
  676. var match = line.match(/^\s*(\/?)\*/);
  677. if (match) {
  678. if (match[1]) {
  679. indent += " ";
  680. }
  681. indent += "* ";
  682. }
  683. }
  684. return indent;
  685. };
  686. this.checkOutdent = function(state, line, input) {
  687. return this.$outdent.checkOutdent(line, input);
  688. };
  689. this.autoOutdent = function(state, doc, row) {
  690. this.$outdent.autoOutdent(doc, row);
  691. };
  692. this.createWorker = function(session) {
  693. var worker = new WorkerClient(["ace"], "ace/mode/javascript_worker", "JavaScriptWorker");
  694. worker.attachToDocument(session.getDocument());
  695. worker.on("annotate", function(results) {
  696. session.setAnnotations(results.data);
  697. });
  698. worker.on("terminate", function() {
  699. session.clearAnnotations();
  700. });
  701. return worker;
  702. };
  703. this.$id = "ace/mode/javascript";
  704. }).call(Mode.prototype);
  705. exports.Mode = Mode;
  706. });
  707. ace.define("ace/mode/sjs_highlight_rules",[], function(require, exports, module) {
  708. "use strict";
  709. var oop = require("../lib/oop");
  710. var JavaScriptHighlightRules = require("./javascript_highlight_rules").JavaScriptHighlightRules;
  711. var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
  712. var SJSHighlightRules = function() {
  713. var parent = new JavaScriptHighlightRules({noES6: true});
  714. var escapedRe = "\\\\(?:x[0-9a-fA-F]{2}|" + // hex
  715. "u[0-9a-fA-F]{4}|" + // unicode
  716. "[0-2][0-7]{0,2}|" + // oct
  717. "3[0-6][0-7]?|" + // oct
  718. "37[0-7]?|" + // oct
  719. "[4-7][0-7]?|" + //oct
  720. ".)";
  721. var contextAware = function(f) {
  722. f.isContextAware = true;
  723. return f;
  724. };
  725. var ctxBegin = function(opts) {
  726. return {
  727. token: opts.token,
  728. regex: opts.regex,
  729. next: contextAware(function(currentState, stack) {
  730. if (stack.length === 0)
  731. stack.unshift(currentState);
  732. stack.unshift(opts.next);
  733. return opts.next;
  734. })
  735. };
  736. };
  737. var ctxEnd = function(opts) {
  738. return {
  739. token: opts.token,
  740. regex: opts.regex,
  741. next: contextAware(function(currentState, stack) {
  742. stack.shift();
  743. return stack[0] || "start";
  744. })
  745. };
  746. };
  747. this.$rules = parent.$rules;
  748. this.$rules.no_regex = [
  749. {
  750. token: "keyword",
  751. regex: "(waitfor|or|and|collapse|spawn|retract)\\b"
  752. },
  753. {
  754. token: "keyword.operator",
  755. regex: "(->|=>|\\.\\.)"
  756. },
  757. {
  758. token: "variable.language",
  759. regex: "(hold|default)\\b"
  760. },
  761. ctxBegin({
  762. token: "string",
  763. regex: "`",
  764. next: "bstring"
  765. }),
  766. ctxBegin({
  767. token: "string",
  768. regex: '"',
  769. next: "qqstring"
  770. }),
  771. ctxBegin({
  772. token: "string",
  773. regex: '"',
  774. next: "qqstring"
  775. }),
  776. {
  777. token: ["paren.lparen", "text", "paren.rparen"],
  778. regex: "(\\{)(\\s*)(\\|)",
  779. next: "block_arguments"
  780. }
  781. ].concat(this.$rules.no_regex);
  782. this.$rules.block_arguments = [
  783. {
  784. token: "paren.rparen",
  785. regex: "\\|",
  786. next: "no_regex"
  787. }
  788. ].concat(this.$rules.function_arguments);
  789. this.$rules.bstring = [
  790. {
  791. token : "constant.language.escape",
  792. regex : escapedRe
  793. },
  794. {
  795. token : "string",
  796. regex : "\\\\$",
  797. next: "bstring"
  798. },
  799. ctxBegin({
  800. token : "paren.lparen",
  801. regex : "\\$\\{",
  802. next: "string_interp"
  803. }),
  804. ctxBegin({
  805. token : "paren.lparen",
  806. regex : "\\$",
  807. next: "bstring_interp_single"
  808. }),
  809. ctxEnd({
  810. token : "string",
  811. regex : "`"
  812. }),
  813. {
  814. defaultToken: "string"
  815. }
  816. ];
  817. this.$rules.qqstring = [
  818. {
  819. token : "constant.language.escape",
  820. regex : escapedRe
  821. },
  822. {
  823. token : "string",
  824. regex : "\\\\$",
  825. next: "qqstring"
  826. },
  827. ctxBegin({
  828. token : "paren.lparen",
  829. regex : "#\\{",
  830. next: "string_interp"
  831. }),
  832. ctxEnd({
  833. token : "string",
  834. regex : '"'
  835. }),
  836. {
  837. defaultToken: "string"
  838. }
  839. ];
  840. var embeddableRules = [];
  841. for (var i=0; i < this.$rules.no_regex.length; i++) {
  842. var rule = this.$rules.no_regex[i];
  843. var token = String(rule.token);
  844. if (token.indexOf('paren') == -1 && (!rule.next || rule.next.isContextAware)) {
  845. embeddableRules.push(rule);
  846. }
  847. }
  848. this.$rules.string_interp = [
  849. ctxEnd({
  850. token: "paren.rparen",
  851. regex: "\\}"
  852. }),
  853. ctxBegin({
  854. token: "paren.lparen",
  855. regex: '{',
  856. next: "string_interp"
  857. })
  858. ].concat(embeddableRules);
  859. this.$rules.bstring_interp_single = [
  860. {
  861. token: ["identifier", "paren.lparen"],
  862. regex: '(\\w+)(\\()',
  863. next: 'bstring_interp_single_call'
  864. },
  865. ctxEnd({
  866. token : "identifier",
  867. regex : "\\w*"
  868. })
  869. ];
  870. this.$rules.bstring_interp_single_call = [
  871. ctxBegin({
  872. token: "paren.lparen",
  873. regex: "\\(",
  874. next: "bstring_interp_single_call"
  875. }),
  876. ctxEnd({
  877. token: "paren.rparen",
  878. regex: "\\)"
  879. })
  880. ].concat(embeddableRules);
  881. };
  882. oop.inherits(SJSHighlightRules, TextHighlightRules);
  883. exports.SJSHighlightRules = SJSHighlightRules;
  884. });
  885. ace.define("ace/mode/sjs",[], function(require, exports, module) {
  886. "use strict";
  887. var oop = require("../lib/oop");
  888. var JSMode = require("./javascript").Mode;
  889. var SJSHighlightRules = require("./sjs_highlight_rules").SJSHighlightRules;
  890. var MatchingBraceOutdent = require("./matching_brace_outdent").MatchingBraceOutdent;
  891. var CstyleBehaviour = require("./behaviour/cstyle").CstyleBehaviour;
  892. var CStyleFoldMode = require("./folding/cstyle").FoldMode;
  893. var Mode = function() {
  894. this.HighlightRules = SJSHighlightRules;
  895. this.$outdent = new MatchingBraceOutdent();
  896. this.$behaviour = new CstyleBehaviour();
  897. this.foldingRules = new CStyleFoldMode();
  898. };
  899. oop.inherits(Mode, JSMode);
  900. (function() {
  901. this.createWorker = function(session) {
  902. return null;
  903. };
  904. this.$id = "ace/mode/sjs";
  905. }).call(Mode.prototype);
  906. exports.Mode = Mode;
  907. });
  908. (function() {
  909. ace.require(["ace/mode/sjs"], function(m) {
  910. if (typeof module == "object" && typeof exports == "object" && module) {
  911. module.exports = m;
  912. }
  913. });
  914. })();