Skip to content

Commit

Permalink
Update Rust keywords/types (#419)
Browse files Browse the repository at this point in the history
* Remove unreserved keywords

* Add some newer keywords and types

* Harden Rust lexer test
  • Loading branch information
JohnTitor committed Oct 30, 2020
1 parent 9b3cf51 commit 9eb358b
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
6 changes: 3 additions & 3 deletions lexers/r/rust.go
Expand Up @@ -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},
Expand Down
5 changes: 4 additions & 1 deletion lexers/testdata/rust.actual
Expand Up @@ -4,11 +4,14 @@ struct Rectangle {
height: u32,
}

async fn alignof() {}

fn main() {
let rect1 = Rectangle { width: 30, height: 50 };

// Some comment
println!("rect1 is {:?}", rect1);

let r#type = "valid";
}
let i: i128 = 1117;
}
20 changes: 20 additions & 0 deletions lexers/testdata/rust.expected
Expand Up @@ -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"},
Expand Down Expand Up @@ -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"}
Expand Down

0 comments on commit 9eb358b

Please sign in to comment.