5a2b4fb5ab9db07fc3a8acae381d32d8.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446
  1. ace.define("ace/mode/kotlin_highlight_rules",["require","exports","module","ace/lib/oop","ace/mode/text_highlight_rules"], function(require, exports, module){"use strict";
  2. var oop = require("../lib/oop");
  3. var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
  4. var KotlinHighlightRules = function () {
  5. var keywordMapper = this.$keywords = this.createKeywordMapper({
  6. "storage.modifier.kotlin": "var|val|public|private|protected|abstract|final|enum|open|attribute|"
  7. + "annotation|override|inline|var|val|vararg|lazy|in|out|internal|data|tailrec|operator|infix|const|"
  8. + "yield|typealias|typeof|sealed|inner|value|lateinit|external|suspend|noinline|crossinline|reified|"
  9. + "expect|actual",
  10. "keyword": "companion|class|object|interface|namespace|type|fun|constructor|if|else|while|for|do|return|when|"
  11. + "where|break|continue|try|catch|finally|throw|in|is|as|assert|constructor",
  12. "constant.language.kotlin": "true|false|null|this|super",
  13. "entity.name.function.kotlin": "get|set"
  14. }, "identifier");
  15. this.$rules = {
  16. start: [{
  17. include: "#comments"
  18. }, {
  19. token: [
  20. "text",
  21. "keyword.other.kotlin",
  22. "text",
  23. "entity.name.package.kotlin",
  24. "text"
  25. ],
  26. regex: /^(\s*)(package)\b(?:(\s*)([^ ;$]+)(\s*))?/
  27. }, {
  28. token: "comment",
  29. regex: /^\s*#!.*$/
  30. }, {
  31. include: "#imports"
  32. }, {
  33. include: "#expressions"
  34. }, {
  35. token: "string",
  36. regex: /@[a-zA-Z][a-zA-Z:]*\b/
  37. }, {
  38. token: ["keyword.other.kotlin", "text", "entity.name.variable.kotlin"],
  39. regex: /\b(var|val)(\s+)([a-zA-Z_][\w]*)\b/
  40. }, {
  41. token: ["keyword.other.kotlin", "text", "entity.name.variable.kotlin", "paren.lparen"],
  42. regex: /(fun)(\s+)(\w+)(\()/,
  43. push: [{
  44. token: ["variable.parameter.function.kotlin", "text", "keyword.operator"],
  45. regex: /(\w+)(\s*)(:)/
  46. }, {
  47. token: "paren.rparen",
  48. regex: /\)/,
  49. next: "pop"
  50. }, {
  51. include: "#comments"
  52. }, {
  53. include: "#types"
  54. }, {
  55. include: "#expressions"
  56. }]
  57. }, {
  58. token: ["text", "keyword", "text", "identifier"],
  59. regex: /^(\s*)(class)(\s*)([a-zA-Z]+)/,
  60. next: "#classes"
  61. }, {
  62. token: ["identifier", "punctuaction"],
  63. regex: /([a-zA-Z_][\w]*)(<)/,
  64. push: [{
  65. include: "#generics"
  66. }, {
  67. include: "#defaultTypes"
  68. }, {
  69. token: "punctuation",
  70. regex: />/,
  71. next: "pop"
  72. }]
  73. }, {
  74. token: keywordMapper,
  75. regex: /[a-zA-Z_][\w]*\b/
  76. }, {
  77. token: "paren.lparen",
  78. regex: /[{(\[]/
  79. }, {
  80. token: "paren.rparen",
  81. regex: /[})\]]/
  82. }],
  83. "#comments": [{
  84. token: "comment",
  85. regex: /\/\*/,
  86. push: [{
  87. token: "comment",
  88. regex: /\*\//,
  89. next: "pop"
  90. }, {
  91. defaultToken: "comment"
  92. }]
  93. }, {
  94. token: [
  95. "text",
  96. "comment"
  97. ],
  98. regex: /(\s*)(\/\/.*$)/
  99. }],
  100. "#constants": [{
  101. token: "constant.numeric.kotlin",
  102. regex: /\b(?:0(?:x|X)[0-9a-fA-F]*|(?:[0-9]+\.?[0-9]*|\.[0-9]+)(?:(?:e|E)(?:\+|-)?[0-9]+)?)(?:[LlFfUuDd]|UL|ul)?\b/
  103. }, {
  104. token: "constant.other.kotlin",
  105. regex: /\b[A-Z][A-Z0-9_]+\b/
  106. }],
  107. "#expressions": [{
  108. include: "#strings"
  109. }, {
  110. include: "#constants"
  111. }, {
  112. include: "#keywords"
  113. }],
  114. "#imports": [{
  115. token: [
  116. "text",
  117. "keyword.other.kotlin",
  118. "text",
  119. "keyword.other.kotlin"
  120. ],
  121. regex: /^(\s*)(import)(\s+[^ $]+\s+)((?:as)?)/
  122. }],
  123. "#generics": [{
  124. token: "punctuation",
  125. regex: /</,
  126. push: [{
  127. token: "punctuation",
  128. regex: />/,
  129. next: "pop"
  130. }, {
  131. token: "storage.type.generic.kotlin",
  132. regex: /\w+/
  133. }, {
  134. token: "keyword.operator",
  135. regex: /:/
  136. }, {
  137. token: "punctuation",
  138. regex: /,/
  139. }, {
  140. include: "#generics"
  141. }]
  142. }],
  143. "#classes": [{
  144. include: "#generics"
  145. }, {
  146. token: "keyword",
  147. regex: /public|private|constructor/
  148. }, {
  149. token: "string",
  150. regex: /@[a-zA-Z][a-zA-Z:]*\b/
  151. }, {
  152. token: "text",
  153. regex: /(?=$|\(|{)/,
  154. next: "start"
  155. }],
  156. "#keywords": [{
  157. token: "keyword.operator.kotlin",
  158. regex: /==|!=|===|!==|<=|>=|<|>|=>|->|::|\?:/
  159. }, {
  160. token: "keyword.operator.assignment.kotlin",
  161. regex: /=/
  162. }, {
  163. token: "keyword.operator.declaration.kotlin",
  164. regex: /:/,
  165. push: [{
  166. token: "text",
  167. regex: /(?=$|{|=|,)/,
  168. next: "pop"
  169. }, {
  170. include: "#types"
  171. }]
  172. }, {
  173. token: "keyword.operator.dot.kotlin",
  174. regex: /\./
  175. }, {
  176. token: "keyword.operator.increment-decrement.kotlin",
  177. regex: /\-\-|\+\+/
  178. }, {
  179. token: "keyword.operator.arithmetic.kotlin",
  180. regex: /\-|\+|\*|\/|%/
  181. }, {
  182. token: "keyword.operator.arithmetic.assign.kotlin",
  183. regex: /\+=|\-=|\*=|\/=/
  184. }, {
  185. token: "keyword.operator.logical.kotlin",
  186. regex: /!|&&|\|\|/
  187. }, {
  188. token: "keyword.operator.range.kotlin",
  189. regex: /\.\./
  190. }, {
  191. token: "punctuation.kotlin",
  192. regex: /[;,]/
  193. }],
  194. "#types": [{
  195. include: "#defaultTypes"
  196. }, {
  197. token: "paren.lparen",
  198. regex: /\(/,
  199. push: [{
  200. token: "paren.rparen",
  201. regex: /\)/,
  202. next: "pop"
  203. }, {
  204. include: "#defaultTypes"
  205. }, {
  206. token: "punctuation",
  207. regex: /,/
  208. }]
  209. }, {
  210. include: "#generics"
  211. }, {
  212. token: "keyword.operator.declaration.kotlin",
  213. regex: /->/
  214. }, {
  215. token: "paren.rparen",
  216. regex: /\)/
  217. }, {
  218. token: "keyword.operator.declaration.kotlin",
  219. regex: /:/,
  220. push: [{
  221. token: "text",
  222. regex: /(?=$|{|=|,)/,
  223. next: "pop"
  224. }, {
  225. include: "#types"
  226. }]
  227. }],
  228. "#defaultTypes": [{
  229. token: "storage.type.buildin.kotlin",
  230. regex: /\b(Any|Unit|String|Int|Boolean|Char|Long|Double|Float|Short|Byte|dynamic|IntArray|BooleanArray|CharArray|LongArray|DoubleArray|FloatArray|ShortArray|ByteArray|Array|List|Map|Nothing|Enum|Throwable|Comparable)\b/
  231. }],
  232. "#strings": [{
  233. token: "string",
  234. regex: /"""/,
  235. push: [{
  236. token: "string",
  237. regex: /"""/,
  238. next: "pop"
  239. }, {
  240. token: "variable.parameter.template.kotlin",
  241. regex: /\$\w+|\${[^}]+}/
  242. }, {
  243. token: "constant.character.escape.kotlin",
  244. regex: /\\./
  245. }, {
  246. defaultToken: "string"
  247. }]
  248. }, {
  249. token: "string",
  250. regex: /"/,
  251. push: [{
  252. token: "string",
  253. regex: /"/,
  254. next: "pop"
  255. }, {
  256. token: "variable.parameter.template.kotlin",
  257. regex: /\$\w+|\$\{[^\}]+\}/
  258. }, {
  259. token: "constant.character.escape.kotlin",
  260. regex: /\\./
  261. }, {
  262. defaultToken: "string"
  263. }]
  264. }, {
  265. token: "string",
  266. regex: /'/,
  267. push: [{
  268. token: "string",
  269. regex: /'/,
  270. next: "pop"
  271. }, {
  272. token: "constant.character.escape.kotlin",
  273. regex: /\\./
  274. }, {
  275. defaultToken: "string"
  276. }]
  277. }, {
  278. token: "string",
  279. regex: /`/,
  280. push: [{
  281. token: "string",
  282. regex: /`/,
  283. next: "pop"
  284. }, {
  285. defaultToken: "string"
  286. }]
  287. }]
  288. };
  289. this.normalizeRules();
  290. };
  291. KotlinHighlightRules.metaData = {
  292. fileTypes: ["kt", "kts"],
  293. name: "Kotlin",
  294. scopeName: "source.Kotlin"
  295. };
  296. oop.inherits(KotlinHighlightRules, TextHighlightRules);
  297. exports.KotlinHighlightRules = KotlinHighlightRules;
  298. });
  299. ace.define("ace/mode/folding/cstyle",["require","exports","module","ace/lib/oop","ace/range","ace/mode/folding/fold_mode"], function(require, exports, module){"use strict";
  300. var oop = require("../../lib/oop");
  301. var Range = require("../../range").Range;
  302. var BaseFoldMode = require("./fold_mode").FoldMode;
  303. var FoldMode = exports.FoldMode = function (commentRegex) {
  304. if (commentRegex) {
  305. this.foldingStartMarker = new RegExp(this.foldingStartMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.start));
  306. this.foldingStopMarker = new RegExp(this.foldingStopMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.end));
  307. }
  308. };
  309. oop.inherits(FoldMode, BaseFoldMode);
  310. (function () {
  311. this.foldingStartMarker = /([\{\[\(])[^\}\]\)]*$|^\s*(\/\*)/;
  312. this.foldingStopMarker = /^[^\[\{\(]*([\}\]\)])|^[\s\*]*(\*\/)/;
  313. this.singleLineBlockCommentRe = /^\s*(\/\*).*\*\/\s*$/;
  314. this.tripleStarBlockCommentRe = /^\s*(\/\*\*\*).*\*\/\s*$/;
  315. this.startRegionRe = /^\s*(\/\*|\/\/)#?region\b/;
  316. this._getFoldWidgetBase = this.getFoldWidget;
  317. this.getFoldWidget = function (session, foldStyle, row) {
  318. var line = session.getLine(row);
  319. if (this.singleLineBlockCommentRe.test(line)) {
  320. if (!this.startRegionRe.test(line) && !this.tripleStarBlockCommentRe.test(line))
  321. return "";
  322. }
  323. var fw = this._getFoldWidgetBase(session, foldStyle, row);
  324. if (!fw && this.startRegionRe.test(line))
  325. return "start"; // lineCommentRegionStart
  326. return fw;
  327. };
  328. this.getFoldWidgetRange = function (session, foldStyle, row, forceMultiline) {
  329. var line = session.getLine(row);
  330. if (this.startRegionRe.test(line))
  331. return this.getCommentRegionBlock(session, line, row);
  332. var match = line.match(this.foldingStartMarker);
  333. if (match) {
  334. var i = match.index;
  335. if (match[1])
  336. return this.openingBracketBlock(session, match[1], row, i);
  337. var range = session.getCommentFoldRange(row, i + match[0].length, 1);
  338. if (range && !range.isMultiLine()) {
  339. if (forceMultiline) {
  340. range = this.getSectionRange(session, row);
  341. }
  342. else if (foldStyle != "all")
  343. range = null;
  344. }
  345. return range;
  346. }
  347. if (foldStyle === "markbegin")
  348. return;
  349. var match = line.match(this.foldingStopMarker);
  350. if (match) {
  351. var i = match.index + match[0].length;
  352. if (match[1])
  353. return this.closingBracketBlock(session, match[1], row, i);
  354. return session.getCommentFoldRange(row, i, -1);
  355. }
  356. };
  357. this.getSectionRange = function (session, row) {
  358. var line = session.getLine(row);
  359. var startIndent = line.search(/\S/);
  360. var startRow = row;
  361. var startColumn = line.length;
  362. row = row + 1;
  363. var endRow = row;
  364. var maxRow = session.getLength();
  365. while (++row < maxRow) {
  366. line = session.getLine(row);
  367. var indent = line.search(/\S/);
  368. if (indent === -1)
  369. continue;
  370. if (startIndent > indent)
  371. break;
  372. var subRange = this.getFoldWidgetRange(session, "all", row);
  373. if (subRange) {
  374. if (subRange.start.row <= startRow) {
  375. break;
  376. }
  377. else if (subRange.isMultiLine()) {
  378. row = subRange.end.row;
  379. }
  380. else if (startIndent == indent) {
  381. break;
  382. }
  383. }
  384. endRow = row;
  385. }
  386. return new Range(startRow, startColumn, endRow, session.getLine(endRow).length);
  387. };
  388. this.getCommentRegionBlock = function (session, line, row) {
  389. var startColumn = line.search(/\s*$/);
  390. var maxRow = session.getLength();
  391. var startRow = row;
  392. var re = /^\s*(?:\/\*|\/\/|--)#?(end)?region\b/;
  393. var depth = 1;
  394. while (++row < maxRow) {
  395. line = session.getLine(row);
  396. var m = re.exec(line);
  397. if (!m)
  398. continue;
  399. if (m[1])
  400. depth--;
  401. else
  402. depth++;
  403. if (!depth)
  404. break;
  405. }
  406. var endRow = row;
  407. if (endRow > startRow) {
  408. return new Range(startRow, startColumn, endRow, line.length);
  409. }
  410. };
  411. }).call(FoldMode.prototype);
  412. });
  413. ace.define("ace/mode/kotlin",["require","exports","module","ace/lib/oop","ace/mode/text","ace/mode/kotlin_highlight_rules","ace/mode/behaviour/cstyle","ace/mode/folding/cstyle"], function(require, exports, module){/*
  414. THIS FILE WAS AUTOGENERATED BY mode.tmpl.js
  415. */
  416. "use strict";
  417. var oop = require("../lib/oop");
  418. var TextMode = require("./text").Mode;
  419. var KotlinHighlightRules = require("./kotlin_highlight_rules").KotlinHighlightRules;
  420. var CstyleBehaviour = require("./behaviour/cstyle").CstyleBehaviour;
  421. var FoldMode = require("./folding/cstyle").FoldMode;
  422. var Mode = function () {
  423. this.HighlightRules = KotlinHighlightRules;
  424. this.foldingRules = new FoldMode();
  425. this.$behaviour = new CstyleBehaviour();
  426. };
  427. oop.inherits(Mode, TextMode);
  428. (function () {
  429. this.lineCommentStart = "//";
  430. this.blockComment = { start: "/*", end: "*/" };
  431. this.$id = "ace/mode/kotlin";
  432. }).call(Mode.prototype);
  433. exports.Mode = Mode;
  434. }); (function() {
  435. ace.require(["ace/mode/kotlin"], function(m) {
  436. if (typeof module == "object" && typeof exports == "object" && module) {
  437. module.exports = m;
  438. }
  439. });
  440. })();