Commit a339e8e5 by Aaron Leung

Full-on arbitrarily nested scopes for variables.

parent 974822d7
...@@ -17,11 +17,12 @@ namespace Sass { ...@@ -17,11 +17,12 @@ namespace Sass {
lex< exactly<';'> >(); lex< exactly<';'> >();
} }
else if (peek< mixin >(position)) { else if (peek< mixin >(position)) {
context.pending.push_back(parse_mixin_definition()); Node mixin(parse_mixin_definition());
context.pending.push_back(mixin);
root << mixin;
} }
else if (peek< include >(position)) { else if (peek< include >(position)) {
Node call(parse_mixin_call()); Node call(parse_mixin_call());
// call << root;
root << call; root << call;
root[0].has_expansions = true; root[0].has_expansions = true;
lex< exactly<';'> >(); lex< exactly<';'> >();
...@@ -31,6 +32,7 @@ namespace Sass { ...@@ -31,6 +32,7 @@ namespace Sass {
Node assn(parse_assignment()); Node assn(parse_assignment());
lex< exactly<';'> >(); lex< exactly<';'> >();
context.pending.push_back(assn); context.pending.push_back(assn);
root << assn;
} }
else { else {
root << parse_ruleset(); root << parse_ruleset();
...@@ -337,7 +339,6 @@ namespace Sass { ...@@ -337,7 +339,6 @@ namespace Sass {
} }
else if (peek< include >(position)) { else if (peek< include >(position)) {
Node call(parse_mixin_call()); Node call(parse_mixin_call());
// call << block;
block << call; block << call;
// block.has_expansions = true; // block.has_expansions = true;
block[0].has_expansions = true; block[0].has_expansions = true;
...@@ -375,7 +376,6 @@ namespace Sass { ...@@ -375,7 +376,6 @@ namespace Sass {
while (lex< block_comment >()) { while (lex< block_comment >()) {
block << Node(line_number, Node::comment, lexed); block << Node(line_number, Node::comment, lexed);
block[0].has_rules_or_comments = true; block[0].has_rules_or_comments = true;
cerr << "Parsing a terminal comment: " << string(lexed) << endl;
} }
} }
return block; return block;
......
...@@ -36,13 +36,22 @@ namespace Sass { ...@@ -36,13 +36,22 @@ namespace Sass {
return expr; return expr;
} break; } break;
case Node::block: { case Node::root: {
for (int i = 0; i < expr.size(); ++i) { for (int i = 0; i < expr.size(); ++i) {
eval(expr[i], env); eval(expr[i], env);
} }
return expr; return expr;
} break; } break;
case Node::block: {
Environment current;
current.link(env);
for (int i = 0; i < expr.size(); ++i) {
eval(expr[i], current);
}
return expr;
} break;
case Node::assignment: { case Node::assignment: {
Node val(expr[1]); Node val(expr[1]);
if (val.type == Node::comma_list || val.type == Node::space_list) { if (val.type == Node::comma_list || val.type == Node::space_list) {
...@@ -71,7 +80,7 @@ namespace Sass { ...@@ -71,7 +80,7 @@ namespace Sass {
} }
} }
else { else {
expr[1] = eval(rhs, env); if (rhs.eval_me) expr[1] = eval(rhs, env);
} }
return expr; return expr;
} break; } break;
......
...@@ -3,12 +3,10 @@ $y: global-y; ...@@ -3,12 +3,10 @@ $y: global-y;
$z: global-z; $z: global-z;
@mixin foo($x, $y) { @mixin foo($x, $y) {
/* begin foo */
margin: $x $y; margin: $x $y;
blip { blip {
hey: now; hey: now;
} }
/* end foo */
} }
@mixin foogoo($x, $y, $z) { @mixin foogoo($x, $y, $z) {
...@@ -16,17 +14,15 @@ $z: global-z; ...@@ -16,17 +14,15 @@ $z: global-z;
} }
@mixin hux($y) { @mixin hux($y) {
/* begin hux */
color: $y; color: $y;
@include foo(called-from-hux); @include foo(called-from-hux);
/* end hux */
} }
div { div {
@include foo(1, 2); @include foo(1, 2);
@include foo(1); @include foo(1);
@include foogoo(1, 2); @include foogoo(1, 2);
@include foogoo($y /* blah */ : kwd-y, $z: kwd-z); @include foogoo($y: kwd-y, $z: kwd-z);
} }
div { div {
...@@ -56,7 +52,6 @@ div { ...@@ -56,7 +52,6 @@ div {
} }
div { div {
/* calls to nullary mixins may omit the empty argument list */
@include bung; @include bung;
} }
...@@ -66,6 +61,7 @@ div { ...@@ -66,6 +61,7 @@ div {
} }
@mixin ruleset() { @mixin ruleset() {
moo: goo;
hoo { hoo {
color: boo; color: boo;
} }
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
#include <string> #include <string>
#include <map> #include <map>
#include "document.hpp" #include "document.hpp"
#include "eval_apply.hpp"
using namespace Sass; using namespace Sass;
using namespace std; using namespace std;
...@@ -30,7 +31,8 @@ int main(int argc, char* argv[]) { ...@@ -30,7 +31,8 @@ int main(int argc, char* argv[]) {
Document doc(path, 0); Document doc(path, 0);
doc.parse_scss(); doc.parse_scss();
cerr << "SUCCESSFULLY PARSED DOCUMENT" << endl; cerr << "SUCCESSFULLY PARSED DOCUMENT" << endl;
doc.eval_pending(); // doc.eval_pending();
eval(doc.root, doc.context.global_env);
cerr << "SUCCESSFULLY EVALED DOCUMENT" << endl; cerr << "SUCCESSFULLY EVALED DOCUMENT" << endl;
string output = doc.emit_css(style); string output = doc.emit_css(style);
......
@mixin foo() {
/* begin foo */
/* assigning to $x */
$x: inside foo;
x: $x;
/* end foo */
}
outer {
/* assigning to $x */
$x: inside outer scope;
blah: blah;
inner {
@include foo();
x: $x;
}
}
\ No newline at end of file
outer {
/* assigning to $x */
blah: blah; }
outer inner {
/* begin foo */
/* assigning to $x */
x: inside foo;
/* end foo */
x: inside outer scope; }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment