#81 String literals

brian Sun 4 Jun 2006

I changed the tokenizer to allow string literals to span more than one line:

src := "
  Int f()
  {
    return 3
  }"

andy Mon 5 Jun 2006

So are newlines part of the string?

src := "\nInt f()\n{\n.." // is this equiv?

And how is leading whitespace treated?

"Int f()" or "  Int f()" 

brian Mon 5 Jun 2006

Whitespace is significant

brian Mon 5 Jun 2006

I have string interpolation working! You can embed arbitrary expressions inside a string literal using ${}. Use \$ to get an actual dollar sign. I also allow a shortcut to leave off the {} for dotted identifiers:

x := 15
"\$x"      -> $x
"$x"       -> 15
"$x.toHex" -> f
"$x+2"     -> 15+2
"${x+2}"   -> 17

The implementation is based on the tokenizer creating virtual tokens to make interpolation look like long hand:

"foo${x+2}bar" -> "foo" + (x+2) + "bar"

Login or Signup to reply.