kotlin.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. /*!-----------------------------------------------------------------------------
  2. * Copyright (c) Microsoft Corporation. All rights reserved.
  3. * Version: 0.31.1(337587859b1c171314b40503171188b6cea6a32a)
  4. * Released under the MIT license
  5. * https://github.com/microsoft/monaco-editor/blob/main/LICENSE.txt
  6. *-----------------------------------------------------------------------------*/
  7. // src/basic-languages/kotlin/kotlin.ts
  8. var conf = {
  9. wordPattern: /(-?\d*\.\d\w*)|([^\`\~\!\#\%\^\&\*\(\)\-\=\+\[\{\]\}\\\|\;\:\'\"\,\.\<\>\/\?\s]+)/g,
  10. comments: {
  11. lineComment: "//",
  12. blockComment: ["/*", "*/"]
  13. },
  14. brackets: [
  15. ["{", "}"],
  16. ["[", "]"],
  17. ["(", ")"]
  18. ],
  19. autoClosingPairs: [
  20. { open: "{", close: "}" },
  21. { open: "[", close: "]" },
  22. { open: "(", close: ")" },
  23. { open: '"', close: '"' },
  24. { open: "'", close: "'" }
  25. ],
  26. surroundingPairs: [
  27. { open: "{", close: "}" },
  28. { open: "[", close: "]" },
  29. { open: "(", close: ")" },
  30. { open: '"', close: '"' },
  31. { open: "'", close: "'" },
  32. { open: "<", close: ">" }
  33. ],
  34. folding: {
  35. markers: {
  36. start: new RegExp("^\\s*//\\s*(?:(?:#?region\\b)|(?:<editor-fold\\b))"),
  37. end: new RegExp("^\\s*//\\s*(?:(?:#?endregion\\b)|(?:</editor-fold>))")
  38. }
  39. }
  40. };
  41. var language = {
  42. defaultToken: "",
  43. tokenPostfix: ".kt",
  44. keywords: [
  45. "as",
  46. "as?",
  47. "break",
  48. "class",
  49. "continue",
  50. "do",
  51. "else",
  52. "false",
  53. "for",
  54. "fun",
  55. "if",
  56. "in",
  57. "!in",
  58. "interface",
  59. "is",
  60. "!is",
  61. "null",
  62. "object",
  63. "package",
  64. "return",
  65. "super",
  66. "this",
  67. "throw",
  68. "true",
  69. "try",
  70. "typealias",
  71. "val",
  72. "var",
  73. "when",
  74. "while",
  75. "by",
  76. "catch",
  77. "constructor",
  78. "delegate",
  79. "dynamic",
  80. "field",
  81. "file",
  82. "finally",
  83. "get",
  84. "import",
  85. "init",
  86. "param",
  87. "property",
  88. "receiver",
  89. "set",
  90. "setparam",
  91. "where",
  92. "actual",
  93. "abstract",
  94. "annotation",
  95. "companion",
  96. "const",
  97. "crossinline",
  98. "data",
  99. "enum",
  100. "expect",
  101. "external",
  102. "final",
  103. "infix",
  104. "inline",
  105. "inner",
  106. "internal",
  107. "lateinit",
  108. "noinline",
  109. "open",
  110. "operator",
  111. "out",
  112. "override",
  113. "private",
  114. "protected",
  115. "public",
  116. "reified",
  117. "sealed",
  118. "suspend",
  119. "tailrec",
  120. "vararg",
  121. "field",
  122. "it"
  123. ],
  124. operators: [
  125. "+",
  126. "-",
  127. "*",
  128. "/",
  129. "%",
  130. "=",
  131. "+=",
  132. "-=",
  133. "*=",
  134. "/=",
  135. "%=",
  136. "++",
  137. "--",
  138. "&&",
  139. "||",
  140. "!",
  141. "==",
  142. "!=",
  143. "===",
  144. "!==",
  145. ">",
  146. "<",
  147. "<=",
  148. ">=",
  149. "[",
  150. "]",
  151. "!!",
  152. "?.",
  153. "?:",
  154. "::",
  155. "..",
  156. ":",
  157. "?",
  158. "->",
  159. "@",
  160. ";",
  161. "$",
  162. "_"
  163. ],
  164. symbols: /[=><!~?:&|+\-*\/\^%]+/,
  165. escapes: /\\(?:[abfnrtv\\"']|x[0-9A-Fa-f]{1,4}|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})/,
  166. digits: /\d+(_+\d+)*/,
  167. octaldigits: /[0-7]+(_+[0-7]+)*/,
  168. binarydigits: /[0-1]+(_+[0-1]+)*/,
  169. hexdigits: /[[0-9a-fA-F]+(_+[0-9a-fA-F]+)*/,
  170. tokenizer: {
  171. root: [
  172. [/[A-Z][\w\$]*/, "type.identifier"],
  173. [
  174. /[a-zA-Z_$][\w$]*/,
  175. {
  176. cases: {
  177. "@keywords": { token: "keyword.$0" },
  178. "@default": "identifier"
  179. }
  180. }
  181. ],
  182. { include: "@whitespace" },
  183. [/[{}()\[\]]/, "@brackets"],
  184. [/[<>](?!@symbols)/, "@brackets"],
  185. [
  186. /@symbols/,
  187. {
  188. cases: {
  189. "@operators": "delimiter",
  190. "@default": ""
  191. }
  192. }
  193. ],
  194. [/@\s*[a-zA-Z_\$][\w\$]*/, "annotation"],
  195. [/(@digits)[eE]([\-+]?(@digits))?[fFdD]?/, "number.float"],
  196. [/(@digits)\.(@digits)([eE][\-+]?(@digits))?[fFdD]?/, "number.float"],
  197. [/0[xX](@hexdigits)[Ll]?/, "number.hex"],
  198. [/0(@octaldigits)[Ll]?/, "number.octal"],
  199. [/0[bB](@binarydigits)[Ll]?/, "number.binary"],
  200. [/(@digits)[fFdD]/, "number.float"],
  201. [/(@digits)[lL]?/, "number"],
  202. [/[;,.]/, "delimiter"],
  203. [/"([^"\\]|\\.)*$/, "string.invalid"],
  204. [/"""/, "string", "@multistring"],
  205. [/"/, "string", "@string"],
  206. [/'[^\\']'/, "string"],
  207. [/(')(@escapes)(')/, ["string", "string.escape", "string"]],
  208. [/'/, "string.invalid"]
  209. ],
  210. whitespace: [
  211. [/[ \t\r\n]+/, ""],
  212. [/\/\*\*(?!\/)/, "comment.doc", "@javadoc"],
  213. [/\/\*/, "comment", "@comment"],
  214. [/\/\/.*$/, "comment"]
  215. ],
  216. comment: [
  217. [/[^\/*]+/, "comment"],
  218. [/\/\*/, "comment", "@comment"],
  219. [/\*\//, "comment", "@pop"],
  220. [/[\/*]/, "comment"]
  221. ],
  222. javadoc: [
  223. [/[^\/*]+/, "comment.doc"],
  224. [/\/\*/, "comment.doc", "@push"],
  225. [/\/\*/, "comment.doc.invalid"],
  226. [/\*\//, "comment.doc", "@pop"],
  227. [/[\/*]/, "comment.doc"]
  228. ],
  229. string: [
  230. [/[^\\"]+/, "string"],
  231. [/@escapes/, "string.escape"],
  232. [/\\./, "string.escape.invalid"],
  233. [/"/, "string", "@pop"]
  234. ],
  235. multistring: [
  236. [/[^\\"]+/, "string"],
  237. [/@escapes/, "string.escape"],
  238. [/\\./, "string.escape.invalid"],
  239. [/"""/, "string", "@pop"],
  240. [/./, "string"]
  241. ]
  242. }
  243. };
  244. export {
  245. conf,
  246. language
  247. };