Repository: alecthomas/chroma
Pull request #419 (2020-10-30 20:34:12)

Update Rust keywords/types
The current keywords/types for Rust are outdated a bit, the latest items can be seen here: https://doc.rust-lang.org/nightly/reference/keywords.html
For instance, chroma doesn't recognize `async/await` keywords currently.


Patch:
diff --git a/lexers/r/rust.go b/lexers/r/rust.go
index 191d1be..959f11c 100644
--- a/lexers/r/rust.go
+++ b/lexers/r/rust.go
@@ -31,15 +31,15 @@ var Rust = internal.Register(MustNewLexer(
 			{`r#*"(?:\\.|[^\\\r\n;])*"#*`, LiteralString, nil},
 			{`"(?:\\.|[^\\\r\n"])*"`, LiteralString, nil},
 			{`\$([a-zA-Z_]\w*|\(,?|\),?|,?)`, CommentPreproc, nil},
-			{Words(``, `\b`, `as`, `box`, `const`, `crate`, `else`, `extern`, `for`, `if`, `impl`, `in`, `loop`, `match`, `move`, `mut`, `pub`, `ref`, `return`, `static`, `super`, `trait`, `unsafe`, `use`, `where`, `while`), Keyword, nil},
-			{Words(``, `\b`, `abstract`, `alignof`, `become`, `do`, `final`, `macro`, `offsetof`, `override`, `priv`, `proc`, `pure`, `sizeof`, `typeof`, `unsized`, `virtual`, `yield`), KeywordReserved, nil},
+			{Words(``, `\b`, `as`, `async`, `await`, `const`, `crate`, `else`, `extern`, `for`, `if`, `impl`, `in`, `loop`, `match`, `move`, `mut`, `pub`, `ref`, `return`, `static`, `super`, `trait`, `unsafe`, `use`, `where`, `while`), Keyword, nil},
+			{Words(``, `\b`, `abstract`, `become`, `box`, `do`, `final`, `macro`, `override`, `priv`, `try`, `typeof`, `unsized`, `virtual`, `yield`), KeywordReserved, nil},
 			{`(true|false)\b`, KeywordConstant, nil},
 			{`mod\b`, Keyword, Push("modname")},
 			{`let\b`, KeywordDeclaration, nil},
 			{`fn\b`, Keyword, Push("funcname")},
 			{`(struct|enum|type|union)\b`, Keyword, Push("typename")},
 			{`(default)(\s+)(type|fn)\b`, ByGroups(Keyword, Text, Keyword), nil},
-			{Words(``, `\b`, `u8`, `u16`, `u32`, `u64`, `i8`, `i16`, `i32`, `i64`, `usize`, `isize`, `f32`, `f64`, `str`, `bool`), KeywordType, nil},
+			{Words(``, `\b`, `u8`, `u16`, `u32`, `u64`, `u128`, `i8`, `i16`, `i32`, `i64`, `i128`, `usize`, `isize`, `f32`, `f64`, `str`, `bool`), KeywordType, nil},
 			{`self\b`, NameBuiltinPseudo, nil},
 			{Words(``, `\b`, `Copy`, `Send`, `Sized`, `Sync`, `Drop`, `Fn`, `FnMut`, `FnOnce`, `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`), NameBuiltin, nil},
 			{`::\b`, Text, nil},


Test patch:
diff --git a/lexers/testdata/rust.actual b/lexers/testdata/rust.actual
index 216415a..bd878c0 100644
--- a/lexers/testdata/rust.actual
+++ b/lexers/testdata/rust.actual
@@ -4,6 +4,8 @@ struct Rectangle {
     height: u32,
 }
 
+async fn alignof() {}
+
 fn main() {
     let rect1 = Rectangle { width: 30, height: 50 };
 
@@ -11,4 +13,5 @@ fn main() {
     println!("rect1 is {:?}", rect1);
 
     let r#type = "valid";
-}
\ No newline at end of file
+    let i: i128 = 1117;
+}
diff --git a/lexers/testdata/rust.expected b/lexers/testdata/rust.expected
index 648d2fd..4912752 100644
--- a/lexers/testdata/rust.expected
+++ b/lexers/testdata/rust.expected
@@ -19,6 +19,15 @@
   {"type":"TextWhitespace","value":"\n"},
   {"type":"Punctuation","value":"}"},
   {"type":"TextWhitespace","value":"\n\n"},
+  {"type":"Keyword","value":"async"},
+  {"type":"TextWhitespace","value":" "},
+  {"type":"Keyword","value":"fn"},
+  {"type":"Text","value":" "},
+  {"type":"NameFunction","value":"alignof"},
+  {"type":"Punctuation","value":"()"},
+  {"type":"TextWhitespace","value":" "},
+  {"type":"Punctuation","value":"{}"},
+  {"type":"TextWhitespace","value":"\n\n"},
   {"type":"Keyword","value":"fn"},
   {"type":"Text","value":" "},
   {"type":"NameFunction","value":"main"},
@@ -66,6 +75,17 @@
   {"type":"TextWhitespace","value":" "},
   {"type":"LiteralString","value":"\"valid\""},
   {"type":"Punctuation","value":";"},
+  {"type":"TextWhitespace","value":"\n    "},
+  {"type":"KeywordDeclaration","value":"let"},
+  {"type":"TextWhitespace","value":" "},
+  {"type":"Name","value":"i"},
+  {"type":"Text","value":": "},
+  {"type":"NameClass","value":"i128"},
+  {"type":"TextWhitespace","value":" "},
+  {"type":"Operator","value":"="},
+  {"type":"TextWhitespace","value":" "},
+  {"type":"LiteralNumberInteger","value":"1117"},
+  {"type":"Punctuation","value":";"},
   {"type":"TextWhitespace","value":"\n"},
   {"type":"Punctuation","value":"}"},
   {"type":"TextWhitespace","value":"\n"}