elixir.js 15 KB

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