rust.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  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. // src/basic-languages/rust/rust.ts
  8. var conf = {
  9. comments: {
  10. lineComment: "//",
  11. blockComment: ["/*", "*/"]
  12. },
  13. brackets: [
  14. ["{", "}"],
  15. ["[", "]"],
  16. ["(", ")"]
  17. ],
  18. autoClosingPairs: [
  19. { open: "[", close: "]" },
  20. { open: "{", close: "}" },
  21. { open: "(", close: ")" },
  22. { open: '"', close: '"', notIn: ["string"] }
  23. ],
  24. surroundingPairs: [
  25. { open: "{", close: "}" },
  26. { open: "[", close: "]" },
  27. { open: "(", close: ")" },
  28. { open: '"', close: '"' },
  29. { open: "'", close: "'" }
  30. ],
  31. folding: {
  32. markers: {
  33. start: new RegExp("^\\s*#pragma\\s+region\\b"),
  34. end: new RegExp("^\\s*#pragma\\s+endregion\\b")
  35. }
  36. }
  37. };
  38. var language = {
  39. tokenPostfix: ".rust",
  40. defaultToken: "invalid",
  41. keywords: [
  42. "as",
  43. "async",
  44. "await",
  45. "box",
  46. "break",
  47. "const",
  48. "continue",
  49. "crate",
  50. "dyn",
  51. "else",
  52. "enum",
  53. "extern",
  54. "false",
  55. "fn",
  56. "for",
  57. "if",
  58. "impl",
  59. "in",
  60. "let",
  61. "loop",
  62. "match",
  63. "mod",
  64. "move",
  65. "mut",
  66. "pub",
  67. "ref",
  68. "return",
  69. "self",
  70. "static",
  71. "struct",
  72. "super",
  73. "trait",
  74. "true",
  75. "try",
  76. "type",
  77. "unsafe",
  78. "use",
  79. "where",
  80. "while",
  81. "catch",
  82. "default",
  83. "union",
  84. "static",
  85. "abstract",
  86. "alignof",
  87. "become",
  88. "do",
  89. "final",
  90. "macro",
  91. "offsetof",
  92. "override",
  93. "priv",
  94. "proc",
  95. "pure",
  96. "sizeof",
  97. "typeof",
  98. "unsized",
  99. "virtual",
  100. "yield"
  101. ],
  102. typeKeywords: [
  103. "Self",
  104. "m32",
  105. "m64",
  106. "m128",
  107. "f80",
  108. "f16",
  109. "f128",
  110. "int",
  111. "uint",
  112. "float",
  113. "char",
  114. "bool",
  115. "u8",
  116. "u16",
  117. "u32",
  118. "u64",
  119. "f32",
  120. "f64",
  121. "i8",
  122. "i16",
  123. "i32",
  124. "i64",
  125. "str",
  126. "Option",
  127. "Either",
  128. "c_float",
  129. "c_double",
  130. "c_void",
  131. "FILE",
  132. "fpos_t",
  133. "DIR",
  134. "dirent",
  135. "c_char",
  136. "c_schar",
  137. "c_uchar",
  138. "c_short",
  139. "c_ushort",
  140. "c_int",
  141. "c_uint",
  142. "c_long",
  143. "c_ulong",
  144. "size_t",
  145. "ptrdiff_t",
  146. "clock_t",
  147. "time_t",
  148. "c_longlong",
  149. "c_ulonglong",
  150. "intptr_t",
  151. "uintptr_t",
  152. "off_t",
  153. "dev_t",
  154. "ino_t",
  155. "pid_t",
  156. "mode_t",
  157. "ssize_t"
  158. ],
  159. constants: ["true", "false", "Some", "None", "Left", "Right", "Ok", "Err"],
  160. supportConstants: [
  161. "EXIT_FAILURE",
  162. "EXIT_SUCCESS",
  163. "RAND_MAX",
  164. "EOF",
  165. "SEEK_SET",
  166. "SEEK_CUR",
  167. "SEEK_END",
  168. "_IOFBF",
  169. "_IONBF",
  170. "_IOLBF",
  171. "BUFSIZ",
  172. "FOPEN_MAX",
  173. "FILENAME_MAX",
  174. "L_tmpnam",
  175. "TMP_MAX",
  176. "O_RDONLY",
  177. "O_WRONLY",
  178. "O_RDWR",
  179. "O_APPEND",
  180. "O_CREAT",
  181. "O_EXCL",
  182. "O_TRUNC",
  183. "S_IFIFO",
  184. "S_IFCHR",
  185. "S_IFBLK",
  186. "S_IFDIR",
  187. "S_IFREG",
  188. "S_IFMT",
  189. "S_IEXEC",
  190. "S_IWRITE",
  191. "S_IREAD",
  192. "S_IRWXU",
  193. "S_IXUSR",
  194. "S_IWUSR",
  195. "S_IRUSR",
  196. "F_OK",
  197. "R_OK",
  198. "W_OK",
  199. "X_OK",
  200. "STDIN_FILENO",
  201. "STDOUT_FILENO",
  202. "STDERR_FILENO"
  203. ],
  204. supportMacros: [
  205. "format!",
  206. "print!",
  207. "println!",
  208. "panic!",
  209. "format_args!",
  210. "unreachable!",
  211. "write!",
  212. "writeln!"
  213. ],
  214. operators: [
  215. "!",
  216. "!=",
  217. "%",
  218. "%=",
  219. "&",
  220. "&=",
  221. "&&",
  222. "*",
  223. "*=",
  224. "+",
  225. "+=",
  226. "-",
  227. "-=",
  228. "->",
  229. ".",
  230. "..",
  231. "...",
  232. "/",
  233. "/=",
  234. ":",
  235. ";",
  236. "<<",
  237. "<<=",
  238. "<",
  239. "<=",
  240. "=",
  241. "==",
  242. "=>",
  243. ">",
  244. ">=",
  245. ">>",
  246. ">>=",
  247. "@",
  248. "^",
  249. "^=",
  250. "|",
  251. "|=",
  252. "||",
  253. "_",
  254. "?",
  255. "#"
  256. ],
  257. escapes: /\\([nrt0\"''\\]|x\h{2}|u\{\h{1,6}\})/,
  258. delimiters: /[,]/,
  259. symbols: /[\#\!\%\&\*\+\-\.\/\:\;\<\=\>\@\^\|_\?]+/,
  260. intSuffixes: /[iu](8|16|32|64|128|size)/,
  261. floatSuffixes: /f(32|64)/,
  262. tokenizer: {
  263. root: [
  264. [/r(#*)"/, { token: "string.quote", bracket: "@open", next: "@stringraw.$1" }],
  265. [
  266. /[a-zA-Z][a-zA-Z0-9_]*!?|_[a-zA-Z0-9_]+/,
  267. {
  268. cases: {
  269. "@typeKeywords": "keyword.type",
  270. "@keywords": "keyword",
  271. "@supportConstants": "keyword",
  272. "@supportMacros": "keyword",
  273. "@constants": "keyword",
  274. "@default": "identifier"
  275. }
  276. }
  277. ],
  278. [/\$/, "identifier"],
  279. [/'[a-zA-Z_][a-zA-Z0-9_]*(?=[^\'])/, "identifier"],
  280. [/'(\S|@escapes)'/, "string.byteliteral"],
  281. [/"/, { token: "string.quote", bracket: "@open", next: "@string" }],
  282. { include: "@numbers" },
  283. { include: "@whitespace" },
  284. [
  285. /@delimiters/,
  286. {
  287. cases: {
  288. "@keywords": "keyword",
  289. "@default": "delimiter"
  290. }
  291. }
  292. ],
  293. [/[{}()\[\]<>]/, "@brackets"],
  294. [/@symbols/, { cases: { "@operators": "operator", "@default": "" } }]
  295. ],
  296. whitespace: [
  297. [/[ \t\r\n]+/, "white"],
  298. [/\/\*/, "comment", "@comment"],
  299. [/\/\/.*$/, "comment"]
  300. ],
  301. comment: [
  302. [/[^\/*]+/, "comment"],
  303. [/\/\*/, "comment", "@push"],
  304. ["\\*/", "comment", "@pop"],
  305. [/[\/*]/, "comment"]
  306. ],
  307. string: [
  308. [/[^\\"]+/, "string"],
  309. [/@escapes/, "string.escape"],
  310. [/\\./, "string.escape.invalid"],
  311. [/"/, { token: "string.quote", bracket: "@close", next: "@pop" }]
  312. ],
  313. stringraw: [
  314. [/[^"#]+/, { token: "string" }],
  315. [
  316. /"(#*)/,
  317. {
  318. cases: {
  319. "$1==$S2": { token: "string.quote", bracket: "@close", next: "@pop" },
  320. "@default": { token: "string" }
  321. }
  322. }
  323. ],
  324. [/["#]/, { token: "string" }]
  325. ],
  326. numbers: [
  327. [/(0o[0-7_]+)(@intSuffixes)?/, { token: "number" }],
  328. [/(0b[0-1_]+)(@intSuffixes)?/, { token: "number" }],
  329. [/[\d][\d_]*(\.[\d][\d_]*)?[eE][+-][\d_]+(@floatSuffixes)?/, { token: "number" }],
  330. [/\b(\d\.?[\d_]*)(@floatSuffixes)?\b/, { token: "number" }],
  331. [/(0x[\da-fA-F]+)_?(@intSuffixes)?/, { token: "number" }],
  332. [/[\d][\d_]*(@intSuffixes?)?/, { token: "number" }]
  333. ]
  334. }
  335. };
  336. export {
  337. conf,
  338. language
  339. };