darron / language-ejs

EJS support for Atom.
Apache License 2.0
14 stars 7 forks source link

Syntax doesn't work when surrounded by quotes #8

Open OscarGodson opened 8 years ago

OscarGodson commented 8 years ago

For example

<img class="__post-cover-photo" src="<%= thumbnail %>" />

It's a solid color inside of the quotes. It should have different colors for things like <%= and %> and thumbnail

karloluis commented 8 years ago

Sadly the is no look ahead in regex, therefore there is no way for it to know that there is a script inside this string.

OscarGodson commented 8 years ago

Hm, out of curiosity then how do the other templating languages do this? For example that identical code works in Mustache just changing it to {{ and }} instead of <%= and %>

karloluis commented 8 years ago

It's a scoping mechanism. Those symbols determine that code begins and ends, code which has it's own syntax. For strings there is no further syntax to be parsed through, you can just have a string.

There is no way to differentiate when `"<%= ... %>" is meant for code and when it coincidentally happens as a string, therefore the syntax compromises and says it's always a string because it doesn't know any better.

If my explanation does not suffice as it might be confusing, try to learn more about regular expression or even how compilers and interpreters "tokenize" your code. Hope this helped any way.