charly icon indicating copy to clipboard operation
charly copied to clipboard

String interpolation

Open KCreate opened this issue 9 years ago • 2 comments

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 avatar Dec 21 '16 09:12 KCreate

@KCreate I would keep the top one, because it saves us the (, ) and .to_s()

ghost avatar Apr 22 '17 07:04 ghost

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()

KCreate avatar Apr 22 '17 10:04 KCreate