scala.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  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('vs/basic-languages/scala/scala',["require", "exports"], function (require, exports) {
  6. "use strict";
  7. Object.defineProperty(exports, "__esModule", { value: true });
  8. exports.language = exports.conf = void 0;
  9. exports.conf = {
  10. /*
  11. * `...` is allowed as an identifier.
  12. * $ is allowed in identifiers.
  13. * unary_<op> is allowed as an identifier.
  14. * <name>_= is allowed as an identifier.
  15. */
  16. wordPattern: /(unary_[@~!#%^&*()\-=+\\|:<>\/?]+)|([a-zA-Z_$][\w$]*?_=)|(`[^`]+`)|([a-zA-Z_$][\w$]*)/g,
  17. comments: {
  18. lineComment: '//',
  19. blockComment: ['/*', '*/']
  20. },
  21. brackets: [
  22. ['{', '}'],
  23. ['[', ']'],
  24. ['(', ')']
  25. ],
  26. autoClosingPairs: [
  27. { open: '{', close: '}' },
  28. { open: '[', close: ']' },
  29. { open: '(', close: ')' },
  30. { open: '"', close: '"' },
  31. { open: "'", close: "'" }
  32. ],
  33. surroundingPairs: [
  34. { open: '{', close: '}' },
  35. { open: '[', close: ']' },
  36. { open: '(', close: ')' },
  37. { open: '"', close: '"' },
  38. { open: "'", close: "'" }
  39. ],
  40. folding: {
  41. markers: {
  42. start: new RegExp('^\\s*//\\s*(?:(?:#?region\\b)|(?:<editor-fold\\b))'),
  43. end: new RegExp('^\\s*//\\s*(?:(?:#?endregion\\b)|(?:</editor-fold>))')
  44. }
  45. }
  46. };
  47. exports.language = {
  48. tokenPostfix: '.scala',
  49. // We can't easily add everything from Dotty, but we can at least add some of its keywords
  50. keywords: [
  51. 'asInstanceOf',
  52. 'catch',
  53. 'class',
  54. 'classOf',
  55. 'def',
  56. 'do',
  57. 'else',
  58. 'extends',
  59. 'finally',
  60. 'for',
  61. 'foreach',
  62. 'forSome',
  63. 'if',
  64. 'import',
  65. 'isInstanceOf',
  66. 'macro',
  67. 'match',
  68. 'new',
  69. 'object',
  70. 'package',
  71. 'return',
  72. 'throw',
  73. 'trait',
  74. 'try',
  75. 'type',
  76. 'until',
  77. 'val',
  78. 'var',
  79. 'while',
  80. 'with',
  81. 'yield',
  82. // Dotty-specific:
  83. 'given',
  84. 'enum',
  85. 'then'
  86. ],
  87. // Dotty-specific:
  88. softKeywords: ['as', 'export', 'extension', 'end', 'derives', 'on'],
  89. constants: ['true', 'false', 'null', 'this', 'super'],
  90. modifiers: [
  91. 'abstract',
  92. 'final',
  93. 'implicit',
  94. 'lazy',
  95. 'override',
  96. 'private',
  97. 'protected',
  98. 'sealed'
  99. ],
  100. // Dotty-specific:
  101. softModifiers: ['inline', 'opaque', 'open', 'transparent', 'using'],
  102. name: /(?:[a-z_$][\w$]*|`[^`]+`)/,
  103. type: /(?:[A-Z][\w$]*)/,
  104. // we include these common regular expressions
  105. symbols: /[=><!~?:&|+\-*\/^\\%@#]+/,
  106. digits: /\d+(_+\d+)*/,
  107. hexdigits: /[[0-9a-fA-F]+(_+[0-9a-fA-F]+)*/,
  108. // C# style strings
  109. escapes: /\\(?:[btnfr\\"']|x[0-9A-Fa-f]{1,4}|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})/,
  110. fstring_conv: /[bBhHsScCdoxXeEfgGaAt]|[Tn](?:[HIklMSLNpzZsQ]|[BbhAaCYyjmde]|[RTrDFC])/,
  111. // The main tokenizer for our languages
  112. tokenizer: {
  113. root: [
  114. // strings
  115. [/\braw"""/, { token: 'string.quote', bracket: '@open', next: '@rawstringt' }],
  116. [/\braw"/, { token: 'string.quote', bracket: '@open', next: '@rawstring' }],
  117. [/\bs"""/, { token: 'string.quote', bracket: '@open', next: '@sstringt' }],
  118. [/\bs"/, { token: 'string.quote', bracket: '@open', next: '@sstring' }],
  119. [/\bf""""/, { token: 'string.quote', bracket: '@open', next: '@fstringt' }],
  120. [/\bf"/, { token: 'string.quote', bracket: '@open', next: '@fstring' }],
  121. [/"""/, { token: 'string.quote', bracket: '@open', next: '@stringt' }],
  122. [/"/, { token: 'string.quote', bracket: '@open', next: '@string' }],
  123. // numbers
  124. [/(@digits)[eE]([\-+]?(@digits))?[fFdD]?/, 'number.float', '@allowMethod'],
  125. [/(@digits)\.(@digits)([eE][\-+]?(@digits))?[fFdD]?/, 'number.float', '@allowMethod'],
  126. [/0[xX](@hexdigits)[Ll]?/, 'number.hex', '@allowMethod'],
  127. [/(@digits)[fFdD]/, 'number.float', '@allowMethod'],
  128. [/(@digits)[lL]?/, 'number', '@allowMethod'],
  129. [/\b_\*/, 'key'],
  130. [/\b(_)\b/, 'keyword', '@allowMethod'],
  131. // identifiers and keywords
  132. [/\bimport\b/, 'keyword', '@import'],
  133. [/\b(case)([ \t]+)(class)\b/, ['keyword.modifier', 'white', 'keyword']],
  134. [/\bcase\b/, 'keyword', '@case'],
  135. [/\bva[lr]\b/, 'keyword', '@vardef'],
  136. [
  137. /\b(def)([ \t]+)((?:unary_)?@symbols|@name(?:_=)|@name)/,
  138. ['keyword', 'white', 'identifier']
  139. ],
  140. [/@name(?=[ \t]*:(?!:))/, 'variable'],
  141. [/(\.)(@name|@symbols)/, ['operator', { token: '@rematch', next: '@allowMethod' }]],
  142. [/([{(])(\s*)(@name(?=\s*=>))/, ['@brackets', 'white', 'variable']],
  143. [
  144. /@name/,
  145. {
  146. cases: {
  147. '@keywords': 'keyword',
  148. '@softKeywords': 'keyword',
  149. '@modifiers': 'keyword.modifier',
  150. '@softModifiers': 'keyword.modifier',
  151. '@constants': {
  152. token: 'constant',
  153. next: '@allowMethod'
  154. },
  155. '@default': {
  156. token: 'identifier',
  157. next: '@allowMethod'
  158. }
  159. }
  160. }
  161. ],
  162. [/@type/, 'type', '@allowMethod'],
  163. // whitespace
  164. { include: '@whitespace' },
  165. // @ annotations.
  166. [/@[a-zA-Z_$][\w$]*(?:\.[a-zA-Z_$][\w$]*)*/, 'annotation'],
  167. // delimiters and operators
  168. [/[{(]/, '@brackets'],
  169. [/[})]/, '@brackets', '@allowMethod'],
  170. [/\[/, 'operator.square'],
  171. [/](?!\s*(?:va[rl]|def|type)\b)/, 'operator.square', '@allowMethod'],
  172. [/]/, 'operator.square'],
  173. [/([=-]>|<-|>:|<:|:>|<%)(?=[\s\w()[\]{},\."'`])/, 'keyword'],
  174. [/@symbols/, 'operator'],
  175. // delimiter: after number because of .\d floats
  176. [/[;,\.]/, 'delimiter'],
  177. // symbols
  178. [/'[a-zA-Z$][\w$]*(?!')/, 'attribute.name'],
  179. // characters
  180. [/'[^\\']'/, 'string', '@allowMethod'],
  181. [
  182. /(')(@escapes)(')/,
  183. ['string', 'string.escape', { token: 'string', next: '@allowMethod' }]
  184. ],
  185. [/'/, 'string.invalid']
  186. ],
  187. import: [
  188. [/;/, 'delimiter', '@pop'],
  189. [/^|$/, '', '@pop'],
  190. [/[ \t]+/, 'white'],
  191. [/[\n\r]+/, 'white', '@pop'],
  192. [/\/\*/, 'comment', '@comment'],
  193. [/@name|@type/, 'type'],
  194. [/[(){}]/, '@brackets'],
  195. [/[[\]]/, 'operator.square'],
  196. [/[\.,]/, 'delimiter']
  197. ],
  198. allowMethod: [
  199. [/^|$/, '', '@pop'],
  200. [/[ \t]+/, 'white'],
  201. [/[\n\r]+/, 'white', '@pop'],
  202. [/\/\*/, 'comment', '@comment'],
  203. [/(?==>[\s\w([{])/, 'keyword', '@pop'],
  204. [
  205. /(@name|@symbols)(?=[ \t]*[[({"'`]|[ \t]+(?:[+-]?\.?\d|\w))/,
  206. {
  207. cases: {
  208. '@keywords': { token: 'keyword', next: '@pop' },
  209. '->|<-|>:|<:|<%': { token: 'keyword', next: '@pop' },
  210. '@default': { token: '@rematch', next: '@pop' }
  211. }
  212. }
  213. ],
  214. ['', '', '@pop']
  215. ],
  216. comment: [
  217. [/[^\/*]+/, 'comment'],
  218. [/\/\*/, 'comment', '@push'],
  219. [/\*\//, 'comment', '@pop'],
  220. [/[\/*]/, 'comment']
  221. ],
  222. case: [
  223. [/\b_\*/, 'key'],
  224. [/\b(_|true|false|null|this|super)\b/, 'keyword', '@allowMethod'],
  225. [/\bif\b|=>/, 'keyword', '@pop'],
  226. [/`[^`]+`/, 'identifier', '@allowMethod'],
  227. [/@name/, 'variable', '@allowMethod'],
  228. [/:::?|\||@(?![a-z_$])/, 'keyword'],
  229. { include: '@root' }
  230. ],
  231. vardef: [
  232. [/\b_\*/, 'key'],
  233. [/\b(_|true|false|null|this|super)\b/, 'keyword'],
  234. [/@name/, 'variable'],
  235. [/:::?|\||@(?![a-z_$])/, 'keyword'],
  236. [/=|:(?!:)/, 'operator', '@pop'],
  237. [/$/, 'white', '@pop'],
  238. { include: '@root' }
  239. ],
  240. string: [
  241. [/[^\\"\n\r]+/, 'string'],
  242. [/@escapes/, 'string.escape'],
  243. [/\\./, 'string.escape.invalid'],
  244. [
  245. /"/,
  246. {
  247. token: 'string.quote',
  248. bracket: '@close',
  249. switchTo: '@allowMethod'
  250. }
  251. ]
  252. ],
  253. stringt: [
  254. [/[^\\"\n\r]+/, 'string'],
  255. [/@escapes/, 'string.escape'],
  256. [/\\./, 'string.escape.invalid'],
  257. [/"(?=""")/, 'string'],
  258. [
  259. /"""/,
  260. {
  261. token: 'string.quote',
  262. bracket: '@close',
  263. switchTo: '@allowMethod'
  264. }
  265. ],
  266. [/"/, 'string']
  267. ],
  268. fstring: [
  269. [/@escapes/, 'string.escape'],
  270. [
  271. /"/,
  272. {
  273. token: 'string.quote',
  274. bracket: '@close',
  275. switchTo: '@allowMethod'
  276. }
  277. ],
  278. [/\$\$/, 'string'],
  279. [/(\$)([a-z_]\w*)/, ['operator', 'identifier']],
  280. [/\$\{/, 'operator', '@interp'],
  281. [/%%/, 'string'],
  282. [
  283. /(%)([\-#+ 0,(])(\d+|\.\d+|\d+\.\d+)(@fstring_conv)/,
  284. ['metatag', 'keyword.modifier', 'number', 'metatag']
  285. ],
  286. [/(%)(\d+|\.\d+|\d+\.\d+)(@fstring_conv)/, ['metatag', 'number', 'metatag']],
  287. [/(%)([\-#+ 0,(])(@fstring_conv)/, ['metatag', 'keyword.modifier', 'metatag']],
  288. [/(%)(@fstring_conv)/, ['metatag', 'metatag']],
  289. [/./, 'string']
  290. ],
  291. fstringt: [
  292. [/@escapes/, 'string.escape'],
  293. [/"(?=""")/, 'string'],
  294. [
  295. /"""/,
  296. {
  297. token: 'string.quote',
  298. bracket: '@close',
  299. switchTo: '@allowMethod'
  300. }
  301. ],
  302. [/\$\$/, 'string'],
  303. [/(\$)([a-z_]\w*)/, ['operator', 'identifier']],
  304. [/\$\{/, 'operator', '@interp'],
  305. [/%%/, 'string'],
  306. [
  307. /(%)([\-#+ 0,(])(\d+|\.\d+|\d+\.\d+)(@fstring_conv)/,
  308. ['metatag', 'keyword.modifier', 'number', 'metatag']
  309. ],
  310. [/(%)(\d+|\.\d+|\d+\.\d+)(@fstring_conv)/, ['metatag', 'number', 'metatag']],
  311. [/(%)([\-#+ 0,(])(@fstring_conv)/, ['metatag', 'keyword.modifier', 'metatag']],
  312. [/(%)(@fstring_conv)/, ['metatag', 'metatag']],
  313. [/./, 'string']
  314. ],
  315. sstring: [
  316. [/@escapes/, 'string.escape'],
  317. [
  318. /"/,
  319. {
  320. token: 'string.quote',
  321. bracket: '@close',
  322. switchTo: '@allowMethod'
  323. }
  324. ],
  325. [/\$\$/, 'string'],
  326. [/(\$)([a-z_]\w*)/, ['operator', 'identifier']],
  327. [/\$\{/, 'operator', '@interp'],
  328. [/./, 'string']
  329. ],
  330. sstringt: [
  331. [/@escapes/, 'string.escape'],
  332. [/"(?=""")/, 'string'],
  333. [
  334. /"""/,
  335. {
  336. token: 'string.quote',
  337. bracket: '@close',
  338. switchTo: '@allowMethod'
  339. }
  340. ],
  341. [/\$\$/, 'string'],
  342. [/(\$)([a-z_]\w*)/, ['operator', 'identifier']],
  343. [/\$\{/, 'operator', '@interp'],
  344. [/./, 'string']
  345. ],
  346. interp: [[/{/, 'operator', '@push'], [/}/, 'operator', '@pop'], { include: '@root' }],
  347. rawstring: [
  348. [/[^"]/, 'string'],
  349. [
  350. /"/,
  351. {
  352. token: 'string.quote',
  353. bracket: '@close',
  354. switchTo: '@allowMethod'
  355. }
  356. ]
  357. ],
  358. rawstringt: [
  359. [/[^"]/, 'string'],
  360. [/"(?=""")/, 'string'],
  361. [
  362. /"""/,
  363. {
  364. token: 'string.quote',
  365. bracket: '@close',
  366. switchTo: '@allowMethod'
  367. }
  368. ],
  369. [/"/, 'string']
  370. ],
  371. whitespace: [
  372. [/[ \t\r\n]+/, 'white'],
  373. [/\/\*/, 'comment', '@comment'],
  374. [/\/\/.*$/, 'comment']
  375. ]
  376. }
  377. };
  378. });