kotlin.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /*---------------------------------------------------------------------------------------------
  2. * Copyright (c) Microsoft Corporation. All rights reserved.
  3. * Licensed under the MIT License. See License.txt in the project root for license information.
  4. *--------------------------------------------------------------------------------------------*/
  5. define(["require", "exports"], function (require, exports) {
  6. 'use strict';
  7. Object.defineProperty(exports, "__esModule", { value: true });
  8. exports.conf = {
  9. // the default separators except `@$`
  10. wordPattern: /(-?\d*\.\d\w*)|([^\`\~\!\#\%\^\&\*\(\)\-\=\+\[\{\]\}\\\|\;\:\'\"\,\.\<\>\/\?\s]+)/g,
  11. comments: {
  12. lineComment: '//',
  13. blockComment: ['/*', '*/'],
  14. },
  15. brackets: [
  16. ['{', '}'],
  17. ['[', ']'],
  18. ['(', ')'],
  19. ],
  20. autoClosingPairs: [
  21. { open: '{', close: '}' },
  22. { open: '[', close: ']' },
  23. { open: '(', close: ')' },
  24. { open: '"', close: '"' },
  25. { open: '\'', close: '\'' },
  26. ],
  27. surroundingPairs: [
  28. { open: '{', close: '}' },
  29. { open: '[', close: ']' },
  30. { open: '(', close: ')' },
  31. { open: '"', close: '"' },
  32. { open: '\'', close: '\'' },
  33. { open: '<', close: '>' },
  34. ],
  35. folding: {
  36. markers: {
  37. start: new RegExp("^\\s*//\\s*(?:(?:#?region\\b)|(?:<editor-fold\\b))"),
  38. end: new RegExp("^\\s*//\\s*(?:(?:#?endregion\\b)|(?:</editor-fold>))")
  39. }
  40. }
  41. };
  42. exports.language = {
  43. defaultToken: '',
  44. tokenPostfix: '.kt',
  45. keywords: [
  46. 'as', 'as?', 'break', 'class', 'continue', 'do', 'else', 'false', 'for', 'fun', 'if',
  47. 'in', '!in', 'interface', 'is', '!is', 'null', 'object', 'package', 'return', 'super',
  48. 'this', 'throw', 'true', 'try', 'typealias', 'val', 'var', 'when', 'while', 'by',
  49. 'catch', 'constructor', 'delegate', 'dynamic', 'field', 'file', 'finally', 'get',
  50. 'import', 'init', 'param', 'property', 'receiver', 'set', 'setparam', 'where', 'actual',
  51. 'abstract', 'annotation', 'companion', 'const', 'crossinline', 'data', 'enum', 'expect',
  52. 'external', 'final', 'infix', 'inline', 'inner', 'internal', 'lateinit', 'noinline',
  53. 'open', 'operator', 'out', 'override', 'private', 'protected', 'public', 'reified',
  54. 'sealed', 'suspend', 'tailrec', 'vararg', 'field', 'it'
  55. ],
  56. operators: [
  57. '+', '-', '*', '/', '%', '=', '+=', '-=', '*=', '/=',
  58. '%=', '++', '--', '&&', '||', '!', '==', '!=', '===',
  59. '!==', '>', '<', '<=', '>=', '[', ']', '!!', '?.', '?:',
  60. '::', '..', ':', '?', '->', '@', ';', '$', '_'
  61. ],
  62. // we include these common regular expressions
  63. symbols: /[=><!~?:&|+\-*\/\^%]+/,
  64. escapes: /\\(?:[abfnrtv\\"']|x[0-9A-Fa-f]{1,4}|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})/,
  65. digits: /\d+(_+\d+)*/,
  66. octaldigits: /[0-7]+(_+[0-7]+)*/,
  67. binarydigits: /[0-1]+(_+[0-1]+)*/,
  68. hexdigits: /[[0-9a-fA-F]+(_+[0-9a-fA-F]+)*/,
  69. // The main tokenizer for our languages
  70. tokenizer: {
  71. root: [
  72. // class name highlighting
  73. [/[A-Z][\w\$]*/, 'type.identifier'],
  74. // identifiers and keywords
  75. [/[a-zA-Z_$][\w$]*/, {
  76. cases: {
  77. '@keywords': { token: 'keyword.$0' },
  78. '@default': 'identifier'
  79. }
  80. }],
  81. // whitespace
  82. { include: '@whitespace' },
  83. // delimiters and operators
  84. [/[{}()\[\]]/, '@brackets'],
  85. [/[<>](?!@symbols)/, '@brackets'],
  86. [/@symbols/, {
  87. cases: {
  88. '@operators': 'delimiter',
  89. '@default': ''
  90. }
  91. }],
  92. // @ annotations.
  93. [/@\s*[a-zA-Z_\$][\w\$]*/, 'annotation'],
  94. // numbers
  95. [/(@digits)[eE]([\-+]?(@digits))?[fFdD]?/, 'number.float'],
  96. [/(@digits)\.(@digits)([eE][\-+]?(@digits))?[fFdD]?/, 'number.float'],
  97. [/0[xX](@hexdigits)[Ll]?/, 'number.hex'],
  98. [/0(@octaldigits)[Ll]?/, 'number.octal'],
  99. [/0[bB](@binarydigits)[Ll]?/, 'number.binary'],
  100. [/(@digits)[fFdD]/, 'number.float'],
  101. [/(@digits)[lL]?/, 'number'],
  102. // delimiter: after number because of .\d floats
  103. [/[;,.]/, 'delimiter'],
  104. // strings
  105. [/"([^"\\]|\\.)*$/, 'string.invalid'],
  106. [/"""/, 'string', '@multistring'],
  107. [/"/, 'string', '@string'],
  108. // characters
  109. [/'[^\\']'/, 'string'],
  110. [/(')(@escapes)(')/, ['string', 'string.escape', 'string']],
  111. [/'/, 'string.invalid']
  112. ],
  113. whitespace: [
  114. [/[ \t\r\n]+/, ''],
  115. [/\/\*\*(?!\/)/, 'comment.doc', '@javadoc'],
  116. [/\/\*/, 'comment', '@comment'],
  117. [/\/\/.*$/, 'comment'],
  118. ],
  119. comment: [
  120. [/[^\/*]+/, 'comment'],
  121. [/\/\*/, 'comment', '@comment'],
  122. [/\*\//, 'comment', '@pop'],
  123. [/[\/*]/, 'comment']
  124. ],
  125. //Identical copy of comment above, except for the addition of .doc
  126. javadoc: [
  127. [/[^\/*]+/, 'comment.doc'],
  128. [/\/\*/, 'comment.doc', '@push'],
  129. [/\/\*/, 'comment.doc.invalid'],
  130. [/\*\//, 'comment.doc', '@pop'],
  131. [/[\/*]/, 'comment.doc']
  132. ],
  133. string: [
  134. [/[^\\"]+/, 'string'],
  135. [/@escapes/, 'string.escape'],
  136. [/\\./, 'string.escape.invalid'],
  137. [/"/, 'string', '@pop']
  138. ],
  139. multistring: [
  140. [/[^\\"]+/, 'string'],
  141. [/@escapes/, 'string.escape'],
  142. [/\\./, 'string.escape.invalid'],
  143. [/"""/, 'string', '@pop'],
  144. [/./, 'string']
  145. ],
  146. },
  147. };
  148. });