ruby.js 14 KB

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