PageRenderTime 38ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/files/ace/1.1.5/noconflict/mode-typescript.js

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