Skip to content

Commit 9eb358b

Browse files
authored
Update Rust keywords/types (#419)
* Remove unreserved keywords * Add some newer keywords and types * Harden Rust lexer test
1 parent 9b3cf51 commit 9eb358b

File tree

3 files changed

+27
-4
lines changed

3 files changed

+27
-4
lines changed

Diff for: lexers/r/rust.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,15 @@ var Rust = internal.Register(MustNewLexer(
3131
{`r#*"(?:\\.|[^\\\r\n;])*"#*`, LiteralString, nil},
3232
{`"(?:\\.|[^\\\r\n"])*"`, LiteralString, nil},
3333
{`\$([a-zA-Z_]\w*|\(,?|\),?|,?)`, CommentPreproc, nil},
34-
{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},
35-
{Words(``, `\b`, `abstract`, `alignof`, `become`, `do`, `final`, `macro`, `offsetof`, `override`, `priv`, `proc`, `pure`, `sizeof`, `typeof`, `unsized`, `virtual`, `yield`), KeywordReserved, nil},
34+
{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},
35+
{Words(``, `\b`, `abstract`, `become`, `box`, `do`, `final`, `macro`, `override`, `priv`, `try`, `typeof`, `unsized`, `virtual`, `yield`), KeywordReserved, nil},
3636
{`(true|false)\b`, KeywordConstant, nil},
3737
{`mod\b`, Keyword, Push("modname")},
3838
{`let\b`, KeywordDeclaration, nil},
3939
{`fn\b`, Keyword, Push("funcname")},
4040
{`(struct|enum|type|union)\b`, Keyword, Push("typename")},
4141
{`(default)(\s+)(type|fn)\b`, ByGroups(Keyword, Text, Keyword), nil},
42-
{Words(``, `\b`, `u8`, `u16`, `u32`, `u64`, `i8`, `i16`, `i32`, `i64`, `usize`, `isize`, `f32`, `f64`, `str`, `bool`), KeywordType, nil},
42+
{Words(``, `\b`, `u8`, `u16`, `u32`, `u64`, `u128`, `i8`, `i16`, `i32`, `i64`, `i128`, `usize`, `isize`, `f32`, `f64`, `str`, `bool`), KeywordType, nil},
4343
{`self\b`, NameBuiltinPseudo, nil},
4444
{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},
4545
{`::\b`, Text, nil},

Diff for: lexers/testdata/rust.actual

+4-1
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@ struct Rectangle {
44
height: u32,
55
}
66

7+
async fn alignof() {}
8+
79
fn main() {
810
let rect1 = Rectangle { width: 30, height: 50 };
911

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

1315
let r#type = "valid";
14-
}
16+
let i: i128 = 1117;
17+
}

Diff for: lexers/testdata/rust.expected

+20
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,15 @@
1919
{"type":"TextWhitespace","value":"\n"},
2020
{"type":"Punctuation","value":"}"},
2121
{"type":"TextWhitespace","value":"\n\n"},
22+
{"type":"Keyword","value":"async"},
23+
{"type":"TextWhitespace","value":" "},
24+
{"type":"Keyword","value":"fn"},
25+
{"type":"Text","value":" "},
26+
{"type":"NameFunction","value":"alignof"},
27+
{"type":"Punctuation","value":"()"},
28+
{"type":"TextWhitespace","value":" "},
29+
{"type":"Punctuation","value":"{}"},
30+
{"type":"TextWhitespace","value":"\n\n"},
2231
{"type":"Keyword","value":"fn"},
2332
{"type":"Text","value":" "},
2433
{"type":"NameFunction","value":"main"},
@@ -66,6 +75,17 @@
6675
{"type":"TextWhitespace","value":" "},
6776
{"type":"LiteralString","value":"\"valid\""},
6877
{"type":"Punctuation","value":";"},
78+
{"type":"TextWhitespace","value":"\n "},
79+
{"type":"KeywordDeclaration","value":"let"},
80+
{"type":"TextWhitespace","value":" "},
81+
{"type":"Name","value":"i"},
82+
{"type":"Text","value":": "},
83+
{"type":"NameClass","value":"i128"},
84+
{"type":"TextWhitespace","value":" "},
85+
{"type":"Operator","value":"="},
86+
{"type":"TextWhitespace","value":" "},
87+
{"type":"LiteralNumberInteger","value":"1117"},
88+
{"type":"Punctuation","value":";"},
6989
{"type":"TextWhitespace","value":"\n"},
7090
{"type":"Punctuation","value":"}"},
7191
{"type":"TextWhitespace","value":"\n"}

0 commit comments

Comments
 (0)