rust.js 7.4 KB

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