> Incidental white space surrounding the content, introduced to match the indentation of Java source code, is removed.
I like how Scala does this via the indent marker and strip.
https://openjdk.java.net/jeps/378
I'm not entirely sure "most sophisticated" is entirely a good thing - but the jep looks pretty thorough at least.
Ed: how does Scala do it? Java uses the indents for the closing triple-quote to determine stripping/indent + cutting trailing spaces. Ie, if my reading is correct:
a = """
OK.
"""
Is "OK.\n" (even if there are any spaces after the dot).So given that, I don't think it really ends up being that sophisticated. I think this could be a decent easy programming question for a technical interview though!
def pushConstant(num: Int): String =
s"""
|@$num
|D=A
|$accessTopOfStack
|M=D
|$incrementStackPointer
|""".stripMargin
accessTopOfStack and incrementStackPointer are other functions that return text. It made composing Assembly a breeze.At the same time I'm slightly scared of that magic. It helps that it's well-defined in the JEP.