Commit 607058ec by Aaron Leung

Extensible environments. More powerful than necessary, but will be necessary if…

Extensible environments. More powerful than necessary, but will be necessary if scoped variables and mixins are added to the language.
parent 35b4632f
namespace Sass {
using std::map;
struct Environment {
map<Token, Node> frame;
Environment* parent;
Environment() : frame(map<Token, Node>()), parent(0)
{ }
Environment(Environment* env) : frame(map<Token, Node>()), parent(env)
{ }
bool query(const Token& key) const
{
if (frame.count(key)) return true;
else if (parent) return parent->query(key);
else return false;
}
Node& operator[](const Token& key)
{
if (frame.count(key)) return frame[key];
else if (parent) return (*parent)[key];
else return frame[key];
}
};
struct Context {
map<Token, Node> environment;
// Environment environment;
// map<Token, Node> mixins;
Environment global_env;
vector<Node> pending;
vector<char*> source_refs;
size_t ref_count;
......@@ -24,21 +47,5 @@ namespace Sass {
}
}
};
struct Environment {
vector< map<Token, Node> > stack;
Environment()
: stack(vector< map<Token, Node> >())
{
stack.reserve(2);
stack.push_back(map<Token, Node>());
}
void extend()
{
stack.push_back(map<Token, Node>());
}
};
}
\ No newline at end of file
}
......@@ -59,8 +59,6 @@ namespace Sass {
numeric_dimension,
number,
hex_triple,
comment,
mixin,
parameters,
......@@ -68,7 +66,10 @@ namespace Sass {
arguments,
variable,
assignment
assignment,
comment,
none
};
static size_t fresh;
......@@ -86,7 +87,7 @@ namespace Sass {
bool from_variable;
bool eval_me;
Node() : type(nil), children(0) { ++fresh; }
Node() : type(none), children(0) { ++fresh; }
Node(const Node& n)
: line_number(n.line_number),
......
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