Skip to content

Commit

Permalink
Rust: Improved type-definition and use standard tokens correctly (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
RunDevelopment committed Dec 10, 2021
1 parent e437325 commit 4049e5c
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 93 deletions.
5 changes: 2 additions & 3 deletions components/prism-rust.js
Expand Up @@ -27,8 +27,7 @@
},
'char': {
pattern: /b?'(?:\\(?:x[0-7][\da-fA-F]|u\{(?:[\da-fA-F]_*){1,6}\}|.)|[^\\\r\n\t'])'/,
greedy: true,
alias: 'string'
greedy: true
},
'attribute': {
pattern: /#!?\[(?:[^\[\]"]|"(?:\\[\s\S]|[^\\"])*")*\]/,
Expand Down Expand Up @@ -71,7 +70,7 @@
alias: 'function'
},
'type-definition': {
pattern: /(\b(?:enum|struct|union)\s+)\w+/,
pattern: /(\b(?:enum|struct|trait|type|union)\s+)\w+/,
lookbehind: true,
alias: 'class-name'
},
Expand Down
2 changes: 1 addition & 1 deletion components/prism-rust.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 34 additions & 1 deletion tests/languages/rust/class-name_feature.test
Expand Up @@ -16,6 +16,12 @@ enum Foo {
}
}

pub trait Summary {
fn summarize(&self) -> String;
}

type Point = (u8, u8);

----------------------------------------------------

[
Expand Down Expand Up @@ -91,7 +97,34 @@ enum Foo {

["punctuation", "}"],

["punctuation", "}"]
["punctuation", "}"],

["keyword", "pub"],
["keyword", "trait"],
["type-definition", "Summary"],
["punctuation", "{"],

["keyword", "fn"],
["function-definition", "summarize"],
["punctuation", "("],
["operator", "&"],
["keyword", "self"],
["punctuation", ")"],
["punctuation", "->"],
["class-name", "String"],
["punctuation", ";"],

["punctuation", "}"],

["keyword", "type"],
["type-definition", "Point"],
["operator", "="],
["punctuation", "("],
["keyword", "u8"],
["punctuation", ","],
["keyword", "u8"],
["punctuation", ")"],
["punctuation", ";"]
]

----------------------------------------------------
Expand Down
176 changes: 88 additions & 88 deletions tests/languages/rust/keyword_feature.test
@@ -1,107 +1,107 @@
abstract
as
async
await
become
box
break
const
continue
abstract;
as;
async;
await;
become;
box;
break;
const;
continue;
crate;
do
dyn
else
do;
dyn;
else;
enum;
extern
final
extern;
final;
fn;
for
if
impl
in
let
loop
macro
match
for;
if;
impl;
in;
let;
loop;
macro;
match;
mod;
move
mut
override
priv
pub
ref
return
self
Self
static
move;
mut;
override;
priv;
pub;
ref;
return;
self;
Self;
static;
struct;
super
trait
try
type
typeof
super;
trait;
try;
type;
typeof;
union;
unsafe
unsized
use
virtual
where
while
yield
unsafe;
unsized;
use;
virtual;
where;
while;
yield;

----------------------------------------------------

[
["keyword", "abstract"],
["keyword", "as"],
["keyword", "async"],
["keyword", "await"],
["keyword", "become"],
["keyword", "box"],
["keyword", "break"],
["keyword", "const"],
["keyword", "continue"],
["keyword", "abstract"], ["punctuation", ";"],
["keyword", "as"], ["punctuation", ";"],
["keyword", "async"], ["punctuation", ";"],
["keyword", "await"], ["punctuation", ";"],
["keyword", "become"], ["punctuation", ";"],
["keyword", "box"], ["punctuation", ";"],
["keyword", "break"], ["punctuation", ";"],
["keyword", "const"], ["punctuation", ";"],
["keyword", "continue"], ["punctuation", ";"],
["keyword", "crate"], ["punctuation", ";"],
["keyword", "do"],
["keyword", "dyn"],
["keyword", "else"],
["keyword", "do"], ["punctuation", ";"],
["keyword", "dyn"], ["punctuation", ";"],
["keyword", "else"], ["punctuation", ";"],
["keyword", "enum"], ["punctuation", ";"],
["keyword", "extern"],
["keyword", "final"],
["keyword", "extern"], ["punctuation", ";"],
["keyword", "final"], ["punctuation", ";"],
["keyword", "fn"], ["punctuation", ";"],
["keyword", "for"],
["keyword", "if"],
["keyword", "impl"],
["keyword", "in"],
["keyword", "let"],
["keyword", "loop"],
["keyword", "macro"],
["keyword", "match"],
["keyword", "for"], ["punctuation", ";"],
["keyword", "if"], ["punctuation", ";"],
["keyword", "impl"], ["punctuation", ";"],
["keyword", "in"], ["punctuation", ";"],
["keyword", "let"], ["punctuation", ";"],
["keyword", "loop"], ["punctuation", ";"],
["keyword", "macro"], ["punctuation", ";"],
["keyword", "match"], ["punctuation", ";"],
["keyword", "mod"], ["punctuation", ";"],
["keyword", "move"],
["keyword", "mut"],
["keyword", "override"],
["keyword", "priv"],
["keyword", "pub"],
["keyword", "ref"],
["keyword", "return"],
["keyword", "self"],
["keyword", "Self"],
["keyword", "static"],
["keyword", "move"], ["punctuation", ";"],
["keyword", "mut"], ["punctuation", ";"],
["keyword", "override"], ["punctuation", ";"],
["keyword", "priv"], ["punctuation", ";"],
["keyword", "pub"], ["punctuation", ";"],
["keyword", "ref"], ["punctuation", ";"],
["keyword", "return"], ["punctuation", ";"],
["keyword", "self"], ["punctuation", ";"],
["keyword", "Self"], ["punctuation", ";"],
["keyword", "static"], ["punctuation", ";"],
["keyword", "struct"], ["punctuation", ";"],
["keyword", "super"],
["keyword", "trait"],
["keyword", "try"],
["keyword", "type"],
["keyword", "typeof"],
["keyword", "super"], ["punctuation", ";"],
["keyword", "trait"], ["punctuation", ";"],
["keyword", "try"], ["punctuation", ";"],
["keyword", "type"], ["punctuation", ";"],
["keyword", "typeof"], ["punctuation", ";"],
["keyword", "union"], ["punctuation", ";"],
["keyword", "unsafe"],
["keyword", "unsized"],
["keyword", "use"],
["keyword", "virtual"],
["keyword", "where"],
["keyword", "while"],
["keyword", "yield"]
["keyword", "unsafe"], ["punctuation", ";"],
["keyword", "unsized"], ["punctuation", ";"],
["keyword", "use"], ["punctuation", ";"],
["keyword", "virtual"], ["punctuation", ";"],
["keyword", "where"], ["punctuation", ";"],
["keyword", "while"], ["punctuation", ";"],
["keyword", "yield"], ["punctuation", ";"]
]

----------------------------------------------------
Expand Down

0 comments on commit 4049e5c

Please sign in to comment.