From 55b0e59213e751884b579bb22b228d1b51717606 Mon Sep 17 00:00:00 2001 From: CosmicHorror Date: Sun, 29 Jan 2023 12:27:19 -0700 Subject: [PATCH] Rust: Attempt to lex constant idents (#741) --- lexers/embedded/rust.xml | 3 + lexers/testdata/rust/const_idents.actual | 10 +++ lexers/testdata/rust/const_idents.expected | 74 ++++++++++++++++++++++ 3 files changed, 87 insertions(+) create mode 100644 lexers/testdata/rust/const_idents.actual create mode 100644 lexers/testdata/rust/const_idents.expected diff --git a/lexers/embedded/rust.xml b/lexers/embedded/rust.xml index 1ee1413c8..2ae11b419 100644 --- a/lexers/embedded/rust.xml +++ b/lexers/embedded/rust.xml @@ -294,6 +294,9 @@ + + + diff --git a/lexers/testdata/rust/const_idents.actual b/lexers/testdata/rust/const_idents.actual new file mode 100644 index 000000000..119d4bbae --- /dev/null +++ b/lexers/testdata/rust/const_idents.actual @@ -0,0 +1,10 @@ +const IM_A_CONST: () = (); + +fn main() { + dbg!(IM_A_CONST); +} + +// None of this should be considered const +fn foo(_: (T0, T1, U)) { + let _: std::collections::BTreeSet<()> = todo!(); +} diff --git a/lexers/testdata/rust/const_idents.expected b/lexers/testdata/rust/const_idents.expected new file mode 100644 index 000000000..7808d45a5 --- /dev/null +++ b/lexers/testdata/rust/const_idents.expected @@ -0,0 +1,74 @@ +[ + {"type":"Keyword","value":"const"}, + {"type":"TextWhitespace","value":" "}, + {"type":"NameConstant","value":"IM_A_CONST"}, + {"type":"Text","value":": "}, + {"type":"Punctuation","value":"()"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"="}, + {"type":"TextWhitespace","value":" "}, + {"type":"Punctuation","value":"();"}, + {"type":"TextWhitespace","value":"\n\n"}, + {"type":"Keyword","value":"fn"}, + {"type":"Text","value":" "}, + {"type":"NameFunction","value":"main"}, + {"type":"Punctuation","value":"()"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Punctuation","value":"{"}, + {"type":"TextWhitespace","value":"\n "}, + {"type":"NameFunctionMagic","value":"dbg!"}, + {"type":"Punctuation","value":"("}, + {"type":"NameConstant","value":"IM_A_CONST"}, + {"type":"Punctuation","value":");"}, + {"type":"TextWhitespace","value":"\n"}, + {"type":"Punctuation","value":"}"}, + {"type":"TextWhitespace","value":"\n\n"}, + {"type":"CommentSingle","value":"// None of this should be considered const\n"}, + {"type":"Keyword","value":"fn"}, + {"type":"Text","value":" "}, + {"type":"NameFunction","value":"foo"}, + {"type":"Operator","value":"\u003c"}, + {"type":"Name","value":"T0"}, + {"type":"Punctuation","value":","}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"T1"}, + {"type":"Punctuation","value":","}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"U"}, + {"type":"Operator","value":"\u003e"}, + {"type":"Punctuation","value":"("}, + {"type":"Name","value":"_"}, + {"type":"Text","value":": "}, + {"type":"Punctuation","value":"("}, + {"type":"Name","value":"T0"}, + {"type":"Punctuation","value":","}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"T1"}, + {"type":"Punctuation","value":","}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"U"}, + {"type":"Punctuation","value":"))"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Punctuation","value":"{"}, + {"type":"TextWhitespace","value":"\n "}, + {"type":"KeywordDeclaration","value":"let"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"_"}, + {"type":"Text","value":": "}, + {"type":"NameClass","value":"std"}, + {"type":"Text","value":"::"}, + {"type":"Name","value":"collections"}, + {"type":"Text","value":"::"}, + {"type":"Name","value":"BTreeSet"}, + {"type":"Operator","value":"\u003c"}, + {"type":"Punctuation","value":"()"}, + {"type":"Operator","value":"\u003e"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"="}, + {"type":"TextWhitespace","value":" "}, + {"type":"NameFunctionMagic","value":"todo!"}, + {"type":"Punctuation","value":"();"}, + {"type":"TextWhitespace","value":"\n"}, + {"type":"Punctuation","value":"}"}, + {"type":"TextWhitespace","value":"\n"} +]