Skip to content

Commit

Permalink
rust: support raw identifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
fasterthanlime authored and alecthomas committed Jan 9, 2020
1 parent 9e22bd6 commit 0f6a31d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lexers/r/rust.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ var Rust = internal.Register(MustNewLexer(
{`'[a-zA-Z_]\w*`, NameAttribute, nil},
{`[{}()\[\],.;]`, Punctuation, nil},
{`[+\-*/%&|<>^!~@=:?]`, Operator, nil},
{`[a-zA-Z_]\w*`, Name, nil},
{`(r#)?[a-zA-Z_]\w*`, Name, nil},
{`#!?\[`, CommentPreproc, Push("attribute[")},
{`([A-Za-z_]\w*)(!)(\s*)([A-Za-z_]\w*)?(\s*)(\{)`, ByGroups(CommentPreproc, Punctuation, TextWhitespace, Name, TextWhitespace, Punctuation), Push("macro{")},
{`([A-Za-z_]\w*)(!)(\s*)([A-Za-z_]\w*)?(\()`, ByGroups(CommentPreproc, Punctuation, TextWhitespace, Name, Punctuation), Push("macro(")},
Expand Down
2 changes: 2 additions & 0 deletions lexers/testdata/rust.actual
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ fn main() {

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

let r#type = "valid";
}
9 changes: 9 additions & 0 deletions lexers/testdata/rust.expected
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,15 @@
{"type":"TextWhitespace","value":" "},
{"type":"Name","value":"rect1"},
{"type":"Punctuation","value":");"},
{"type":"TextWhitespace","value":"\n\n "},
{"type":"KeywordDeclaration","value":"let"},
{"type":"TextWhitespace","value":" "},
{"type":"Name","value":"r#type"},
{"type":"TextWhitespace","value":" "},
{"type":"Operator","value":"="},
{"type":"TextWhitespace","value":" "},
{"type":"LiteralString","value":"\"valid\""},
{"type":"Punctuation","value":";"},
{"type":"TextWhitespace","value":"\n"},
{"type":"Punctuation","value":"}"},
{"type":"TextWhitespace","value":"\n"}
Expand Down

0 comments on commit 0f6a31d

Please sign in to comment.