PageRenderTime 62ms CodeModel.GetById 31ms RepoModel.GetById 0ms app.codeStats 0ms

/plugins/c9.ide.plugins/mock/c9.ide.example3/modes/javascript_highlight_rules.js

https://gitlab.com/c9-mirror/core
JavaScript | 405 lines | 356 code | 14 blank | 35 comment | 12 complexity | 845c93d407e71b2fd73ae3f9a2543ba3 MD5 | raw file
  1. /* ***** BEGIN LICENSE BLOCK *****
  2. * Distributed under the BSD license:
  3. *
  4. * Copyright (c) 2010, Ajax.org B.V.
  5. * All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions are met:
  9. * * Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. * * Redistributions in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in the
  13. * documentation and/or other materials provided with the distribution.
  14. * * Neither the name of Ajax.org B.V. nor the
  15. * names of its contributors may be used to endorse or promote products
  16. * derived from this software without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  19. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  20. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  21. * DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY
  22. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  23. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  24. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  25. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  26. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  27. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. *
  29. * ***** END LICENSE BLOCK ***** */
  30. define(function(require, exports, module) {
  31. "use strict";
  32. var oop = require("ace/lib/oop");
  33. var DocCommentHighlightRules = require("ace/mode/doc_comment_highlight_rules").DocCommentHighlightRules;
  34. var TextHighlightRules = require("ace/mode/text_highlight_rules").TextHighlightRules;
  35. var JavaScriptHighlightRules = function(options) {
  36. // see: https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects
  37. var keywordMapper = this.createKeywordMapper({
  38. "variable.language":
  39. "Array|Boolean|Date|Function|Iterator|Number|Object|RegExp|String|Proxy|" + // Constructors
  40. "Namespace|QName|XML|XMLList|" + // E4X
  41. "ArrayBuffer|Float32Array|Float64Array|Int16Array|Int32Array|Int8Array|" +
  42. "Uint16Array|Uint32Array|Uint8Array|Uint8ClampedArray|" +
  43. "Error|EvalError|InternalError|RangeError|ReferenceError|StopIteration|" + // Errors
  44. "SyntaxError|TypeError|URIError|" +
  45. "decodeURI|decodeURIComponent|encodeURI|encodeURIComponent|eval|isFinite|" + // Non-constructor functions
  46. "isNaN|parseFloat|parseInt|" +
  47. "JSON|Math|" + // Other
  48. "this|arguments|prototype|window|document" , // Pseudo
  49. "keyword":
  50. "const|yield|import|get|set|" +
  51. "break|case|catch|continue|default|delete|do|else|finally|for|function|" +
  52. "if|in|instanceof|new|return|switch|throw|try|typeof|let|var|while|with|debugger|" +
  53. // invalid or reserved
  54. "__parent__|__count__|escape|unescape|with|__proto__|" +
  55. "class|enum|extends|super|export|implements|private|public|interface|package|protected|static",
  56. "storage.type":
  57. "const|let|var|function",
  58. "constant.language":
  59. "null|Infinity|NaN|undefined",
  60. "support.function":
  61. "alert",
  62. "constant.language.boolean": "true|false"
  63. }, "identifier");
  64. // keywords which can be followed by regular expressions
  65. var kwBeforeRe = "case|do|else|finally|in|instanceof|return|throw|try|typeof|yield|void";
  66. // TODO: Unicode escape sequences
  67. var identifierRe = "[a-zA-Z\\$_\u00a1-\uffff][a-zA-Z\\d\\$_\u00a1-\uffff]*\\b";
  68. var escapedRe = "\\\\(?:x[0-9a-fA-F]{2}|" + // hex
  69. "u[0-9a-fA-F]{4}|" + // unicode
  70. "[0-2][0-7]{0,2}|" + // oct
  71. "3[0-6][0-7]?|" + // oct
  72. "37[0-7]?|" + // oct
  73. "[4-7][0-7]?|" + //oct
  74. ".)";
  75. // regexp must not have capturing parentheses. Use (?:) instead.
  76. // regexps are ordered -> the first match is used
  77. this.$rules = {
  78. "no_regex" : [
  79. {
  80. token : "comment",
  81. regex : "\\/\\/",
  82. next : "line_comment"
  83. },
  84. DocCommentHighlightRules.getStartRule("doc-start"),
  85. {
  86. token : "comment", // multi line comment
  87. regex : /\/\*/,
  88. next : "comment"
  89. }, {
  90. token : "string",
  91. regex : "'(?=.)",
  92. next : "qstring"
  93. }, {
  94. token : "string",
  95. regex : '"(?=.)',
  96. next : "qqstring"
  97. }, {
  98. token : "constant.numeric", // hex
  99. regex : /0[xX][0-9a-fA-F]+\b/
  100. }, {
  101. token : "constant.numeric", // float
  102. regex : /[+-]?\d+(?:(?:\.\d*)?(?:[eE][+-]?\d+)?)?\b/
  103. }, {
  104. // Sound.prototype.play =
  105. token : [
  106. "storage.type", "punctuation.operator", "support.function",
  107. "punctuation.operator", "entity.name.function", "text","keyword.operator"
  108. ],
  109. regex : "(" + identifierRe + ")(\\.)(prototype)(\\.)(" + identifierRe +")(\\s*)(=)",
  110. next: "function_arguments"
  111. }, {
  112. // Sound.play = function() { }
  113. token : [
  114. "storage.type", "punctuation.operator", "entity.name.function", "text",
  115. "keyword.operator", "text", "storage.type", "text", "paren.lparen"
  116. ],
  117. regex : "(" + identifierRe + ")(\\.)(" + identifierRe +")(\\s*)(=)(\\s*)(function)(\\s*)(\\()",
  118. next: "function_arguments"
  119. }, {
  120. // play = function() { }
  121. token : [
  122. "entity.name.function", "text", "keyword.operator", "text", "storage.type",
  123. "text", "paren.lparen"
  124. ],
  125. regex : "(" + identifierRe +")(\\s*)(=)(\\s*)(function)(\\s*)(\\()",
  126. next: "function_arguments"
  127. }, {
  128. // Sound.play = function play() { }
  129. token : [
  130. "storage.type", "punctuation.operator", "entity.name.function", "text",
  131. "keyword.operator", "text",
  132. "storage.type", "text", "entity.name.function", "text", "paren.lparen"
  133. ],
  134. regex : "(" + identifierRe + ")(\\.)(" + identifierRe +")(\\s*)(=)(\\s*)(function)(\\s+)(\\w+)(\\s*)(\\()",
  135. next: "function_arguments"
  136. }, {
  137. // function myFunc(arg) { }
  138. token : [
  139. "storage.type", "text", "entity.name.function", "text", "paren.lparen"
  140. ],
  141. regex : "(function)(\\s+)(" + identifierRe + ")(\\s*)(\\()",
  142. next: "function_arguments"
  143. }, {
  144. // foobar: function() { }
  145. token : [
  146. "entity.name.function", "text", "punctuation.operator",
  147. "text", "storage.type", "text", "paren.lparen"
  148. ],
  149. regex : "(" + identifierRe + ")(\\s*)(:)(\\s*)(function)(\\s*)(\\()",
  150. next: "function_arguments"
  151. }, {
  152. // : function() { } (this is for issues with 'foo': function() { })
  153. token : [
  154. "text", "text", "storage.type", "text", "paren.lparen"
  155. ],
  156. regex : "(:)(\\s*)(function)(\\s*)(\\()",
  157. next: "function_arguments"
  158. }, {
  159. token : "keyword",
  160. regex : "(?:" + kwBeforeRe + ")\\b",
  161. next : "start"
  162. }, {
  163. token : ["punctuation.operator", "support.function"],
  164. 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(?=\()/
  165. }, {
  166. token : ["punctuation.operator", "support.function.dom"],
  167. 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(?=\()/
  168. }, {
  169. token : ["punctuation.operator", "support.constant"],
  170. 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/
  171. }, {
  172. token : ["support.constant"],
  173. regex : /that\b/
  174. }, {
  175. token : ["storage.type", "punctuation.operator", "support.function.firebug"],
  176. regex : /(console)(\.)(warn|info|log|error|time|trace|timeEnd|assert)\b/
  177. }, {
  178. token : keywordMapper,
  179. regex : identifierRe
  180. }, {
  181. token : "keyword.operator",
  182. regex : /--|\+\+|===|==|=|!=|!==|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\|\||\?\:|[!$%&*+\-~\/^]=?/,
  183. next : "start"
  184. }, {
  185. token : "punctuation.operator",
  186. regex : /[?:,;.]/,
  187. next : "start"
  188. }, {
  189. token : "paren.lparen",
  190. regex : /[\[({]/,
  191. next : "start"
  192. }, {
  193. token : "paren.rparen",
  194. regex : /[\])}]/
  195. }, {
  196. token: "comment",
  197. regex: /^#!.*$/
  198. }
  199. ],
  200. // regular expressions are only allowed after certain tokens. This
  201. // makes sure we don't mix up regexps with the divison operator
  202. "start": [
  203. DocCommentHighlightRules.getStartRule("doc-start"),
  204. {
  205. token : "comment", // multi line comment
  206. regex : "\\/\\*",
  207. next : "comment_regex_allowed"
  208. }, {
  209. token : "comment",
  210. regex : "\\/\\/",
  211. next : "line_comment_regex_allowed"
  212. }, {
  213. token: "string.regexp",
  214. regex: "\\/",
  215. next: "regex"
  216. }, {
  217. token : "text",
  218. regex : "\\s+|^$",
  219. next : "start"
  220. }, {
  221. // immediately return to the start mode without matching
  222. // anything
  223. token: "empty",
  224. regex: "",
  225. next: "no_regex"
  226. }
  227. ],
  228. "regex": [
  229. {
  230. // escapes
  231. token: "regexp.keyword.operator",
  232. regex: "\\\\(?:u[\\da-fA-F]{4}|x[\\da-fA-F]{2}|.)"
  233. }, {
  234. // flag
  235. token: "string.regexp",
  236. regex: "/[sxngimy]*",
  237. next: "no_regex"
  238. }, {
  239. // invalid operators
  240. token : "invalid",
  241. regex: /\{\d+\b,?\d*\}[+*]|[+*$^?][+*]|[$^][?]|\?{3,}/
  242. }, {
  243. // operators
  244. token : "constant.language.escape",
  245. regex: /\(\?[:=!]|\)|\{\d+\b,?\d*\}|[+*]\?|[()$^+*?.]/
  246. }, {
  247. token : "constant.language.delimiter",
  248. regex: /\|/
  249. }, {
  250. token: "constant.language.escape",
  251. regex: /\[\^?/,
  252. next: "regex_character_class"
  253. }, {
  254. token: "empty",
  255. regex: "$",
  256. next: "no_regex"
  257. }, {
  258. defaultToken: "string.regexp"
  259. }
  260. ],
  261. "regex_character_class": [
  262. {
  263. token: "regexp.charclass.keyword.operator",
  264. regex: "\\\\(?:u[\\da-fA-F]{4}|x[\\da-fA-F]{2}|.)"
  265. }, {
  266. token: "constant.language.escape",
  267. regex: "]",
  268. next: "regex"
  269. }, {
  270. token: "constant.language.escape",
  271. regex: "-"
  272. }, {
  273. token: "empty",
  274. regex: "$",
  275. next: "no_regex"
  276. }, {
  277. defaultToken: "string.regexp.charachterclass"
  278. }
  279. ],
  280. "function_arguments": [
  281. {
  282. token: "variable.parameter",
  283. regex: identifierRe
  284. }, {
  285. token: "punctuation.operator",
  286. regex: "[, ]+"
  287. }, {
  288. token: "punctuation.operator",
  289. regex: "$"
  290. }, {
  291. token: "empty",
  292. regex: "",
  293. next: "no_regex"
  294. }
  295. ],
  296. "comment_regex_allowed" : [
  297. DocCommentHighlightRules.getTagRule(),
  298. {token : "comment", regex : "\\*\\/", next : "start"},
  299. {defaultToken : "comment", caseInsensitive: true}
  300. ],
  301. "comment" : [
  302. DocCommentHighlightRules.getTagRule(),
  303. {token : "comment", regex : "\\*\\/", next : "no_regex"},
  304. {defaultToken : "comment", caseInsensitive: true}
  305. ],
  306. "line_comment_regex_allowed" : [
  307. DocCommentHighlightRules.getTagRule(),
  308. {token : "comment", regex : "$|^", next : "start"},
  309. {defaultToken : "comment", caseInsensitive: true}
  310. ],
  311. "line_comment" : [
  312. DocCommentHighlightRules.getTagRule(),
  313. {token : "comment", regex : "$|^", next : "no_regex"},
  314. {defaultToken : "comment", caseInsensitive: true}
  315. ],
  316. "qqstring" : [
  317. {
  318. token : "constant.language.escape",
  319. regex : escapedRe
  320. }, {
  321. token : "string",
  322. regex : "\\\\$",
  323. next : "qqstring"
  324. }, {
  325. token : "string",
  326. regex : '"|$',
  327. next : "no_regex"
  328. }, {
  329. defaultToken: "string"
  330. }
  331. ],
  332. "qstring" : [
  333. {
  334. token : "constant.language.escape",
  335. regex : escapedRe
  336. }, {
  337. token : "string",
  338. regex : "\\\\$",
  339. next : "qstring"
  340. }, {
  341. token : "string",
  342. regex : "'|$",
  343. next : "no_regex"
  344. }, {
  345. defaultToken: "string"
  346. }
  347. ]
  348. };
  349. if (!options || !options.noES6) {
  350. this.$rules.no_regex.unshift({
  351. regex: "[{}]", onMatch: function(val, state, stack) {
  352. this.next = val == "{" ? this.nextState : "";
  353. if (val == "{" && stack.length) {
  354. stack.unshift("start", state);
  355. return "paren";
  356. }
  357. if (val == "}" && stack.length) {
  358. stack.shift();
  359. this.next = stack.shift();
  360. if (this.next.indexOf("string") != -1)
  361. return "paren.quasi.end";
  362. }
  363. return val == "{" ? "paren.lparen" : "paren.rparen";
  364. },
  365. nextState: "start"
  366. }, {
  367. token : "string.quasi.start",
  368. regex : /`/,
  369. push : [{
  370. token : "constant.language.escape",
  371. regex : escapedRe
  372. }, {
  373. token : "paren.quasi.start",
  374. regex : /\${/,
  375. push : "start"
  376. }, {
  377. token : "string.quasi.end",
  378. regex : /`/,
  379. next : "pop"
  380. }, {
  381. defaultToken: "string.quasi"
  382. }]
  383. });
  384. }
  385. this.embedRules(DocCommentHighlightRules, "doc-",
  386. [ DocCommentHighlightRules.getEndRule("no_regex") ]);
  387. this.normalizeRules();
  388. };
  389. oop.inherits(JavaScriptHighlightRules, TextHighlightRules);
  390. exports.JavaScriptHighlightRules = JavaScriptHighlightRules;
  391. });