-
Notifications
You must be signed in to change notification settings - Fork 462
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] Refactor interpolation #1738
Conversation
Use an intermediate list representation to create the actual hash map in the evaluation phase.
cbac042
to
9695d17
Compare
Spec test I'm currently using to test binary expressions with interpolations: foo {
bar: 10 * 5;
bar: 10 / 5;
bar: 10 + 5;
bar: 10 - 5;
}
foo {
bar: 10 * #{5};
bar: 10 / #{5};
bar: 10 + #{5};
bar: 10 - #{5};
}
foo {
bar: 10 * 5#{px};
bar: 10 / 5#{px};
bar: 10 + 5#{px};
bar: 10 - 5#{px};
}
baz {
baz: #{5} * 1;
baz: #{5} / 1;
baz: #{5} + 1;
baz: #{5} - 1;
}
baz {
baz: #{5px} * 1;
baz: #{5px} / 1;
baz: #{5px} + 1;
baz: #{5px} - 1;
}
bar {
width: #{1+2}+4;
width: #{1/2}/4;
width: #{1+2}+4;
width: #{1-2}-4;
}
foo {
bar: 10/5;
bar: 10/ 5;
bar: 10 /5;
bar: 10 / 5;
bar: 10 / 5;
}
div {
baz: #{4/5}/1;
baz: #{4/ 5}/ 1;
baz: #{4 /5} /1;
baz: #{4 / 5} / 1;
}
mul {
baz: #{4*5}*1;
baz: #{4* 5}* 1;
baz: #{4 *5} *1;
baz: #{4 * 5} * 1;
}
add {
baz: #{4+5}+1;
baz: #{4+ 5}+ 1;
baz: #{4 +5} +1;
baz: #{4 + 5} + 1;
}
sub {
baz: #{4-5}-1;
baz: #{4- 5}- 1;
baz: #{4 -5} -1;
baz: #{4 - 5} - 1;
} Expected result: foo {
bar: 50;
bar: 10 / 5;
bar: 15;
bar: 5; }
foo {
bar: 10 * 5;
bar: 10 / 5;
bar: 10 + 5;
bar: 10 - 5; }
foo {
bar: 50px;
bar: 10/5px;
bar: 15px;
bar: 5px; }
baz {
baz: 5 * 1;
baz: 5 / 1;
baz: 5 + 1;
baz: 5 - 1; }
baz {
baz: 5px * 1;
baz: 5px / 1;
baz: 5px + 1;
baz: 5px - 1; }
bar {
width: 3+4;
width: 1/2/4;
width: 3+4;
width: -1-4; }
foo {
bar: 10/5;
bar: 10/ 5;
bar: 10 /5;
bar: 10 / 5;
bar: 10 / 5; }
div {
baz: 4/5/1;
baz: 4/5/ 1;
baz: 4/5 /1;
baz: 4/5 / 1; }
mul {
baz: 20*1;
baz: 20* 1;
baz: 20 *1;
baz: 20 * 1; }
add {
baz: 9+1;
baz: 9+ 1;
baz: 9 +1;
baz: 9 + 1; }
sub {
baz: -1-1;
baz: -1- 1;
baz: 4 -5 -1;
baz: -1 - 1; } What this WIP currently produces: foo {
bar: 50;
bar: 10 / 5;
bar: 15;
bar: 5; }
foo {
bar: 10 * 5;
bar: 10 / 5;
bar: 10 + 5;
bar: 10 - 5; }
foo {
bar: 50px;
bar: 10/5px;
bar: 15px;
bar: 5px; }
baz {
baz: 5 * 1;
baz: 5 / 1;
baz: 5 + 1;
baz: 5 - 1; }
baz {
baz: 5px * 1;
baz: 5px / 1;
baz: 5px + 1;
baz: 5px - 1; }
bar {
width: 3+4;
width: 1/2 / 4;
width: 3+4;
width: -1-4; }
foo {
bar: 10/5;
bar: 10/ 5;
bar: 10 /5;
bar: 10 / 5;
bar: 10 / 5; }
div {
baz: 4/5 / 1;
baz: 4/5 / 1;
baz: 4/5 / 1;
baz: 4/5 / 1; }
mul {
baz: 20 * 1;
baz: 20 * 1;
baz: 20 * 1;
baz: 20 * 1; }
add {
baz: 9+1;
baz: 9 1;
baz: 9 + 1;
baz: 9 + 1; }
sub {
baz: -1-1;
baz: -1- 1;
baz: 4 -5 -1;
baz: -1 - 1; } As far as I can see this now would only differ in whitespace, but I had to do some very crude checks to get this behavior. @xzyfer IMO you said you want to takle this too? It seems that binary expressions somehow remember the whitespace around operators. IMO this needs to be addressed first before I could clean up the binary expression part of this refactoring. |
Libsass is also not accepting asterisk glued to numbers and interpolations, maybe this is related? |
Part of this code will be addressed with my static value refactor which
|
@xzyfer so will your refactor solve all the issues in the sample I posted above? |
I'm not planning to directly address them. My work is focusing on improving As far as my approach I'm simply changing our parser to better match the
|
Preview (WIP) of interpolation refactoring. Got rid of most of the escape vodoo.
Currently still fails in two main corners:
Parsed AST for issue 948:
I guess we had a "hotfix" in place for this before. But we may just don't parse it correctly.
Edit: Seems to be related to how we handle binary_expressions, see test code below: