diff --git a/lexers/embedded/rust.xml b/lexers/embedded/rust.xml index f2d7a52f4..083b96ffe 100644 --- a/lexers/embedded/rust.xml +++ b/lexers/embedded/rust.xml @@ -105,6 +105,24 @@ + + + + + + + + + + + + + + + + + + @@ -294,6 +312,16 @@ + + + + + + + + + + diff --git a/lexers/testdata/rust/rust.expected b/lexers/testdata/rust/rust.expected index 72d425972..b64cb952d 100644 --- a/lexers/testdata/rust/rust.expected +++ b/lexers/testdata/rust/rust.expected @@ -60,7 +60,9 @@ {"type":"TextWhitespace","value":" "}, {"type":"NameFunctionMagic","value":"println!"}, {"type":"Punctuation","value":"("}, - {"type":"LiteralString","value":"\"rect1 is {:?}\""}, + {"type":"LiteralString","value":"\"rect1 is "}, + {"type":"LiteralStringInterpol","value":"{:?}"}, + {"type":"LiteralString","value":"\""}, {"type":"Punctuation","value":","}, {"type":"TextWhitespace","value":" "}, {"type":"Name","value":"rect1"}, diff --git a/lexers/testdata/rust/string_interpol.actual b/lexers/testdata/rust/string_interpol.actual new file mode 100644 index 000000000..e299612ab --- /dev/null +++ b/lexers/testdata/rust/string_interpol.actual @@ -0,0 +1,29 @@ +fn main() { + let foo = 'x'; + + println!( + " + Kitchen sink + {{ }} - Escaped + {{{}}} - Escaped with inner interpol + {foo:#?} - Ident with pretty debug format + {0:-<5} - Positional with complex fill/alignment + ", + foo, + ); + + // Unconventional formatting + println! ( "Hello, {foo}!"); + + // Exhausting the supported macros + eprintln!("{foo}"); + eprint!("{foo}"); + println!("{foo}"); + print!("{foo}"); + format!("{foo}"); + format_args!("{foo}"); + panic!("{foo}"); + todo!("{foo}"); + unreachable!("{foo}"); + unimplemented!("{foo}"); +} diff --git a/lexers/testdata/rust/string_interpol.expected b/lexers/testdata/rust/string_interpol.expected new file mode 100644 index 000000000..e514c1047 --- /dev/null +++ b/lexers/testdata/rust/string_interpol.expected @@ -0,0 +1,126 @@ +[ + {"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":"KeywordDeclaration","value":"let"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"foo"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"="}, + {"type":"TextWhitespace","value":" "}, + {"type":"LiteralStringChar","value":"'x'"}, + {"type":"Punctuation","value":";"}, + {"type":"TextWhitespace","value":"\n\n "}, + {"type":"NameFunctionMagic","value":"println!"}, + {"type":"Punctuation","value":"("}, + {"type":"TextWhitespace","value":"\n "}, + {"type":"LiteralString","value":"\"\n Kitchen sink\n "}, + {"type":"LiteralStringEscape","value":"{{"}, + {"type":"LiteralString","value":" "}, + {"type":"LiteralStringEscape","value":"}}"}, + {"type":"LiteralString","value":" - Escaped\n "}, + {"type":"LiteralStringEscape","value":"{{"}, + {"type":"LiteralStringInterpol","value":"{}"}, + {"type":"LiteralStringEscape","value":"}}"}, + {"type":"LiteralString","value":" - Escaped with inner interpol\n "}, + {"type":"LiteralStringInterpol","value":"{foo:#?}"}, + {"type":"LiteralString","value":" - Ident with pretty debug format\n "}, + {"type":"LiteralStringInterpol","value":"{0:-\u003c5}"}, + {"type":"LiteralString","value":" - Positional with complex fill/alignment\n \""}, + {"type":"Punctuation","value":","}, + {"type":"TextWhitespace","value":"\n "}, + {"type":"Name","value":"foo"}, + {"type":"Punctuation","value":","}, + {"type":"TextWhitespace","value":"\n "}, + {"type":"Punctuation","value":");"}, + {"type":"TextWhitespace","value":"\n\n "}, + {"type":"CommentSingle","value":"// Unconventional formatting\n"}, + {"type":"TextWhitespace","value":" "}, + {"type":"NameFunctionMagic","value":"println!"}, + {"type":"TextWhitespace","value":"\t"}, + {"type":"Punctuation","value":"("}, + {"type":"TextWhitespace","value":"\t"}, + {"type":"LiteralString","value":"\"Hello, "}, + {"type":"LiteralStringInterpol","value":"{foo}"}, + {"type":"LiteralString","value":"!\""}, + {"type":"Punctuation","value":");"}, + {"type":"TextWhitespace","value":"\n\n "}, + {"type":"CommentSingle","value":"// Exhausting the supported macros\n"}, + {"type":"TextWhitespace","value":" "}, + {"type":"NameFunctionMagic","value":"eprintln!"}, + {"type":"Punctuation","value":"("}, + {"type":"LiteralString","value":"\""}, + {"type":"LiteralStringInterpol","value":"{foo}"}, + {"type":"LiteralString","value":"\""}, + {"type":"Punctuation","value":");"}, + {"type":"TextWhitespace","value":"\n "}, + {"type":"NameFunctionMagic","value":"eprint!"}, + {"type":"Punctuation","value":"("}, + {"type":"LiteralString","value":"\""}, + {"type":"LiteralStringInterpol","value":"{foo}"}, + {"type":"LiteralString","value":"\""}, + {"type":"Punctuation","value":");"}, + {"type":"TextWhitespace","value":"\n "}, + {"type":"NameFunctionMagic","value":"println!"}, + {"type":"Punctuation","value":"("}, + {"type":"LiteralString","value":"\""}, + {"type":"LiteralStringInterpol","value":"{foo}"}, + {"type":"LiteralString","value":"\""}, + {"type":"Punctuation","value":");"}, + {"type":"TextWhitespace","value":"\n "}, + {"type":"NameFunctionMagic","value":"print!"}, + {"type":"Punctuation","value":"("}, + {"type":"LiteralString","value":"\""}, + {"type":"LiteralStringInterpol","value":"{foo}"}, + {"type":"LiteralString","value":"\""}, + {"type":"Punctuation","value":");"}, + {"type":"TextWhitespace","value":"\n "}, + {"type":"NameFunctionMagic","value":"format!"}, + {"type":"Punctuation","value":"("}, + {"type":"LiteralString","value":"\""}, + {"type":"LiteralStringInterpol","value":"{foo}"}, + {"type":"LiteralString","value":"\""}, + {"type":"Punctuation","value":");"}, + {"type":"TextWhitespace","value":"\n "}, + {"type":"NameFunctionMagic","value":"format_args!"}, + {"type":"Punctuation","value":"("}, + {"type":"LiteralString","value":"\""}, + {"type":"LiteralStringInterpol","value":"{foo}"}, + {"type":"LiteralString","value":"\""}, + {"type":"Punctuation","value":");"}, + {"type":"TextWhitespace","value":"\n "}, + {"type":"NameFunctionMagic","value":"panic!"}, + {"type":"Punctuation","value":"("}, + {"type":"LiteralString","value":"\""}, + {"type":"LiteralStringInterpol","value":"{foo}"}, + {"type":"LiteralString","value":"\""}, + {"type":"Punctuation","value":");"}, + {"type":"TextWhitespace","value":"\n "}, + {"type":"NameFunctionMagic","value":"todo!"}, + {"type":"Punctuation","value":"("}, + {"type":"LiteralString","value":"\""}, + {"type":"LiteralStringInterpol","value":"{foo}"}, + {"type":"LiteralString","value":"\""}, + {"type":"Punctuation","value":");"}, + {"type":"TextWhitespace","value":"\n "}, + {"type":"NameFunctionMagic","value":"unreachable!"}, + {"type":"Punctuation","value":"("}, + {"type":"LiteralString","value":"\""}, + {"type":"LiteralStringInterpol","value":"{foo}"}, + {"type":"LiteralString","value":"\""}, + {"type":"Punctuation","value":");"}, + {"type":"TextWhitespace","value":"\n "}, + {"type":"NameFunctionMagic","value":"unimplemented!"}, + {"type":"Punctuation","value":"("}, + {"type":"LiteralString","value":"\""}, + {"type":"LiteralStringInterpol","value":"{foo}"}, + {"type":"LiteralString","value":"\""}, + {"type":"Punctuation","value":");"}, + {"type":"TextWhitespace","value":"\n"}, + {"type":"Punctuation","value":"}"}, + {"type":"TextWhitespace","value":"\n"} +]