Commit 6863a86f by Aaron Leung

Implemented the @warn directive. A bit glitchy if you try to pass it a list with…

Implemented the @warn directive. A bit glitchy if you try to pass it a list with arithmetic expressions and interpolants, but it generally works without barfing.
parent a210fc7f
......@@ -168,6 +168,7 @@ namespace Sass {
Node parse_while_directive(Node surrounding_ruleset, Node::Type inside_of = Node::none);
Node parse_media_query(Node::Type inside_of = Node::none);
Node parse_media_expression();
Node parse_warning();
Selector_Lookahead lookahead_for_selector(const char* start = 0);
......
......@@ -54,6 +54,10 @@ namespace Sass {
else if (peek< media >()) {
root << parse_media_query(Node::none);
}
else if (peek< warn >()) {
root << parse_warning();
if (!lex< exactly<';'> >()) throw_syntax_error("top-level @warn directive must be terminated by ';'");
}
else {
lex< spaces_and_comments >();
throw_syntax_error("invalid top-level expression");
......@@ -514,6 +518,10 @@ namespace Sass {
block << ret_expr;
semicolon = true;
}
else if (peek< warn >()) {
block << parse_warning();
semicolon = true;
}
else if (inside_of == Node::function) {
throw_syntax_error("only variable declarations and control directives are allowed inside functions");
}
......@@ -882,6 +890,7 @@ namespace Sass {
break;
}
}
schema.should_eval() = true;
return schema;
}
......@@ -1096,6 +1105,15 @@ namespace Sass {
}
return media_expr;
}
Node Document::parse_warning()
{
lex< warn >();
Node warning(context.new_Node(Node::warning, path, line, 1));
warning << parse_list();
warning[0].should_eval() = true;
return warning;
}
Selector_Lookahead Document::lookahead_for_selector(const char* start)
{
......
......@@ -320,6 +320,7 @@ namespace Sass {
case Node::string_schema:
case Node::value_schema:
case Node::identifier_schema: {
cerr << "evaluating a string schema: " << expr.to_string() << endl;
for (size_t i = 0, S = expr.size(); i < S; ++i) {
expr[i] = eval(expr[i], prefix, env, f_env, new_Node, ctx);
}
......@@ -407,6 +408,11 @@ namespace Sass {
}
} break;
case Node::warning: {
expr[0] = eval(expr[0], prefix, env, f_env, new_Node, ctx);
return expr;
} break;
default: {
return expr;
} break;
......
......@@ -161,6 +161,8 @@ namespace Sass {
return_directive,
content_directive,
warning,
variable,
assignment
};
......@@ -293,7 +295,8 @@ namespace Sass {
case Node::comment:
case Node::css_import:
case Node::rule:
case Node::propset: has_statements = true; break;
case Node::propset:
case Node::warning: has_statements = true; break;
case Node::media_query:
case Node::ruleset: has_blocks = true; break;
......
......@@ -323,6 +323,22 @@ namespace Sass {
}
return result;
} break;
case warning: {
string prefix("WARNING: ");
string indent(" ");
Node contents(at(0));
string result(contents.to_string());
if (contents.type() == string_constant || contents.type() == string_schema) {
result = result.substr(1, result.size()-2); // unquote if it's a single string
}
stringstream ss;
ss << prefix << result << endl;
ss << indent << "on line " << at(0).line() << " of " << at(0).path();
ss << endl << endl;
cerr << ss.str();
return "";
} break;
default: {
// return content.token.to_string();
......@@ -354,7 +370,7 @@ namespace Sass {
buf << " {";
for (size_t i = 0, S = block.size(); i < S; ++i) {
Type stm_type = block[i].type();
if (stm_type == comment || stm_type == rule || stm_type == css_import || stm_type == propset) {
if (stm_type == comment || stm_type == rule || stm_type == css_import || stm_type == propset || stm_type == warning) {
block[i].emit_nested_css(buf, depth+1);
}
}
......
......@@ -179,6 +179,12 @@ namespace Sass {
exactly<'-'>,
exactly<'_'> > >(src);
}
extern const char warn_kwd[] = "@warn";
const char* warn(const char* src) {
return exactly<warn_kwd>(src);
}
// Match CSS type selectors
const char* namespace_prefix(const char* src) {
return sequence< optional< alternatives< identifier, exactly<'*'> > >,
......
......@@ -329,6 +329,8 @@ namespace Sass {
const char* while_directive(const char* src);
const char* warn(const char* src);
// Match CSS type selectors
const char* namespace_prefix(const char* src);
const char* type_selector(const char* src);
......
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