Commit eb1eae78 by Aaron Leung

Handling guarded assignments.

parent 75d1174f
......@@ -218,6 +218,7 @@ namespace Sass {
Node val(parse_list());
Node assn(context.new_Node(Node::assignment, path, line, 2));
assn << var << val;
if (lex< default_flag >()) assn << context.new_Node(Node::none, path, line, 0);
return assn;
}
......@@ -609,7 +610,8 @@ namespace Sass {
peek< exactly<'}'> >(position) ||
peek< exactly<'{'> >(position) ||
peek< exactly<')'> >(position) ||
peek< exactly<','> >(position))
peek< exactly<','> >(position) ||
peek< default_flag >(position))
{ return disj1; }
Node space_list(context.new_Node(Node::space_list, path, line, 2));
......@@ -620,7 +622,8 @@ namespace Sass {
peek< exactly<'}'> >(position) ||
peek< exactly<'{'> >(position) ||
peek< exactly<')'> >(position) ||
peek< exactly<','> >(position)))
peek< exactly<','> >(position) ||
peek< default_flag >(position)))
{
Node disj(parse_disjunction());
space_list << disj;
......
......@@ -124,6 +124,7 @@ namespace Sass {
val = eval(val, prefix, env, f_env, new_Node, ctx);
}
Node var(expr[0]);
if (expr.is_guarded() && env.query(var.token())) return expr;
// If a binding exists (possible upframe), then update it.
// Otherwise, make a new on in the current frame.
if (env.query(var.token())) {
......@@ -657,6 +658,7 @@ namespace Sass {
val = eval(val, Node(), bindings, ctx.function_env, new_Node, ctx);
}
Node var(stm[0]);
if (stm.is_guarded() && bindings.query(var.token())) continue;
// If a binding exists (possible upframe), then update it.
// Otherwise, make a new on in the current frame.
if (bindings.query(var.token())) {
......
......@@ -173,6 +173,7 @@ namespace Sass {
bool& should_eval() const;
bool& is_unquoted() const;
bool is_numeric() const;
bool is_guarded() const;
string& path() const;
size_t line() const;
......@@ -349,6 +350,7 @@ namespace Sass {
inline bool& Node::should_eval() const { return ip_->should_eval; }
inline bool& Node::is_unquoted() const { return ip_->is_unquoted; }
inline bool Node::is_numeric() const { return ip_->is_numeric(); }
inline bool Node::is_guarded() const { return (type() == assignment) && (size() == 3); }
inline string& Node::path() const { return ip_->path; }
inline size_t Node::line() const { return ip_->line; }
......
......@@ -271,6 +271,13 @@ namespace Sass {
spaces_and_comments,
exactly<important_kwd> >(src);
}
// Match Sass "!default" keyword.
extern const char default_kwd[] = "default";
const char* default_flag(const char* src) {
return sequence< exactly<'!'>,
spaces_and_comments,
exactly<default_kwd> >(src);
}
// Match CSS pseudo-class/element prefixes.
const char* pseudo_prefix(const char* src) {
return sequence< exactly<':'>, optional< exactly<':'> > >(src);
......
......@@ -351,6 +351,8 @@ namespace Sass {
const char* uri(const char* src);
// Match CSS "!important" keyword.
const char* important(const char* src);
// Match Sass "!default" keyword.
const char* default_flag(const char* src);
// Match CSS pseudo-class/element prefixes
const char* pseudo_prefix(const char* src);
// Match CSS function call openers.
......
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