biofriction-wp-theme/node_modules/highlight.js/lib/languages/rust.js

85 lines
2.8 KiB
JavaScript

module.exports = function(hljs) {
var NUM_SUFFIX = '([uif](8|16|32|64|size))\?';
var BLOCK_COMMENT = hljs.inherit(hljs.C_BLOCK_COMMENT_MODE);
BLOCK_COMMENT.contains.push('self');
return {
aliases: ['rs'],
keywords: {
keyword:
'alignof as be box break const continue crate do else enum extern ' +
'false fn for if impl in let loop match mod mut offsetof once priv ' +
'proc pub pure ref return self Self sizeof static struct super trait true ' +
'type typeof unsafe unsized use virtual while where yield ' +
'int i8 i16 i32 i64 ' +
'uint u8 u32 u64 ' +
'float f32 f64 ' +
'str char bool',
built_in:
// prelude
'Copy Send Sized Sync Drop Fn FnMut FnOnce drop Box ToOwned Clone ' +
'PartialEq PartialOrd Eq Ord AsRef AsMut Into From Default Iterator ' +
'Extend IntoIterator DoubleEndedIterator ExactSizeIterator Option ' +
'Some None Result Ok Err SliceConcatExt String ToString Vec ' +
// macros
'assert! assert_eq! bitflags! bytes! cfg! col! concat! concat_idents! ' +
'debug_assert! debug_assert_eq! env! panic! file! format! format_args! ' +
'include_bin! include_str! line! local_data_key! module_path! ' +
'option_env! print! println! select! stringify! try! unimplemented! ' +
'unreachable! vec! write! writeln!'
},
lexemes: hljs.IDENT_RE + '!?',
illegal: '</',
contains: [
hljs.C_LINE_COMMENT_MODE,
BLOCK_COMMENT,
hljs.inherit(hljs.QUOTE_STRING_MODE, {illegal: null}),
{
className: 'string',
variants: [
{ begin: /r(#*)".*?"\1(?!#)/ },
{ begin: /'\\?(x\w{2}|u\w{4}|U\w{8}|.)'/ },
{ begin: /'[a-zA-Z_][a-zA-Z0-9_]*/ }
]
},
{
className: 'number',
variants: [
{ begin: '\\b0b([01_]+)' + NUM_SUFFIX },
{ begin: '\\b0o([0-7_]+)' + NUM_SUFFIX },
{ begin: '\\b0x([A-Fa-f0-9_]+)' + NUM_SUFFIX },
{ begin: '\\b(\\d[\\d_]*(\\.[0-9_]+)?([eE][+-]?[0-9_]+)?)' +
NUM_SUFFIX
}
],
relevance: 0
},
{
className: 'function',
beginKeywords: 'fn', end: '(\\(|<)', excludeEnd: true,
contains: [hljs.UNDERSCORE_TITLE_MODE]
},
{
className: 'preprocessor',
begin: '#\\!?\\[', end: '\\]'
},
{
beginKeywords: 'type', end: '(=|<)',
contains: [hljs.UNDERSCORE_TITLE_MODE],
illegal: '\\S'
},
{
beginKeywords: 'trait enum', end: '{',
contains: [
hljs.inherit(hljs.UNDERSCORE_TITLE_MODE, {endsParent: true})
],
illegal: '[\\w\\d]'
},
{
begin: hljs.IDENT_RE + '::'
},
{
begin: '->'
}
]
};
};