rust.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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(["require", "exports"], function (require, exports) {
  6. 'use strict';
  7. Object.defineProperty(exports, "__esModule", { value: true });
  8. exports.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', 'comment'] },
  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', 'box', 'break', 'const', 'continue', 'crate', 'else', 'enum',
  44. 'extern', 'false', 'fn', 'for', 'if', 'impl', 'in', 'let', 'loop',
  45. 'match', 'mod', 'move', 'mut', 'pub', 'ref', 'return', 'self',
  46. 'static', 'struct', 'super', 'trait', 'true', 'type', 'unsafe', 'use',
  47. 'where', 'while', 'catch', 'default', 'union', 'static', 'abstract',
  48. 'alignof', 'become', 'do', 'final', 'macro', 'offsetof', 'override',
  49. 'priv', 'proc', 'pure', 'sizeof', 'typeof', 'unsized', 'virtual',
  50. 'yield',
  51. ],
  52. typeKeywords: [
  53. 'Self', 'm32', 'm64', 'm128', 'f80', 'f16', 'f128', 'int', 'uint',
  54. 'float', 'char', 'bool', 'u8', 'u16', 'u32', 'u64', 'f32', 'f64', 'i8',
  55. 'i16', 'i32', 'i64', 'str', 'Option', 'Either', 'c_float', 'c_double',
  56. 'c_void', 'FILE', 'fpos_t', 'DIR', 'dirent', 'c_char', 'c_schar',
  57. 'c_uchar', 'c_short', 'c_ushort', 'c_int', 'c_uint', 'c_long',
  58. 'c_ulong', 'size_t', 'ptrdiff_t', 'clock_t', 'time_t', 'c_longlong',
  59. 'c_ulonglong', 'intptr_t', 'uintptr_t', 'off_t', 'dev_t', 'ino_t',
  60. 'pid_t', 'mode_t', 'ssize_t',
  61. ],
  62. constants: [
  63. 'true', 'false', 'Some', 'None', 'Left', 'Right', 'Ok', 'Err',
  64. ],
  65. supportConstants: [
  66. 'EXIT_FAILURE', 'EXIT_SUCCESS', 'RAND_MAX', 'EOF', 'SEEK_SET',
  67. 'SEEK_CUR', 'SEEK_END', '_IOFBF', '_IONBF', '_IOLBF', 'BUFSIZ',
  68. 'FOPEN_MAX', 'FILENAME_MAX', 'L_tmpnam', 'TMP_MAX', 'O_RDONLY',
  69. 'O_WRONLY', 'O_RDWR', 'O_APPEND', 'O_CREAT', 'O_EXCL', 'O_TRUNC',
  70. 'S_IFIFO', 'S_IFCHR', 'S_IFBLK', 'S_IFDIR', 'S_IFREG', 'S_IFMT',
  71. 'S_IEXEC', 'S_IWRITE', 'S_IREAD', 'S_IRWXU', 'S_IXUSR', 'S_IWUSR',
  72. 'S_IRUSR', 'F_OK', 'R_OK', 'W_OK', 'X_OK', 'STDIN_FILENO',
  73. 'STDOUT_FILENO', 'STDERR_FILENO',
  74. ],
  75. supportMacros: [
  76. 'format!', 'print!', 'println!', 'panic!', 'format_args!', 'unreachable!',
  77. 'write!', 'writeln!'
  78. ],
  79. operators: [
  80. '!', '!=', '%', '%=', '&', '&=', '&&', '*', '*=', '+', '+=', '-', '-=',
  81. '->', '.', '..', '...', '/', '/=', ':', ';', '<<', '<<=', '<', '<=', '=',
  82. '==', '=>', '>', '>=', '>>', '>>=', '@', '^', '^=', '|', '|=', '||', '_',
  83. '?', '#'
  84. ],
  85. escapes: /\\([nrt0\"''\\]|x\h{2}|u\{\h{1,6}\})/,
  86. delimiters: /[,]/,
  87. symbols: /[\#\!\%\&\*\+\-\.\/\:\;\<\=\>\@\^\|_\?]+/,
  88. intSuffixes: /[iu](8|16|32|64|128|size)/,
  89. floatSuffixes: /f(32|64)/,
  90. tokenizer: {
  91. root: [
  92. [/[a-zA-Z][a-zA-Z0-9_]*!?|_[a-zA-Z0-9_]+/,
  93. {
  94. cases: {
  95. '@typeKeywords': 'keyword.type',
  96. '@keywords': 'keyword',
  97. '@supportConstants': 'keyword',
  98. '@supportMacros': 'keyword',
  99. '@constants': 'keyword',
  100. '@default': 'identifier',
  101. }
  102. }
  103. ],
  104. // Designator
  105. [/\$/, 'identifier'],
  106. // Lifetime annotations
  107. [/'[a-zA-Z_][a-zA-Z0-9_]*(?=[^\'])/, 'identifier'],
  108. // Byte literal
  109. [/'\S'/, 'string.byteliteral'],
  110. // Strings
  111. [/"/, { token: 'string.quote', bracket: '@open', next: '@string' }],
  112. { include: '@numbers' },
  113. // Whitespace + comments
  114. { include: '@whitespace' },
  115. [/@delimiters/, {
  116. cases: {
  117. '@keywords': 'keyword',
  118. '@default': 'delimiter'
  119. }
  120. }],
  121. [/[{}()\[\]<>]/, '@brackets'],
  122. [/@symbols/, { cases: { '@operators': 'operator', '@default': '' } }],
  123. ],
  124. whitespace: [
  125. [/[ \t\r\n]+/, 'white'],
  126. [/\/\*/, 'comment', '@comment'],
  127. [/\/\/.*$/, 'comment'],
  128. ],
  129. comment: [
  130. [/[^\/*]+/, 'comment'],
  131. [/\/\*/, 'comment', '@push'],
  132. ["\\*/", 'comment', '@pop'],
  133. [/[\/*]/, 'comment']
  134. ],
  135. string: [
  136. [/[^\\"]+/, 'string'],
  137. [/@escapes/, 'string.escape'],
  138. [/\\./, 'string.escape.invalid'],
  139. [/"/, { token: 'string.quote', bracket: '@close', next: '@pop' }]
  140. ],
  141. numbers: [
  142. //Octal
  143. [/(0o[0-7_]+)(@intSuffixes)?/, { token: 'number' }],
  144. //Binary
  145. [/(0b[0-1_]+)(@intSuffixes)?/, { token: 'number' }],
  146. //Exponent
  147. [/[\d][\d_]*(\.[\d][\d_]*)?[eE][+-][\d_]+(@floatSuffixes)?/, { token: 'number' }],
  148. //Float
  149. [/\b(\d\.?[\d_]*)(@floatSuffixes)?\b/, { token: 'number' }],
  150. //Hexadecimal
  151. [/(0x[\da-fA-F]+)_?(@intSuffixes)?/, { token: 'number' }],
  152. //Integer
  153. [/[\d][\d_]*(@intSuffixes?)?/, { token: 'number' }],
  154. ]
  155. }
  156. };
  157. });