rust.js 8.9 KB

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