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 { namespace Sass {
using std::map; 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 { struct Context {
map<Token, Node> environment; map<Token, Node> environment;
// Environment environment; Environment global_env;
// map<Token, Node> mixins;
vector<Node> pending; vector<Node> pending;
vector<char*> source_refs; vector<char*> source_refs;
size_t ref_count; size_t ref_count;
...@@ -25,20 +48,4 @@ namespace Sass { ...@@ -25,20 +48,4 @@ 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>());
}
};
} }
...@@ -60,15 +60,16 @@ namespace Sass { ...@@ -60,15 +60,16 @@ namespace Sass {
number, number,
hex_triple, hex_triple,
comment,
mixin, mixin,
parameters, parameters,
expansion, expansion,
arguments, arguments,
variable, variable,
assignment assignment,
comment,
none
}; };
static size_t fresh; static size_t fresh;
...@@ -86,7 +87,7 @@ namespace Sass { ...@@ -86,7 +87,7 @@ namespace Sass {
bool from_variable; bool from_variable;
bool eval_me; bool eval_me;
Node() : type(nil), children(0) { ++fresh; } Node() : type(none), children(0) { ++fresh; }
Node(const Node& n) Node(const Node& n)
: line_number(n.line_number), : 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