ruby.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472
  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/ruby/ruby", ["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/ruby/ruby.ts
  28. var ruby_exports = {};
  29. __export(ruby_exports, {
  30. conf: () => conf,
  31. language: () => language
  32. });
  33. var conf = {
  34. comments: {
  35. lineComment: "#",
  36. blockComment: ["=begin", "=end"]
  37. },
  38. brackets: [
  39. ["(", ")"],
  40. ["{", "}"],
  41. ["[", "]"]
  42. ],
  43. autoClosingPairs: [
  44. { open: "{", close: "}" },
  45. { open: "[", close: "]" },
  46. { open: "(", close: ")" },
  47. { open: '"', close: '"' },
  48. { open: "'", close: "'" }
  49. ],
  50. surroundingPairs: [
  51. { open: "{", close: "}" },
  52. { open: "[", close: "]" },
  53. { open: "(", close: ")" },
  54. { open: '"', close: '"' },
  55. { open: "'", close: "'" }
  56. ],
  57. indentationRules: {
  58. increaseIndentPattern: new RegExp(`^\\s*((begin|class|(private|protected)\\s+def|def|else|elsif|ensure|for|if|module|rescue|unless|until|when|while|case)|([^#]*\\sdo\\b)|([^#]*=\\s*(case|if|unless)))\\b([^#\\{;]|("|'|/).*\\4)*(#.*)?$`),
  59. decreaseIndentPattern: new RegExp("^\\s*([}\\]]([,)]?\\s*(#|$)|\\.[a-zA-Z_]\\w*\\b)|(end|rescue|ensure|else|elsif|when)\\b)")
  60. }
  61. };
  62. var language = {
  63. tokenPostfix: ".ruby",
  64. keywords: [
  65. "__LINE__",
  66. "__ENCODING__",
  67. "__FILE__",
  68. "BEGIN",
  69. "END",
  70. "alias",
  71. "and",
  72. "begin",
  73. "break",
  74. "case",
  75. "class",
  76. "def",
  77. "defined?",
  78. "do",
  79. "else",
  80. "elsif",
  81. "end",
  82. "ensure",
  83. "for",
  84. "false",
  85. "if",
  86. "in",
  87. "module",
  88. "next",
  89. "nil",
  90. "not",
  91. "or",
  92. "redo",
  93. "rescue",
  94. "retry",
  95. "return",
  96. "self",
  97. "super",
  98. "then",
  99. "true",
  100. "undef",
  101. "unless",
  102. "until",
  103. "when",
  104. "while",
  105. "yield"
  106. ],
  107. keywordops: ["::", "..", "...", "?", ":", "=>"],
  108. builtins: [
  109. "require",
  110. "public",
  111. "private",
  112. "include",
  113. "extend",
  114. "attr_reader",
  115. "protected",
  116. "private_class_method",
  117. "protected_class_method",
  118. "new"
  119. ],
  120. declarations: [
  121. "module",
  122. "class",
  123. "def",
  124. "case",
  125. "do",
  126. "begin",
  127. "for",
  128. "if",
  129. "while",
  130. "until",
  131. "unless"
  132. ],
  133. linedecls: ["def", "case", "do", "begin", "for", "if", "while", "until", "unless"],
  134. operators: [
  135. "^",
  136. "&",
  137. "|",
  138. "<=>",
  139. "==",
  140. "===",
  141. "!~",
  142. "=~",
  143. ">",
  144. ">=",
  145. "<",
  146. "<=",
  147. "<<",
  148. ">>",
  149. "+",
  150. "-",
  151. "*",
  152. "/",
  153. "%",
  154. "**",
  155. "~",
  156. "+@",
  157. "-@",
  158. "[]",
  159. "[]=",
  160. "`",
  161. "+=",
  162. "-=",
  163. "*=",
  164. "**=",
  165. "/=",
  166. "^=",
  167. "%=",
  168. "<<=",
  169. ">>=",
  170. "&=",
  171. "&&=",
  172. "||=",
  173. "|="
  174. ],
  175. brackets: [
  176. { open: "(", close: ")", token: "delimiter.parenthesis" },
  177. { open: "{", close: "}", token: "delimiter.curly" },
  178. { open: "[", close: "]", token: "delimiter.square" }
  179. ],
  180. symbols: /[=><!~?:&|+\-*\/\^%\.]+/,
  181. escape: /(?:[abefnrstv\\"'\n\r]|[0-7]{1,3}|x[0-9A-Fa-f]{1,2}|u[0-9A-Fa-f]{4})/,
  182. escapes: /\\(?:C\-(@escape|.)|c(@escape|.)|@escape)/,
  183. decpart: /\d(_?\d)*/,
  184. decimal: /0|@decpart/,
  185. delim: /[^a-zA-Z0-9\s\n\r]/,
  186. heredelim: /(?:\w+|'[^']*'|"[^"]*"|`[^`]*`)/,
  187. regexpctl: /[(){}\[\]\$\^|\-*+?\.]/,
  188. regexpesc: /\\(?:[AzZbBdDfnrstvwWn0\\\/]|@regexpctl|c[A-Z]|x[0-9a-fA-F]{2}|u[0-9a-fA-F]{4})?/,
  189. tokenizer: {
  190. root: [
  191. [
  192. /^(\s*)([a-z_]\w*[!?=]?)/,
  193. [
  194. "white",
  195. {
  196. cases: {
  197. "for|until|while": {
  198. token: "keyword.$2",
  199. next: "@dodecl.$2"
  200. },
  201. "@declarations": {
  202. token: "keyword.$2",
  203. next: "@root.$2"
  204. },
  205. end: { token: "keyword.$S2", next: "@pop" },
  206. "@keywords": "keyword",
  207. "@builtins": "predefined",
  208. "@default": "identifier"
  209. }
  210. }
  211. ]
  212. ],
  213. [
  214. /[a-z_]\w*[!?=]?/,
  215. {
  216. cases: {
  217. "if|unless|while|until": {
  218. token: "keyword.$0x",
  219. next: "@modifier.$0x"
  220. },
  221. for: { token: "keyword.$2", next: "@dodecl.$2" },
  222. "@linedecls": { token: "keyword.$0", next: "@root.$0" },
  223. end: { token: "keyword.$S2", next: "@pop" },
  224. "@keywords": "keyword",
  225. "@builtins": "predefined",
  226. "@default": "identifier"
  227. }
  228. }
  229. ],
  230. [/[A-Z][\w]*[!?=]?/, "constructor.identifier"],
  231. [/\$[\w]*/, "global.constant"],
  232. [/@[\w]*/, "namespace.instance.identifier"],
  233. [/@@@[\w]*/, "namespace.class.identifier"],
  234. [/<<[-~](@heredelim).*/, { token: "string.heredoc.delimiter", next: "@heredoc.$1" }],
  235. [/[ \t\r\n]+<<(@heredelim).*/, { token: "string.heredoc.delimiter", next: "@heredoc.$1" }],
  236. [/^<<(@heredelim).*/, { token: "string.heredoc.delimiter", next: "@heredoc.$1" }],
  237. { include: "@whitespace" },
  238. [/"/, { token: "string.d.delim", next: '@dstring.d."' }],
  239. [/'/, { token: "string.sq.delim", next: "@sstring.sq" }],
  240. [/%([rsqxwW]|Q?)/, { token: "@rematch", next: "pstring" }],
  241. [/`/, { token: "string.x.delim", next: "@dstring.x.`" }],
  242. [/:(\w|[$@])\w*[!?=]?/, "string.s"],
  243. [/:"/, { token: "string.s.delim", next: '@dstring.s."' }],
  244. [/:'/, { token: "string.s.delim", next: "@sstring.s" }],
  245. [/\/(?=(\\\/|[^\/\n])+\/)/, { token: "regexp.delim", next: "@regexp" }],
  246. [/[{}()\[\]]/, "@brackets"],
  247. [
  248. /@symbols/,
  249. {
  250. cases: {
  251. "@keywordops": "keyword",
  252. "@operators": "operator",
  253. "@default": ""
  254. }
  255. }
  256. ],
  257. [/[;,]/, "delimiter"],
  258. [/0[xX][0-9a-fA-F](_?[0-9a-fA-F])*/, "number.hex"],
  259. [/0[_oO][0-7](_?[0-7])*/, "number.octal"],
  260. [/0[bB][01](_?[01])*/, "number.binary"],
  261. [/0[dD]@decpart/, "number"],
  262. [
  263. /@decimal((\.@decpart)?([eE][\-+]?@decpart)?)/,
  264. {
  265. cases: {
  266. $1: "number.float",
  267. "@default": "number"
  268. }
  269. }
  270. ]
  271. ],
  272. dodecl: [
  273. [/^/, { token: "", switchTo: "@root.$S2" }],
  274. [
  275. /[a-z_]\w*[!?=]?/,
  276. {
  277. cases: {
  278. end: { token: "keyword.$S2", next: "@pop" },
  279. do: { token: "keyword", switchTo: "@root.$S2" },
  280. "@linedecls": {
  281. token: "@rematch",
  282. switchTo: "@root.$S2"
  283. },
  284. "@keywords": "keyword",
  285. "@builtins": "predefined",
  286. "@default": "identifier"
  287. }
  288. }
  289. ],
  290. { include: "@root" }
  291. ],
  292. modifier: [
  293. [/^/, "", "@pop"],
  294. [
  295. /[a-z_]\w*[!?=]?/,
  296. {
  297. cases: {
  298. end: { token: "keyword.$S2", next: "@pop" },
  299. "then|else|elsif|do": {
  300. token: "keyword",
  301. switchTo: "@root.$S2"
  302. },
  303. "@linedecls": {
  304. token: "@rematch",
  305. switchTo: "@root.$S2"
  306. },
  307. "@keywords": "keyword",
  308. "@builtins": "predefined",
  309. "@default": "identifier"
  310. }
  311. }
  312. ],
  313. { include: "@root" }
  314. ],
  315. sstring: [
  316. [/[^\\']+/, "string.$S2"],
  317. [/\\\\|\\'|\\$/, "string.$S2.escape"],
  318. [/\\./, "string.$S2.invalid"],
  319. [/'/, { token: "string.$S2.delim", next: "@pop" }]
  320. ],
  321. dstring: [
  322. [/[^\\`"#]+/, "string.$S2"],
  323. [/#/, "string.$S2.escape", "@interpolated"],
  324. [/\\$/, "string.$S2.escape"],
  325. [/@escapes/, "string.$S2.escape"],
  326. [/\\./, "string.$S2.escape.invalid"],
  327. [
  328. /[`"]/,
  329. {
  330. cases: {
  331. "$#==$S3": { token: "string.$S2.delim", next: "@pop" },
  332. "@default": "string.$S2"
  333. }
  334. }
  335. ]
  336. ],
  337. heredoc: [
  338. [
  339. /^(\s*)(@heredelim)$/,
  340. {
  341. cases: {
  342. "$2==$S2": ["string.heredoc", { token: "string.heredoc.delimiter", next: "@pop" }],
  343. "@default": ["string.heredoc", "string.heredoc"]
  344. }
  345. }
  346. ],
  347. [/.*/, "string.heredoc"]
  348. ],
  349. interpolated: [
  350. [/\$\w*/, "global.constant", "@pop"],
  351. [/@\w*/, "namespace.class.identifier", "@pop"],
  352. [/@@@\w*/, "namespace.instance.identifier", "@pop"],
  353. [
  354. /[{]/,
  355. {
  356. token: "string.escape.curly",
  357. switchTo: "@interpolated_compound"
  358. }
  359. ],
  360. ["", "", "@pop"]
  361. ],
  362. interpolated_compound: [
  363. [/[}]/, { token: "string.escape.curly", next: "@pop" }],
  364. { include: "@root" }
  365. ],
  366. pregexp: [
  367. { include: "@whitespace" },
  368. [
  369. /[^\(\{\[\\]/,
  370. {
  371. cases: {
  372. "$#==$S3": { token: "regexp.delim", next: "@pop" },
  373. "$#==$S2": { token: "regexp.delim", next: "@push" },
  374. "~[)}\\]]": "@brackets.regexp.escape.control",
  375. "~@regexpctl": "regexp.escape.control",
  376. "@default": "regexp"
  377. }
  378. }
  379. ],
  380. { include: "@regexcontrol" }
  381. ],
  382. regexp: [
  383. { include: "@regexcontrol" },
  384. [/[^\\\/]/, "regexp"],
  385. ["/[ixmp]*", { token: "regexp.delim" }, "@pop"]
  386. ],
  387. regexcontrol: [
  388. [
  389. /(\{)(\d+(?:,\d*)?)(\})/,
  390. [
  391. "@brackets.regexp.escape.control",
  392. "regexp.escape.control",
  393. "@brackets.regexp.escape.control"
  394. ]
  395. ],
  396. [
  397. /(\[)(\^?)/,
  398. ["@brackets.regexp.escape.control", { token: "regexp.escape.control", next: "@regexrange" }]
  399. ],
  400. [/(\()(\?[:=!])/, ["@brackets.regexp.escape.control", "regexp.escape.control"]],
  401. [/\(\?#/, { token: "regexp.escape.control", next: "@regexpcomment" }],
  402. [/[()]/, "@brackets.regexp.escape.control"],
  403. [/@regexpctl/, "regexp.escape.control"],
  404. [/\\$/, "regexp.escape"],
  405. [/@regexpesc/, "regexp.escape"],
  406. [/\\\./, "regexp.invalid"],
  407. [/#/, "regexp.escape", "@interpolated"]
  408. ],
  409. regexrange: [
  410. [/-/, "regexp.escape.control"],
  411. [/\^/, "regexp.invalid"],
  412. [/\\$/, "regexp.escape"],
  413. [/@regexpesc/, "regexp.escape"],
  414. [/[^\]]/, "regexp"],
  415. [/\]/, "@brackets.regexp.escape.control", "@pop"]
  416. ],
  417. regexpcomment: [
  418. [/[^)]+/, "comment"],
  419. [/\)/, { token: "regexp.escape.control", next: "@pop" }]
  420. ],
  421. pstring: [
  422. [/%([qws])\(/, { token: "string.$1.delim", switchTo: "@qstring.$1.(.)" }],
  423. [/%([qws])\[/, { token: "string.$1.delim", switchTo: "@qstring.$1.[.]" }],
  424. [/%([qws])\{/, { token: "string.$1.delim", switchTo: "@qstring.$1.{.}" }],
  425. [/%([qws])</, { token: "string.$1.delim", switchTo: "@qstring.$1.<.>" }],
  426. [/%([qws])(@delim)/, { token: "string.$1.delim", switchTo: "@qstring.$1.$2.$2" }],
  427. [/%r\(/, { token: "regexp.delim", switchTo: "@pregexp.(.)" }],
  428. [/%r\[/, { token: "regexp.delim", switchTo: "@pregexp.[.]" }],
  429. [/%r\{/, { token: "regexp.delim", switchTo: "@pregexp.{.}" }],
  430. [/%r</, { token: "regexp.delim", switchTo: "@pregexp.<.>" }],
  431. [/%r(@delim)/, { token: "regexp.delim", switchTo: "@pregexp.$1.$1" }],
  432. [/%(x|W|Q?)\(/, { token: "string.$1.delim", switchTo: "@qqstring.$1.(.)" }],
  433. [/%(x|W|Q?)\[/, { token: "string.$1.delim", switchTo: "@qqstring.$1.[.]" }],
  434. [/%(x|W|Q?)\{/, { token: "string.$1.delim", switchTo: "@qqstring.$1.{.}" }],
  435. [/%(x|W|Q?)</, { token: "string.$1.delim", switchTo: "@qqstring.$1.<.>" }],
  436. [/%(x|W|Q?)(@delim)/, { token: "string.$1.delim", switchTo: "@qqstring.$1.$2.$2" }],
  437. [/%([rqwsxW]|Q?)./, { token: "invalid", next: "@pop" }],
  438. [/./, { token: "invalid", next: "@pop" }]
  439. ],
  440. qstring: [
  441. [/\\$/, "string.$S2.escape"],
  442. [/\\./, "string.$S2.escape"],
  443. [
  444. /./,
  445. {
  446. cases: {
  447. "$#==$S4": { token: "string.$S2.delim", next: "@pop" },
  448. "$#==$S3": { token: "string.$S2.delim", next: "@push" },
  449. "@default": "string.$S2"
  450. }
  451. }
  452. ]
  453. ],
  454. qqstring: [[/#/, "string.$S2.escape", "@interpolated"], { include: "@qstring" }],
  455. whitespace: [
  456. [/[ \t\r\n]+/, ""],
  457. [/^\s*=begin\b/, "comment", "@comment"],
  458. [/#.*$/, "comment"]
  459. ],
  460. comment: [
  461. [/[^=]+/, "comment"],
  462. [/^\s*=begin\b/, "comment.invalid"],
  463. [/^\s*=end\b.*/, "comment", "@pop"],
  464. [/[=]/, "comment"]
  465. ]
  466. }
  467. };
  468. return __toCommonJS(ruby_exports);
  469. })();
  470. return moduleExports;
  471. });