charly
charly copied to clipboard
String interpolation
let name = "world"
let message = "up"
"hello #{name} whats #{message} result: #{2 + 2 * 2}"
becomes:
"hello " + (name).to_s() + " whats " + (message).to_s() + " result: " + (2 + 2 * 2).to_s()
The parser will parse it as a StringInterpolationNode and a seperate transformation pass will do the rewriting.
@KCreate I would keep the top one, because it saves us the (, ) and .to_s()
Indeed, the top snippet is what this issue proposes. These snippets demonstrate how the parser would effectively transform the top snippet into the lower snippet.
"hello #{name}"
// gets rewritten by the parser to:
"hello " + (name).to_s()