davidedc / livecodelab

a web based livecoding environment
http://livecodelab.net/
MIT License
327 stars 63 forks source link

Preprocessor adding () in string literals #238

Closed xinaesthete closed 10 years ago

xinaesthete commented 10 years ago

If you write

F = -> box
s = "F-"

then it will compile to

var F, s;

F = function() {
  return box();
};

s = "F()-";

This lead to some slightly obscure behaviour while I was writing an L-system.

nb I haven't actually reproduced this outside of my own fork, but have no reason to believe any of my modifications are relevant. It doesn't happen on the live version at livecodelab.net, presumably because that's somewhat behind.

davidedc commented 10 years ago

yes, I'm aware of that, gonna fix this tonight.

Processing.js avoids that by building a table of strings ahead of transformation, doing the transformations and then replacing the strings back.

Here is the exact snippet of the replacement: https://github.com/jeresig/processing-js/blob/master/processing.js#L18176 ...and this is where the strings are put back: https://github.com/jeresig/processing-js/blob/master/processing.js#L18128

so I'm gonna do that tonight.

davidedc commented 10 years ago

(doesn't happen on the live version cause the live version doesn't have all the new language features, there are a lot more transformations going on now.)

xinaesthete commented 10 years ago

Yes, I gathered this had something to with the newlang stuff, but I haven't really looked closely at what that is or how far it's made it into the trunk.

xinaesthete commented 10 years ago

Brilliant, thanks for the snappy response.