Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 22 additions & 11 deletions src/languages/rust.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default function(hljs) {
const IDENT_RE = regex.concat(RAW_IDENTIFIER, hljs.IDENT_RE);
// ============================================
const FUNCTION_INVOKE = {
className: "title.function.invoke",
scope: "title.function.invoke",
relevance: 0,
begin: regex.concat(
/\b/,
Expand Down Expand Up @@ -199,7 +199,7 @@ export default function(hljs) {
illegal: null
}),
{
className: 'symbol',
scope: 'symbol',
// negative lookahead to avoid matching `'`
begin: /'[a-zA-Z_][a-zA-Z0-9_]*(?!')/
},
Expand All @@ -220,7 +220,7 @@ export default function(hljs) {
]
},
{
className: 'number',
scope: 'number',
variants: [
{ begin: '\\b0b([01_]+)' + NUMBER_SUFFIX },
{ begin: '\\b0o([0-7_]+)' + NUMBER_SUFFIX },
Expand All @@ -230,24 +230,35 @@ export default function(hljs) {
],
relevance: 0
},
{
begin: [
/\bsafe/,
/\s+/,
/extern/,
],
scope: {
1: "keyword",
3: "keyword",
}
},
{
begin: [
/fn/,
/\s+/,
UNDERSCORE_IDENT_RE
],
className: {
scope: {
1: "keyword",
3: "title.function"
}
},
{
className: 'meta',
scope: 'meta',
begin: '#!?\\[',
end: '\\]',
contains: [
{
className: 'string',
scope: 'string',
begin: /"/,
end: /"/,
contains: [
Expand All @@ -263,7 +274,7 @@ export default function(hljs) {
/(?:mut\s+)?/,
UNDERSCORE_IDENT_RE
],
className: {
scope: {
1: "keyword",
3: "keyword",
4: "variable"
Expand All @@ -278,7 +289,7 @@ export default function(hljs) {
/\s+/,
/in/
],
className: {
scope: {
1: "keyword",
3: "variable",
5: "keyword"
Expand All @@ -290,7 +301,7 @@ export default function(hljs) {
/\s+/,
UNDERSCORE_IDENT_RE
],
className: {
scope: {
1: "keyword",
3: "title.class"
}
Expand All @@ -301,7 +312,7 @@ export default function(hljs) {
/\s+/,
UNDERSCORE_IDENT_RE
],
className: {
scope: {
1: "keyword",
3: "title.class"
}
Expand All @@ -315,7 +326,7 @@ export default function(hljs) {
}
},
{
className: "punctuation",
scope: "punctuation",
begin: '->'
},
FUNCTION_INVOKE
Expand Down
4 changes: 4 additions & 0 deletions test/markup/rust/extern.expect.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<span class="hljs-keyword">unsafe</span> <span class="hljs-keyword">extern</span> <span class="hljs-string">&quot;C&quot;</span> {
<span class="hljs-keyword">unsafe</span> <span class="hljs-keyword">fn</span> <span class="hljs-title function_">foo</span>();
safe <span class="hljs-keyword">fn</span> <span class="hljs-title function_">foo</span>();
}
4 changes: 4 additions & 0 deletions test/markup/rust/extern.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
unsafe extern "C" {
unsafe fn foo();
safe fn foo();
}