From 9eb358bc3ff83f00328f08fa5634f931664eb409 Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Sat, 31 Oct 2020 06:01:35 +0900 Subject: [PATCH] Update Rust keywords/types (#419) * Remove unreserved keywords * Add some newer keywords and types * Harden Rust lexer test --- lexers/r/rust.go | 6 +++--- lexers/testdata/rust.actual | 5 ++++- lexers/testdata/rust.expected | 20 ++++++++++++++++++++ 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/lexers/r/rust.go b/lexers/r/rust.go index 191d1beca..959f11c25 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}, diff --git a/lexers/testdata/rust.actual b/lexers/testdata/rust.actual index 216415a6b..bd878c017 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 648d2fd92..491275294 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"}