rust.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*
  2. Language: Rust
  3. Author: Andrey Vlasovskikh <[email protected]>
  4. Contributors: Roman Shmatov <[email protected]>
  5. Category: system
  6. */
  7. function(hljs) {
  8. var NUM_SUFFIX = '([uif](8|16|32|64|size))\?';
  9. var KEYWORDS =
  10. 'alignof as be box break const continue crate do else enum extern ' +
  11. 'false fn for if impl in let loop match mod mut offsetof once priv ' +
  12. 'proc pub pure ref return self Self sizeof static struct super trait true ' +
  13. 'type typeof unsafe unsized use virtual while where yield move default ' +
  14. 'int i8 i16 i32 i64 isize ' +
  15. 'uint u8 u32 u64 usize ' +
  16. 'float f32 f64 ' +
  17. 'str char bool'
  18. var BUILTINS =
  19. // prelude
  20. 'Copy Send Sized Sync Drop Fn FnMut FnOnce drop Box ToOwned Clone ' +
  21. 'PartialEq PartialOrd Eq Ord AsRef AsMut Into From Default Iterator ' +
  22. 'Extend IntoIterator DoubleEndedIterator ExactSizeIterator Option ' +
  23. 'Result SliceConcatExt String ToString Vec ' +
  24. // macros
  25. 'assert! assert_eq! bitflags! bytes! cfg! col! concat! concat_idents! ' +
  26. 'debug_assert! debug_assert_eq! env! panic! file! format! format_args! ' +
  27. 'include_bin! include_str! line! local_data_key! module_path! ' +
  28. 'option_env! print! println! select! stringify! try! unimplemented! ' +
  29. 'unreachable! vec! write! writeln! macro_rules!';
  30. return {
  31. aliases: ['rs'],
  32. keywords: {
  33. keyword:
  34. KEYWORDS,
  35. literal:
  36. 'true false Some None Ok Err',
  37. built_in:
  38. BUILTINS
  39. },
  40. lexemes: hljs.IDENT_RE + '!?',
  41. illegal: '</',
  42. contains: [
  43. hljs.C_LINE_COMMENT_MODE,
  44. hljs.COMMENT('/\\*', '\\*/', {contains: ['self']}),
  45. hljs.inherit(hljs.QUOTE_STRING_MODE, {begin: /b?"/, illegal: null}),
  46. {
  47. className: 'string',
  48. variants: [
  49. { begin: /r(#*)".*?"\1(?!#)/ },
  50. { begin: /b?'\\?(x\w{2}|u\w{4}|U\w{8}|.)'/ }
  51. ]
  52. },
  53. {
  54. className: 'symbol',
  55. begin: /'[a-zA-Z_][a-zA-Z0-9_]*/
  56. },
  57. {
  58. className: 'number',
  59. variants: [
  60. { begin: '\\b0b([01_]+)' + NUM_SUFFIX },
  61. { begin: '\\b0o([0-7_]+)' + NUM_SUFFIX },
  62. { begin: '\\b0x([A-Fa-f0-9_]+)' + NUM_SUFFIX },
  63. { begin: '\\b(\\d[\\d_]*(\\.[0-9_]+)?([eE][+-]?[0-9_]+)?)' +
  64. NUM_SUFFIX
  65. }
  66. ],
  67. relevance: 0
  68. },
  69. {
  70. className: 'function',
  71. beginKeywords: 'fn', end: '(\\(|<)', excludeEnd: true,
  72. contains: [hljs.UNDERSCORE_TITLE_MODE]
  73. },
  74. {
  75. className: 'meta',
  76. begin: '#\\!?\\[', end: '\\]',
  77. contains: [
  78. {
  79. className: 'meta-string',
  80. begin: /"/, end: /"/
  81. }
  82. ]
  83. },
  84. {
  85. className: 'class',
  86. beginKeywords: 'type', end: ';',
  87. contains: [
  88. hljs.inherit(hljs.UNDERSCORE_TITLE_MODE, {endsParent: true})
  89. ],
  90. illegal: '\\S'
  91. },
  92. {
  93. className: 'class',
  94. beginKeywords: 'trait enum struct', end: '{',
  95. contains: [
  96. hljs.inherit(hljs.UNDERSCORE_TITLE_MODE, {endsParent: true})
  97. ],
  98. illegal: '[\\w\\d]'
  99. },
  100. {
  101. begin: hljs.IDENT_RE + '::',
  102. keywords: {built_in: BUILTINS}
  103. },
  104. {
  105. begin: '->'
  106. }
  107. ]
  108. };
  109. }