From 0ea650348768d5e1034650aabcd2c1a552c3c100 Mon Sep 17 00:00:00 2001 From: CosmicHorror Date: Sat, 28 Jan 2023 22:02:56 -0700 Subject: [PATCH] Rust: Include starting apostrophe in lifetime / loop label token (#739) --- lexers/embedded/rust.xml | 13 +- .../rust/lifetimes_and_loop_labels.actual | 16 +++ .../rust/lifetimes_and_loop_labels.expected | 117 ++++++++++++++++++ lexers/testdata/{ => rust}/rust.actual | 0 lexers/testdata/{ => rust}/rust.expected | 0 5 files changed, 141 insertions(+), 5 deletions(-) create mode 100644 lexers/testdata/rust/lifetimes_and_loop_labels.actual create mode 100644 lexers/testdata/rust/lifetimes_and_loop_labels.expected rename lexers/testdata/{ => rust}/rust.actual (100%) rename lexers/testdata/{ => rust}/rust.expected (100%) diff --git a/lexers/embedded/rust.xml b/lexers/embedded/rust.xml index 0df59167f..bd3da6f72 100644 --- a/lexers/embedded/rust.xml +++ b/lexers/embedded/rust.xml @@ -23,9 +23,6 @@ - - - @@ -281,8 +278,11 @@ + + + - + @@ -315,8 +315,11 @@ + + + - + diff --git a/lexers/testdata/rust/lifetimes_and_loop_labels.actual b/lexers/testdata/rust/lifetimes_and_loop_labels.actual new file mode 100644 index 000000000..89664eeef --- /dev/null +++ b/lexers/testdata/rust/lifetimes_and_loop_labels.actual @@ -0,0 +1,16 @@ +struct Bar<'b>(&'b str); + +struct Foo<'b, 'a: 'b>(&'a Bar<'b>); + +fn foo<'some_name>(_: Bar<'_>, _: impl Iterator> + 'static) { + 'im_a_loop_label: loop { + break 'im_a_loop_label; + } + + // None of these should have lifetimes + let _ = 'a'; + let _ = b'a'; + let _ = " + 'not_a_lifetime_or_label + "; +} diff --git a/lexers/testdata/rust/lifetimes_and_loop_labels.expected b/lexers/testdata/rust/lifetimes_and_loop_labels.expected new file mode 100644 index 000000000..eec431f0d --- /dev/null +++ b/lexers/testdata/rust/lifetimes_and_loop_labels.expected @@ -0,0 +1,117 @@ +[ + {"type":"Keyword","value":"struct"}, + {"type":"Text","value":" "}, + {"type":"NameClass","value":"Bar"}, + {"type":"Operator","value":"\u003c"}, + {"type":"NameAttribute","value":"'b"}, + {"type":"Operator","value":"\u003e"}, + {"type":"Punctuation","value":"("}, + {"type":"Operator","value":"\u0026"}, + {"type":"NameAttribute","value":"'b"}, + {"type":"TextWhitespace","value":" "}, + {"type":"KeywordType","value":"str"}, + {"type":"Punctuation","value":");"}, + {"type":"TextWhitespace","value":"\n\n"}, + {"type":"Keyword","value":"struct"}, + {"type":"Text","value":" "}, + {"type":"NameClass","value":"Foo"}, + {"type":"Operator","value":"\u003c"}, + {"type":"NameAttribute","value":"'b"}, + {"type":"Punctuation","value":","}, + {"type":"TextWhitespace","value":" "}, + {"type":"NameAttribute","value":"'a"}, + {"type":"Text","value":": "}, + {"type":"NameAttribute","value":"'b"}, + {"type":"Operator","value":"\u003e"}, + {"type":"Punctuation","value":"("}, + {"type":"Operator","value":"\u0026"}, + {"type":"NameAttribute","value":"'a"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"Bar"}, + {"type":"Operator","value":"\u003c"}, + {"type":"NameAttribute","value":"'b"}, + {"type":"Operator","value":"\u003e"}, + {"type":"Punctuation","value":");"}, + {"type":"TextWhitespace","value":"\n\n"}, + {"type":"Keyword","value":"fn"}, + {"type":"Text","value":" "}, + {"type":"NameFunction","value":"foo"}, + {"type":"Operator","value":"\u003c"}, + {"type":"NameAttribute","value":"'some_name"}, + {"type":"Operator","value":"\u003e"}, + {"type":"Punctuation","value":"("}, + {"type":"Name","value":"_"}, + {"type":"Text","value":": "}, + {"type":"NameClass","value":"Bar"}, + {"type":"Operator","value":"\u003c"}, + {"type":"NameBuiltin","value":"'_"}, + {"type":"Operator","value":"\u003e"}, + {"type":"Punctuation","value":","}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"_"}, + {"type":"Text","value":": "}, + {"type":"NameClass","value":"impl"}, + {"type":"TextWhitespace","value":" "}, + {"type":"NameBuiltin","value":"Iterator"}, + {"type":"Operator","value":"\u003c"}, + {"type":"Name","value":"Item"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"="}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"Bar"}, + {"type":"Operator","value":"\u003c"}, + {"type":"NameBuiltin","value":"'static"}, + {"type":"Operator","value":"\u003e\u003e"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"+"}, + {"type":"TextWhitespace","value":" "}, + {"type":"NameBuiltin","value":"'static"}, + {"type":"Punctuation","value":")"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Punctuation","value":"{"}, + {"type":"TextWhitespace","value":"\n "}, + {"type":"NameAttribute","value":"'im_a_loop_label"}, + {"type":"Text","value":": "}, + {"type":"NameClass","value":"loop"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Punctuation","value":"{"}, + {"type":"TextWhitespace","value":"\n "}, + {"type":"Keyword","value":"break"}, + {"type":"TextWhitespace","value":" "}, + {"type":"NameLabel","value":"'im_a_loop_label"}, + {"type":"Punctuation","value":";"}, + {"type":"TextWhitespace","value":"\n "}, + {"type":"Punctuation","value":"}"}, + {"type":"TextWhitespace","value":"\n\n "}, + {"type":"CommentSingle","value":"// None of these should have lifetimes\n"}, + {"type":"TextWhitespace","value":" "}, + {"type":"KeywordDeclaration","value":"let"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"_"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"="}, + {"type":"TextWhitespace","value":" "}, + {"type":"LiteralStringChar","value":"'a'"}, + {"type":"Punctuation","value":";"}, + {"type":"TextWhitespace","value":"\n "}, + {"type":"KeywordDeclaration","value":"let"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"_"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"="}, + {"type":"TextWhitespace","value":" "}, + {"type":"Error","value":"b'a'"}, + {"type":"Punctuation","value":";"}, + {"type":"TextWhitespace","value":"\n "}, + {"type":"KeywordDeclaration","value":"let"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"_"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"="}, + {"type":"TextWhitespace","value":" "}, + {"type":"LiteralString","value":"\"\n 'not_a_lifetime_or_label\n \""}, + {"type":"Punctuation","value":";"}, + {"type":"TextWhitespace","value":"\n"}, + {"type":"Punctuation","value":"}"}, + {"type":"TextWhitespace","value":"\n"} +] diff --git a/lexers/testdata/rust.actual b/lexers/testdata/rust/rust.actual similarity index 100% rename from lexers/testdata/rust.actual rename to lexers/testdata/rust/rust.actual diff --git a/lexers/testdata/rust.expected b/lexers/testdata/rust/rust.expected similarity index 100% rename from lexers/testdata/rust.expected rename to lexers/testdata/rust/rust.expected