l0bsterssg

node.js static responsive blog post generator
Log | Files | Refs | README

rust.js (3573B)


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