Commit 5bd4581b by Aaron Leung

Merge branch 'expand-eval-apply'

Conflicts:
	eval_apply.cpp
parents 580c318b e44e4923
......@@ -202,7 +202,7 @@ namespace Sass {
if (!lex< identifier >()) throw_syntax_error("invalid name in @include directive");
Node name(context.new_Node(Node::identifier, path, line, lexed));
Node args(parse_arguments());
Node the_call(context.new_Node(Node::expansion, path, line, 2));
Node the_call(context.new_Node(Node::mixin_call, path, line, 2));
the_call << name << args;
return the_call;
}
......@@ -215,12 +215,10 @@ namespace Sass {
if (lex< exactly<'('> >()) {
if (!peek< exactly<')'> >(position)) {
Node arg(parse_argument(Node::none));
arg.should_eval() = true;
args << arg;
if (arg.type() == Node::assignment) arg_type = Node::assignment;
while (lex< exactly<','> >()) {
Node arg(parse_argument(arg_type));
arg.should_eval() = true;
args << arg;
if (arg.type() == Node::assignment) arg_type = Node::assignment;
}
......@@ -239,6 +237,7 @@ namespace Sass {
Node var(context.new_Node(Node::variable, path, line, lexed));
lex< exactly<':'> >();
Node val(parse_space_list());
val.should_eval() = true;
Node assn(context.new_Node(Node::assignment, path, line, 2));
assn << var << val;
return assn;
......@@ -254,23 +253,14 @@ namespace Sass {
Node var(context.new_Node(Node::variable, path, line, lexed));
lex< exactly<':'> >();
Node val(parse_space_list());
val.should_eval() = true;
Node assn(context.new_Node(Node::assignment, path, line, 2));
assn << var << val;
return assn;
}
return parse_space_list();
// if (peek< sequence < variable, spaces_and_comments, exactly<':'> > >()) {
// lex< variable >();
// Node var(context.new_Node(Node::variable, path, line, lexed));
// lex< exactly<':'> >();
// Node val(parse_space_list());
// Node assn(context.new_Node(Node::assignment, path, line, 2));
// assn << var << val;
// return assn;
// }
// else {
// return parse_space_list();
// }
Node val(parse_space_list());
val.should_eval() = true;
return val;
}
Node Document::parse_assignment()
......@@ -598,7 +588,7 @@ namespace Sass {
semicolon = true;
}
else if (lex< extend >()) {
if (surrounding_ruleset.is_null_ptr()) throw_syntax_error("@extend directive may only be used within rules");
if (surrounding_ruleset.is_null()) throw_syntax_error("@extend directive may only be used within rules");
Node extendee(parse_simple_selector_sequence());
context.extensions.insert(pair<Node, Node>(extendee, surrounding_ruleset));
context.has_extensions = true;
......@@ -1016,6 +1006,7 @@ namespace Sass {
if (lex< interpolant >()) {
Token insides(Token::make(lexed.begin + 2, lexed.end - 1));
Node interp_node(Document::make_from_token(context, insides, path, line).parse_list());
interp_node.should_eval() = true;
schema << interp_node;
}
else if (lex< identifier >()) {
......@@ -1080,6 +1071,7 @@ namespace Sass {
else if (lex< interpolant >()) {
Token insides(Token::make(lexed.begin + 2, lexed.end - 1));
Node interp_node(Document::make_from_token(context, insides, path, line).parse_list());
interp_node.should_eval() = true;
schema << interp_node;
}
else if (lex< sequence< identifier, exactly<':'> > >()) {
......
......@@ -13,8 +13,10 @@
namespace Sass {
using std::map;
void expand(Node expr, Node prefix, Environment& env, map<string, Function>& f_env, Node_Factory& new_Node, Context& ctx, bool function_name = false);
Node eval(Node expr, Node prefix, Environment& env, map<string, Function>& f_env, Node_Factory& new_Node, Context& ctx, bool function_name = false);
Node function_eval(string name, Node stm, Environment& bindings, Node_Factory& new_Node, Context& ctx, bool toplevel = false);
Node eval_arguments(Node args, Node prefix, Environment& env, map<string, Function>& f_env, Node_Factory& new_Node, Context& ctx);
Node eval_function(string name, Node stm, Environment& bindings, Node_Factory& new_Node, Context& ctx, bool toplevel = false);
Node reduce(Node list, size_t head, Node acc, Node_Factory& new_Node);
Node accumulate(Node::Type op, Node acc, Node rhs, Node_Factory& new_Node);
double operate(Node op, double lhs, double rhs);
......
......@@ -18,8 +18,9 @@ namespace Sass {
switch (type())
{
case block:
case expansion:
case mixin_call:
case root:
case if_directive:
case for_through_directive:
case for_to_directive:
case each_directive:
......@@ -33,8 +34,9 @@ namespace Sass {
for (size_t i = 0; i < size(); ++i) {
switch (at(i).type())
{
case expansion:
case mixin_call:
case block:
case if_directive:
case for_through_directive:
case for_to_directive:
case each_directive:
......
......@@ -150,11 +150,11 @@ namespace Sass {
identifier_schema,
css_import,
function,
function_call,
mixin,
function,
mixin_call,
parameters,
expansion,
arguments,
if_directive,
......@@ -177,8 +177,8 @@ namespace Sass {
Node(Node_Impl* ip = 0);
Type type() const;
Type type(Type);
bool is_none() const;
bool has_children() const;
bool has_statements() const;
bool has_blocks() const;
......@@ -204,6 +204,7 @@ namespace Sass {
Node& back() const;
Node& operator[](size_t i) const;
void pop_back();
void pop_all();
Node& push_back(Node n);
Node& push_front(Node n);
Node& operator<<(Node n);
......@@ -220,7 +221,7 @@ namespace Sass {
Token token() const;
Token unit() const;
bool is_null_ptr() const { return !ip_; }
bool is_null() const { return !ip_; }
bool is(Node n) const { return ip_ == n.ip_; }
void flatten();
......@@ -369,7 +370,7 @@ namespace Sass {
case Node::for_to_directive:
case Node::each_directive:
case Node::while_directive:
case Node::expansion: {
case Node::mixin_call: {
has_expansions = true;
} break;
......@@ -401,7 +402,7 @@ namespace Sass {
case Node::for_to_directive:
case Node::each_directive:
case Node::while_directive:
case Node::expansion: has_expansions = true; break;
case Node::mixin_call: has_expansions = true; break;
case Node::backref: has_backref = true; break;
......@@ -413,6 +414,9 @@ namespace Sass {
void pop_back()
{ children.pop_back(); }
void pop_all()
{ for (size_t i = 0, S = size(); i < S; ++i) pop_back(); }
bool& boolean_value()
{ return value.boolean; }
......@@ -430,8 +434,8 @@ namespace Sass {
inline Node::Node(Node_Impl* ip) : ip_(ip) { }
inline Node::Type Node::type() const { return ip_->type; }
inline Node::Type Node::type(Type t) { return ip_->type = t; }
inline bool Node::is_none() const { return !ip_; }
inline bool Node::has_children() const { return ip_->has_children; }
inline bool Node::has_statements() const { return ip_->has_statements; }
inline bool Node::has_blocks() const { return ip_->has_blocks; }
......@@ -457,6 +461,7 @@ namespace Sass {
inline Node& Node::back() const { return ip_->back(); }
inline Node& Node::operator[](size_t i) const { return at(i); }
inline void Node::pop_back() { ip_->pop_back(); }
inline void Node::pop_all() { ip_->pop_all(); }
inline Node& Node::push_back(Node n)
{
ip_->push_back(n);
......
......@@ -124,6 +124,7 @@ namespace Sass {
if (size() == 0) return "";
string result(at(0).to_string());
for (size_t i = 1, S = size(); i < S; ++i) {
if (at(i).is_null()) continue;
if (at(i).type() == list && at(i).size() == 0) continue;
result += is_comma_separated() ? ", " : " ";
result += at(i).to_string();
......@@ -270,7 +271,7 @@ namespace Sass {
return result;
} break;
case expansion: {
case mixin_call: {
// ignore it
return "";
} break;
......
......@@ -41,7 +41,7 @@ extern "C" {
{
using namespace Sass;
doc.parse_scss();
eval(doc.root,
expand(doc.root,
doc.context.new_Node(Node::none, doc.path, doc.line, 0),
doc.context.global_env,
doc.context.function_env,
......
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