Commit 7dff7a7b by Aaron Leung

Getting imports to work right. Arbitrary nesting and cross-file variables work properly.

parent c15503ae
...@@ -3,7 +3,20 @@ namespace Sass { ...@@ -3,7 +3,20 @@ namespace Sass {
struct Context { struct Context {
map<Token, Node> environment; map<Token, Node> environment;
vector<char*> source_refs;
size_t ref_count; size_t ref_count;
Context() : environment(map<Token, Node>()), ref_count(0) { }
Context()
: environment(map<Token, Node>()),
source_refs(vector<char*>()),
ref_count(0)
{ }
~Context()
{
for (int i = 0; i < source_refs.size(); ++i) {
delete[] source_refs[i];
}
}
}; };
} }
\ No newline at end of file
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
namespace Sass { namespace Sass {
Document::Document(string path, char* source) Document::Document(string path, char* source)
: path(path), source(source), source_refs(vector<char*>()), : path(path), source(source), //source_refs(vector<char*>()),
line_number(1), own_source(false), line_number(1), own_source(false),
context(*(new Context())), context(*(new Context())),
root(Node(1, Node::root)), root(Node(1, Node::root)),
...@@ -28,10 +28,12 @@ namespace Sass { ...@@ -28,10 +28,12 @@ namespace Sass {
own_source = true; own_source = true;
} }
position = source; position = source;
context.source_refs.push_back(source);
++context.ref_count;
} }
Document::Document(string path, Context& context) Document::Document(string path, Context& context)
: path(path), source(0), source_refs(vector<char*>()), : path(path), source(0), //source_refs(vector<char*>()),
line_number(1), own_source(false), line_number(1), own_source(false),
context(context), context(context),
root(Node(1, Node::root)), root(Node(1, Node::root)),
...@@ -50,16 +52,17 @@ namespace Sass { ...@@ -50,16 +52,17 @@ namespace Sass {
source[len] = '\0'; source[len] = '\0';
std::fclose(f); std::fclose(f);
position = source; position = source;
context.source_refs.push_back(source);
++context.ref_count; ++context.ref_count;
} }
Document::~Document() { Document::~Document() {
if (own_source) delete [] source; // if (own_source) delete [] source;
--context.ref_count; --context.ref_count;
if (context.ref_count == 0) delete &context; if (context.ref_count == 0) delete &context;
for (int i = 0; i < source_refs.size(); ++i) { // for (int i = 0; i < source_refs.size(); ++i) {
delete [] source_refs[i]; // delete [] source_refs[i];
} // }
} }
} }
\ No newline at end of file
...@@ -13,7 +13,6 @@ namespace Sass { ...@@ -13,7 +13,6 @@ namespace Sass {
string path; string path;
char* source; char* source;
vector<char*> source_refs;
const char* position; const char* position;
size_t line_number; size_t line_number;
bool own_source; bool own_source;
......
...@@ -34,10 +34,9 @@ namespace Sass { ...@@ -34,10 +34,9 @@ namespace Sass {
const char* curr_path_start = path.c_str(); const char* curr_path_start = path.c_str();
const char* curr_path_end = folders(curr_path_start); const char* curr_path_end = folders(curr_path_start);
string current_path(curr_path_start, curr_path_end - curr_path_start); string current_path(curr_path_start, curr_path_end - curr_path_start);
cerr << "importing " << current_path + import_path << endl;
Document importee(current_path + import_path, context); Document importee(current_path + import_path, context);
importee.parse_scss(); importee.parse_scss();
source_refs.push_back(importee.source); // source_refs.push_back(importee.source);
return importee.root; return importee.root;
} }
...@@ -243,7 +242,6 @@ namespace Sass { ...@@ -243,7 +242,6 @@ namespace Sass {
lex< hex >() || lex < string_constant >() || lex< hex >() || lex < string_constant >() ||
lex< variable >()) { lex< variable >()) {
if (lexed.begin[0] == '$') { if (lexed.begin[0] == '$') {
cerr << "about to fetch variable: " << string(lexed) << endl;
Node fetched(context.environment[lexed]); Node fetched(context.environment[lexed]);
for (int i = 0; i < fetched.children->size(); ++i) { for (int i = 0; i < fetched.children->size(); ++i) {
values << fetched.children->at(i); values << fetched.children->at(i);
......
hoo { hoo {
mux: scooba-dee-doo; mux: scooba-dee-doo;
flux: gooboo $x; flux: gooboo $x;
@import "d.scss";
} }
\ No newline at end of file
d {
inside: d now;
}
\ No newline at end of file
div span {
moo: goo; }
foo {
blah: blah; }
foo goo {
blee: blee;
hello: world; }
foo goo hoo {
mux: scooba-dee-doo;
flux: gooboo boo; }
foo goo hoo d {
inside: d now; }
foo blux {
hey: another thing;
ho: will this work; }
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