-
-
Notifications
You must be signed in to change notification settings - Fork 401
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rust: Add initial support for string interpolation
- Loading branch information
1 parent
f5f48e2
commit 4bfa1bb
Showing
4 changed files
with
186 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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}"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"} | ||
] |