elixir.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517
  1. "use strict";
  2. /*!-----------------------------------------------------------------------------
  3. * Copyright (c) Microsoft Corporation. All rights reserved.
  4. * Version: 0.38.0(0e330ae453813de4e6cf272460fb79c7117073d0)
  5. * Released under the MIT license
  6. * https://github.com/microsoft/monaco-editor/blob/main/LICENSE.txt
  7. *-----------------------------------------------------------------------------*/
  8. define("vs/basic-languages/elixir/elixir", ["require"],(require)=>{
  9. var moduleExports = (() => {
  10. var __defProp = Object.defineProperty;
  11. var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
  12. var __getOwnPropNames = Object.getOwnPropertyNames;
  13. var __hasOwnProp = Object.prototype.hasOwnProperty;
  14. var __export = (target, all) => {
  15. for (var name in all)
  16. __defProp(target, name, { get: all[name], enumerable: true });
  17. };
  18. var __copyProps = (to, from, except, desc) => {
  19. if (from && typeof from === "object" || typeof from === "function") {
  20. for (let key of __getOwnPropNames(from))
  21. if (!__hasOwnProp.call(to, key) && key !== except)
  22. __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  23. }
  24. return to;
  25. };
  26. var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
  27. // src/basic-languages/elixir/elixir.ts
  28. var elixir_exports = {};
  29. __export(elixir_exports, {
  30. conf: () => conf,
  31. language: () => language
  32. });
  33. var conf = {
  34. comments: {
  35. lineComment: "#"
  36. },
  37. brackets: [
  38. ["{", "}"],
  39. ["[", "]"],
  40. ["(", ")"]
  41. ],
  42. surroundingPairs: [
  43. { open: "{", close: "}" },
  44. { open: "[", close: "]" },
  45. { open: "(", close: ")" },
  46. { open: "'", close: "'" },
  47. { open: '"', close: '"' }
  48. ],
  49. autoClosingPairs: [
  50. { open: "'", close: "'", notIn: ["string", "comment"] },
  51. { open: '"', close: '"', notIn: ["comment"] },
  52. { open: '"""', close: '"""' },
  53. { open: "`", close: "`", notIn: ["string", "comment"] },
  54. { open: "(", close: ")" },
  55. { open: "{", close: "}" },
  56. { open: "[", close: "]" },
  57. { open: "<<", close: ">>" }
  58. ],
  59. indentationRules: {
  60. increaseIndentPattern: /^\s*(after|else|catch|rescue|fn|[^#]*(do|<\-|\->|\{|\[|\=))\s*$/,
  61. decreaseIndentPattern: /^\s*((\}|\])\s*$|(after|else|catch|rescue|end)\b)/
  62. }
  63. };
  64. var language = {
  65. defaultToken: "source",
  66. tokenPostfix: ".elixir",
  67. brackets: [
  68. { open: "[", close: "]", token: "delimiter.square" },
  69. { open: "(", close: ")", token: "delimiter.parenthesis" },
  70. { open: "{", close: "}", token: "delimiter.curly" },
  71. { open: "<<", close: ">>", token: "delimiter.angle.special" }
  72. ],
  73. declarationKeywords: [
  74. "def",
  75. "defp",
  76. "defn",
  77. "defnp",
  78. "defguard",
  79. "defguardp",
  80. "defmacro",
  81. "defmacrop",
  82. "defdelegate",
  83. "defcallback",
  84. "defmacrocallback",
  85. "defmodule",
  86. "defprotocol",
  87. "defexception",
  88. "defimpl",
  89. "defstruct"
  90. ],
  91. operatorKeywords: ["and", "in", "not", "or", "when"],
  92. namespaceKeywords: ["alias", "import", "require", "use"],
  93. otherKeywords: [
  94. "after",
  95. "case",
  96. "catch",
  97. "cond",
  98. "do",
  99. "else",
  100. "end",
  101. "fn",
  102. "for",
  103. "if",
  104. "quote",
  105. "raise",
  106. "receive",
  107. "rescue",
  108. "super",
  109. "throw",
  110. "try",
  111. "unless",
  112. "unquote_splicing",
  113. "unquote",
  114. "with"
  115. ],
  116. constants: ["true", "false", "nil"],
  117. nameBuiltin: ["__MODULE__", "__DIR__", "__ENV__", "__CALLER__", "__STACKTRACE__"],
  118. operator: /-[->]?|!={0,2}|\*{1,2}|\/|\\\\|&{1,3}|\.\.?|\^(?:\^\^)?|\+\+?|<(?:-|<<|=|>|\|>|~>?)?|=~|={1,3}|>(?:=|>>)?|\|~>|\|>|\|{1,3}|~>>?|~~~|::/,
  119. variableName: /[a-z_][a-zA-Z0-9_]*[?!]?/,
  120. atomName: /[a-zA-Z_][a-zA-Z0-9_@]*[?!]?|@specialAtomName|@operator/,
  121. specialAtomName: /\.\.\.|<<>>|%\{\}|%|\{\}/,
  122. aliasPart: /[A-Z][a-zA-Z0-9_]*/,
  123. moduleName: /@aliasPart(?:\.@aliasPart)*/,
  124. sigilSymmetricDelimiter: /"""|'''|"|'|\/|\|/,
  125. sigilStartDelimiter: /@sigilSymmetricDelimiter|<|\{|\[|\(/,
  126. sigilEndDelimiter: /@sigilSymmetricDelimiter|>|\}|\]|\)/,
  127. sigilModifiers: /[a-zA-Z0-9]*/,
  128. decimal: /\d(?:_?\d)*/,
  129. hex: /[0-9a-fA-F](_?[0-9a-fA-F])*/,
  130. octal: /[0-7](_?[0-7])*/,
  131. binary: /[01](_?[01])*/,
  132. escape: /\\u[0-9a-fA-F]{4}|\\x[0-9a-fA-F]{2}|\\./,
  133. tokenizer: {
  134. root: [
  135. { include: "@whitespace" },
  136. { include: "@comments" },
  137. { include: "@keywordsShorthand" },
  138. { include: "@numbers" },
  139. { include: "@identifiers" },
  140. { include: "@strings" },
  141. { include: "@atoms" },
  142. { include: "@sigils" },
  143. { include: "@attributes" },
  144. { include: "@symbols" }
  145. ],
  146. whitespace: [[/\s+/, "white"]],
  147. comments: [[/(#)(.*)/, ["comment.punctuation", "comment"]]],
  148. keywordsShorthand: [
  149. [/(@atomName)(:)(\s+)/, ["constant", "constant.punctuation", "white"]],
  150. [
  151. /"(?=([^"]|#\{.*?\}|\\")*":)/,
  152. { token: "constant.delimiter", next: "@doubleQuotedStringKeyword" }
  153. ],
  154. [
  155. /'(?=([^']|#\{.*?\}|\\')*':)/,
  156. { token: "constant.delimiter", next: "@singleQuotedStringKeyword" }
  157. ]
  158. ],
  159. doubleQuotedStringKeyword: [
  160. [/":/, { token: "constant.delimiter", next: "@pop" }],
  161. { include: "@stringConstantContentInterpol" }
  162. ],
  163. singleQuotedStringKeyword: [
  164. [/':/, { token: "constant.delimiter", next: "@pop" }],
  165. { include: "@stringConstantContentInterpol" }
  166. ],
  167. numbers: [
  168. [/0b@binary/, "number.binary"],
  169. [/0o@octal/, "number.octal"],
  170. [/0x@hex/, "number.hex"],
  171. [/@decimal\.@decimal([eE]-?@decimal)?/, "number.float"],
  172. [/@decimal/, "number"]
  173. ],
  174. identifiers: [
  175. [
  176. /\b(defp?|defnp?|defmacrop?|defguardp?|defdelegate)(\s+)(@variableName)(?!\s+@operator)/,
  177. [
  178. "keyword.declaration",
  179. "white",
  180. {
  181. cases: {
  182. unquote: "keyword",
  183. "@default": "function"
  184. }
  185. }
  186. ]
  187. ],
  188. [
  189. /(@variableName)(?=\s*\.?\s*\()/,
  190. {
  191. cases: {
  192. "@declarationKeywords": "keyword.declaration",
  193. "@namespaceKeywords": "keyword",
  194. "@otherKeywords": "keyword",
  195. "@default": "function.call"
  196. }
  197. }
  198. ],
  199. [
  200. /(@moduleName)(\s*)(\.)(\s*)(@variableName)/,
  201. ["type.identifier", "white", "operator", "white", "function.call"]
  202. ],
  203. [
  204. /(:)(@atomName)(\s*)(\.)(\s*)(@variableName)/,
  205. ["constant.punctuation", "constant", "white", "operator", "white", "function.call"]
  206. ],
  207. [
  208. /(\|>)(\s*)(@variableName)/,
  209. [
  210. "operator",
  211. "white",
  212. {
  213. cases: {
  214. "@otherKeywords": "keyword",
  215. "@default": "function.call"
  216. }
  217. }
  218. ]
  219. ],
  220. [
  221. /(&)(\s*)(@variableName)/,
  222. ["operator", "white", "function.call"]
  223. ],
  224. [
  225. /@variableName/,
  226. {
  227. cases: {
  228. "@declarationKeywords": "keyword.declaration",
  229. "@operatorKeywords": "keyword.operator",
  230. "@namespaceKeywords": "keyword",
  231. "@otherKeywords": "keyword",
  232. "@constants": "constant.language",
  233. "@nameBuiltin": "variable.language",
  234. "_.*": "comment.unused",
  235. "@default": "identifier"
  236. }
  237. }
  238. ],
  239. [/@moduleName/, "type.identifier"]
  240. ],
  241. strings: [
  242. [/"""/, { token: "string.delimiter", next: "@doubleQuotedHeredoc" }],
  243. [/'''/, { token: "string.delimiter", next: "@singleQuotedHeredoc" }],
  244. [/"/, { token: "string.delimiter", next: "@doubleQuotedString" }],
  245. [/'/, { token: "string.delimiter", next: "@singleQuotedString" }]
  246. ],
  247. doubleQuotedHeredoc: [
  248. [/"""/, { token: "string.delimiter", next: "@pop" }],
  249. { include: "@stringContentInterpol" }
  250. ],
  251. singleQuotedHeredoc: [
  252. [/'''/, { token: "string.delimiter", next: "@pop" }],
  253. { include: "@stringContentInterpol" }
  254. ],
  255. doubleQuotedString: [
  256. [/"/, { token: "string.delimiter", next: "@pop" }],
  257. { include: "@stringContentInterpol" }
  258. ],
  259. singleQuotedString: [
  260. [/'/, { token: "string.delimiter", next: "@pop" }],
  261. { include: "@stringContentInterpol" }
  262. ],
  263. atoms: [
  264. [/(:)(@atomName)/, ["constant.punctuation", "constant"]],
  265. [/:"/, { token: "constant.delimiter", next: "@doubleQuotedStringAtom" }],
  266. [/:'/, { token: "constant.delimiter", next: "@singleQuotedStringAtom" }]
  267. ],
  268. doubleQuotedStringAtom: [
  269. [/"/, { token: "constant.delimiter", next: "@pop" }],
  270. { include: "@stringConstantContentInterpol" }
  271. ],
  272. singleQuotedStringAtom: [
  273. [/'/, { token: "constant.delimiter", next: "@pop" }],
  274. { include: "@stringConstantContentInterpol" }
  275. ],
  276. sigils: [
  277. [/~[a-z]@sigilStartDelimiter/, { token: "@rematch", next: "@sigil.interpol" }],
  278. [/~[A-Z]@sigilStartDelimiter/, { token: "@rematch", next: "@sigil.noInterpol" }]
  279. ],
  280. sigil: [
  281. [/~([a-zA-Z])\{/, { token: "@rematch", switchTo: "@sigilStart.$S2.$1.{.}" }],
  282. [/~([a-zA-Z])\[/, { token: "@rematch", switchTo: "@sigilStart.$S2.$1.[.]" }],
  283. [/~([a-zA-Z])\(/, { token: "@rematch", switchTo: "@sigilStart.$S2.$1.(.)" }],
  284. [/~([a-zA-Z])\</, { token: "@rematch", switchTo: "@sigilStart.$S2.$1.<.>" }],
  285. [
  286. /~([a-zA-Z])(@sigilSymmetricDelimiter)/,
  287. { token: "@rematch", switchTo: "@sigilStart.$S2.$1.$2.$2" }
  288. ]
  289. ],
  290. "sigilStart.interpol.s": [
  291. [
  292. /~s@sigilStartDelimiter/,
  293. {
  294. token: "string.delimiter",
  295. switchTo: "@sigilContinue.$S2.$S3.$S4.$S5"
  296. }
  297. ]
  298. ],
  299. "sigilContinue.interpol.s": [
  300. [
  301. /(@sigilEndDelimiter)@sigilModifiers/,
  302. {
  303. cases: {
  304. "$1==$S5": { token: "string.delimiter", next: "@pop" },
  305. "@default": "string"
  306. }
  307. }
  308. ],
  309. { include: "@stringContentInterpol" }
  310. ],
  311. "sigilStart.noInterpol.S": [
  312. [
  313. /~S@sigilStartDelimiter/,
  314. {
  315. token: "string.delimiter",
  316. switchTo: "@sigilContinue.$S2.$S3.$S4.$S5"
  317. }
  318. ]
  319. ],
  320. "sigilContinue.noInterpol.S": [
  321. [/(^|[^\\])\\@sigilEndDelimiter/, "string"],
  322. [
  323. /(@sigilEndDelimiter)@sigilModifiers/,
  324. {
  325. cases: {
  326. "$1==$S5": { token: "string.delimiter", next: "@pop" },
  327. "@default": "string"
  328. }
  329. }
  330. ],
  331. { include: "@stringContent" }
  332. ],
  333. "sigilStart.interpol.r": [
  334. [
  335. /~r@sigilStartDelimiter/,
  336. {
  337. token: "regexp.delimiter",
  338. switchTo: "@sigilContinue.$S2.$S3.$S4.$S5"
  339. }
  340. ]
  341. ],
  342. "sigilContinue.interpol.r": [
  343. [
  344. /(@sigilEndDelimiter)@sigilModifiers/,
  345. {
  346. cases: {
  347. "$1==$S5": { token: "regexp.delimiter", next: "@pop" },
  348. "@default": "regexp"
  349. }
  350. }
  351. ],
  352. { include: "@regexpContentInterpol" }
  353. ],
  354. "sigilStart.noInterpol.R": [
  355. [
  356. /~R@sigilStartDelimiter/,
  357. {
  358. token: "regexp.delimiter",
  359. switchTo: "@sigilContinue.$S2.$S3.$S4.$S5"
  360. }
  361. ]
  362. ],
  363. "sigilContinue.noInterpol.R": [
  364. [/(^|[^\\])\\@sigilEndDelimiter/, "regexp"],
  365. [
  366. /(@sigilEndDelimiter)@sigilModifiers/,
  367. {
  368. cases: {
  369. "$1==$S5": { token: "regexp.delimiter", next: "@pop" },
  370. "@default": "regexp"
  371. }
  372. }
  373. ],
  374. { include: "@regexpContent" }
  375. ],
  376. "sigilStart.interpol": [
  377. [
  378. /~([a-zA-Z])@sigilStartDelimiter/,
  379. {
  380. token: "sigil.delimiter",
  381. switchTo: "@sigilContinue.$S2.$S3.$S4.$S5"
  382. }
  383. ]
  384. ],
  385. "sigilContinue.interpol": [
  386. [
  387. /(@sigilEndDelimiter)@sigilModifiers/,
  388. {
  389. cases: {
  390. "$1==$S5": { token: "sigil.delimiter", next: "@pop" },
  391. "@default": "sigil"
  392. }
  393. }
  394. ],
  395. { include: "@sigilContentInterpol" }
  396. ],
  397. "sigilStart.noInterpol": [
  398. [
  399. /~([a-zA-Z])@sigilStartDelimiter/,
  400. {
  401. token: "sigil.delimiter",
  402. switchTo: "@sigilContinue.$S2.$S3.$S4.$S5"
  403. }
  404. ]
  405. ],
  406. "sigilContinue.noInterpol": [
  407. [/(^|[^\\])\\@sigilEndDelimiter/, "sigil"],
  408. [
  409. /(@sigilEndDelimiter)@sigilModifiers/,
  410. {
  411. cases: {
  412. "$1==$S5": { token: "sigil.delimiter", next: "@pop" },
  413. "@default": "sigil"
  414. }
  415. }
  416. ],
  417. { include: "@sigilContent" }
  418. ],
  419. attributes: [
  420. [
  421. /\@(module|type)?doc (~[sS])?"""/,
  422. {
  423. token: "comment.block.documentation",
  424. next: "@doubleQuotedHeredocDocstring"
  425. }
  426. ],
  427. [
  428. /\@(module|type)?doc (~[sS])?'''/,
  429. {
  430. token: "comment.block.documentation",
  431. next: "@singleQuotedHeredocDocstring"
  432. }
  433. ],
  434. [
  435. /\@(module|type)?doc (~[sS])?"/,
  436. {
  437. token: "comment.block.documentation",
  438. next: "@doubleQuotedStringDocstring"
  439. }
  440. ],
  441. [
  442. /\@(module|type)?doc (~[sS])?'/,
  443. {
  444. token: "comment.block.documentation",
  445. next: "@singleQuotedStringDocstring"
  446. }
  447. ],
  448. [/\@(module|type)?doc false/, "comment.block.documentation"],
  449. [/\@(@variableName)/, "variable"]
  450. ],
  451. doubleQuotedHeredocDocstring: [
  452. [/"""/, { token: "comment.block.documentation", next: "@pop" }],
  453. { include: "@docstringContent" }
  454. ],
  455. singleQuotedHeredocDocstring: [
  456. [/'''/, { token: "comment.block.documentation", next: "@pop" }],
  457. { include: "@docstringContent" }
  458. ],
  459. doubleQuotedStringDocstring: [
  460. [/"/, { token: "comment.block.documentation", next: "@pop" }],
  461. { include: "@docstringContent" }
  462. ],
  463. singleQuotedStringDocstring: [
  464. [/'/, { token: "comment.block.documentation", next: "@pop" }],
  465. { include: "@docstringContent" }
  466. ],
  467. symbols: [
  468. [/\?(\\.|[^\\\s])/, "number.constant"],
  469. [/&\d+/, "operator"],
  470. [/<<<|>>>/, "operator"],
  471. [/[()\[\]\{\}]|<<|>>/, "@brackets"],
  472. [/\.\.\./, "identifier"],
  473. [/=>/, "punctuation"],
  474. [/@operator/, "operator"],
  475. [/[:;,.%]/, "punctuation"]
  476. ],
  477. stringContentInterpol: [
  478. { include: "@interpolation" },
  479. { include: "@escapeChar" },
  480. { include: "@stringContent" }
  481. ],
  482. stringContent: [[/./, "string"]],
  483. stringConstantContentInterpol: [
  484. { include: "@interpolation" },
  485. { include: "@escapeChar" },
  486. { include: "@stringConstantContent" }
  487. ],
  488. stringConstantContent: [[/./, "constant"]],
  489. regexpContentInterpol: [
  490. { include: "@interpolation" },
  491. { include: "@escapeChar" },
  492. { include: "@regexpContent" }
  493. ],
  494. regexpContent: [
  495. [/(\s)(#)(\s.*)$/, ["white", "comment.punctuation", "comment"]],
  496. [/./, "regexp"]
  497. ],
  498. sigilContentInterpol: [
  499. { include: "@interpolation" },
  500. { include: "@escapeChar" },
  501. { include: "@sigilContent" }
  502. ],
  503. sigilContent: [[/./, "sigil"]],
  504. docstringContent: [[/./, "comment.block.documentation"]],
  505. escapeChar: [[/@escape/, "constant.character.escape"]],
  506. interpolation: [[/#{/, { token: "delimiter.bracket.embed", next: "@interpolationContinue" }]],
  507. interpolationContinue: [
  508. [/}/, { token: "delimiter.bracket.embed", next: "@pop" }],
  509. { include: "@root" }
  510. ]
  511. }
  512. };
  513. return __toCommonJS(elixir_exports);
  514. })();
  515. return moduleExports;
  516. });