eclipse-archived / golo-lang

Golo - a lightweight dynamic language for the JVM.
http://golo-lang.org/
Eclipse Public License 2.0
477 stars 91 forks source link

String interpolation #14

Open jponge opened 11 years ago

jponge commented 11 years ago

String interpolation is a nice feature found in modern languages, such as the following in Ruby:

name = "world"
str = "Hello #{name}!"
danielpetisme commented 11 years ago

Oups, Sorry for the duplication. I copyNpaste Let's interpole embeded expressions within a String. Here's a sample test

//Given
let answer  = 42
let what = "answer"

//When 
let sentence = "The ${what: toUpperCase()} is ${answer}"

//Then 
require(sentence == "The ANSWER is 42")

I think the variable interpolation is not that hard (IMHO) where an expresion could be tricky. Maybe we have to split this Specification in 2 (variable & expression)

Regarding the syntax, I dunno care. $ is the historical variable prefix (shell) but any symbol suit fine (Eg. #).

The brackets could be optionnal for variable but mandatory for expressions.

ggrossetie commented 10 years ago

I'm interested to work on this issue but I have no clue how ? I think I need to understand the JJT https://github.com/golo-lang/golo-lang/blob/master/src/main/jjtree/Golo.jjt ?

jponge commented 10 years ago

Yep

ggrossetie commented 10 years ago

nice feature found in modern languages

And also in PHP : https://java.net/downloads/javacc/contrib/grammars/php.jj :wink: