jashkenas / coffeescript

Unfancy JavaScript
https://coffeescript.org/
MIT License
16.49k stars 1.98k forks source link

Expand string interpolation expressions into dedicated AST #4192

Closed flying-sheep closed 8 years ago

flying-sheep commented 8 years ago

Hi, as seen in #3831, string interpolation like "A #{a} B #{b}" is lexed as if it was 'A '+a+' B '+b.

as mentioned in juliankrispel/decaf#2, there are use cases for having the semantic information survive lexing.

Therefore it would be awesome if we could introduce a new StringInterpolation AST node which is later converted to a concatenation expression.

michaelficarra commented 8 years ago

:+1:. This is how I did it in the CoffeeScriptRedux compiler.

jashkenas commented 8 years ago

IIRC, that would also help out with some other tricky issues. Like the old implicit call rewriter kludge.

lydell commented 8 years ago

@jashkenas I think that particular issue was fixed in commit 76c076db555c9ac7c325c3b285cd74644a9bf0d2 ;) But I do agree that information is lost in many places in the parser.

string interpolation like "A #{a} B #{b}" is lexed as if it was 'A '+a+' B '+b

Just a FYI: this is not true. But it is true that the AST looks the same. grammar.coffee:150.

juliankrispel commented 8 years ago

awesomesauce! This would be super helpful

lydell commented 8 years ago

@juliankrispel I'm working on this (and have come very far, all tests are currently passing): https://github.com/lydell/coffee-script/tree/node-types

juliankrispel commented 8 years ago

@lydell omg this is amazing. Tbh I'm not sure what I'm looking at but it's amazing nonetheless :D

flying-sheep commented 8 years ago

i hope you’re looking at lydell/coffee-script@5e54fc478f95a8a133c7d88f20600b7caf2fdee0, which is mostly new, more specific Node classes.

one of which being StringWithInterpolations, i.e. what we need.

changes like this tell me that doing the other stuff also is a very good idea!

vendethiel commented 8 years ago

It should also fix some other long-standing bugs like this