From 863fe6bbec8a4b9a009f99e2d04544e781ce7617 Mon Sep 17 00:00:00 2001 From: Hugo Peixoto Date: Tue, 8 Sep 2020 02:46:16 +0100 Subject: [PATCH] Support tuple index expressions in Rust lexer (#1580) Currently, the Rust lexer does not support tuple index expressions. This commit adds that support. To differentiate between tuple index expressions and field access expressions, the `Name::Attribute` token is used. Co-authored-by: Michael Camilleri --- lib/rouge/lexers/rust.rb | 1 + spec/visual/samples/rust | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/lib/rouge/lexers/rust.rb b/lib/rouge/lexers/rust.rb index 54c1ce3e2b..893007ffd5 100644 --- a/lib/rouge/lexers/rust.rb +++ b/lib/rouge/lexers/rust.rb @@ -100,6 +100,7 @@ def macro_closed? rule %r/([.]\s*)?#{id}(?=\s*[(])/m, Name::Function rule %r/[.]\s*#{id}/, Name::Property + rule %r/[.]\s*\d+/, Name::Attribute rule %r/(#{id})(::)/m do groups Name::Namespace, Punctuation end diff --git a/spec/visual/samples/rust b/spec/visual/samples/rust index 21592f8df1..6be6ca5505 100644 --- a/spec/visual/samples/rust +++ b/spec/visual/samples/rust @@ -413,3 +413,8 @@ async fn learn_and_sing() { let song = learn_song().await; sing_song(song).await; } + +fn tuple_access() { + let t: (i32, i32) = (42, 13); + let f: t.0; +}