source: node_modules/highlight.js/lib/languages/rust.js@ 65b6638

main
Last change on this file since 65b6638 was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago

Initial commit

  • Property mode set to 100644
File size: 3.8 KB
Line 
1/*
2Language: Rust
3Author: Andrey Vlasovskikh <andrey.vlasovskikh@gmail.com>
4Contributors: Roman Shmatov <romanshmatov@gmail.com>, Kasper Andersen <kma_untrusted@protonmail.com>
5Website: https://www.rust-lang.org
6Category: common, system
7*/
8
9function rust(hljs) {
10 const NUM_SUFFIX = '([ui](8|16|32|64|128|size)|f(32|64))\?';
11 const 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 const 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('/\\*', '\\*/', {
52 contains: [ 'self' ]
53 }),
54 hljs.inherit(hljs.QUOTE_STRING_MODE, {
55 begin: /b?"/,
56 illegal: null
57 }),
58 {
59 className: 'string',
60 variants: [
61 {
62 begin: /r(#*)"(.|\n)*?"\1(?!#)/
63 },
64 {
65 begin: /b?'\\?(x\w{2}|u\w{4}|U\w{8}|.)'/
66 }
67 ]
68 },
69 {
70 className: 'symbol',
71 begin: /'[a-zA-Z_][a-zA-Z0-9_]*/
72 },
73 {
74 className: 'number',
75 variants: [
76 {
77 begin: '\\b0b([01_]+)' + NUM_SUFFIX
78 },
79 {
80 begin: '\\b0o([0-7_]+)' + NUM_SUFFIX
81 },
82 {
83 begin: '\\b0x([A-Fa-f0-9_]+)' + NUM_SUFFIX
84 },
85 {
86 begin: '\\b(\\d[\\d_]*(\\.[0-9_]+)?([eE][+-]?[0-9_]+)?)' +
87 NUM_SUFFIX
88 }
89 ],
90 relevance: 0
91 },
92 {
93 className: 'function',
94 beginKeywords: 'fn',
95 end: '(\\(|<)',
96 excludeEnd: true,
97 contains: [ hljs.UNDERSCORE_TITLE_MODE ]
98 },
99 {
100 className: 'meta',
101 begin: '#!?\\[',
102 end: '\\]',
103 contains: [
104 {
105 className: 'meta-string',
106 begin: /"/,
107 end: /"/
108 }
109 ]
110 },
111 {
112 className: 'class',
113 beginKeywords: 'type',
114 end: ';',
115 contains: [
116 hljs.inherit(hljs.UNDERSCORE_TITLE_MODE, {
117 endsParent: true
118 })
119 ],
120 illegal: '\\S'
121 },
122 {
123 className: 'class',
124 beginKeywords: 'trait enum struct union',
125 end: /\{/,
126 contains: [
127 hljs.inherit(hljs.UNDERSCORE_TITLE_MODE, {
128 endsParent: true
129 })
130 ],
131 illegal: '[\\w\\d]'
132 },
133 {
134 begin: hljs.IDENT_RE + '::',
135 keywords: {
136 built_in: BUILTINS
137 }
138 },
139 {
140 begin: '->'
141 }
142 ]
143 };
144}
145
146module.exports = rust;
Note: See TracBrowser for help on using the repository browser.