scala.js 11 KB

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