Skip to content

Commit

Permalink
Fix parsing and output of unknown at-rules
Browse files Browse the repository at this point in the history
Fixes #855
  • Loading branch information
mgreter committed Mar 7, 2015
1 parent 29d19d8 commit 8c98da8
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 5 deletions.
8 changes: 7 additions & 1 deletion ast.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,13 @@ namespace Sass {
At_Rule(ParserState pstate, string kwd, Selector* sel = 0, Block* b = 0)
: Has_Block(pstate, b), keyword_(kwd), selector_(sel), value_(0) // set value manually if needed
{ statement_type(DIRECTIVE); }
bool bubbles() { return true; }
bool bubbles() { return is_keyframes() || is_media(); }
bool is_media() {
return keyword_.compare("@-webkit-media") == 0 ||
keyword_.compare("@-moz-media") == 0 ||
keyword_.compare("@-o-media") == 0 ||
keyword_.compare("@media") == 0;
}
bool is_keyframes() {
return keyword_.compare("@-webkit-keyframes") == 0 ||
keyword_.compare("@-moz-keyframes") == 0 ||
Expand Down
4 changes: 2 additions & 2 deletions debugger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ inline void debug_ast(AST_Node* node, string ind = "", Env* env = 0)
" <" << prettyprint(selector->pstate().token.ws_before()) << "> X <" << prettyprint(selector->pstate().token.ws_after()) << ">" << endl;
} else if (dynamic_cast<Selector_Placeholder*>(node)) {
Selector_Placeholder* selector = dynamic_cast<Selector_Placeholder*>(node);
cerr << ind << "Selector_Placeholder " << selector << (selector->has_line_break() ? " [line-break]": " -") << (selector->has_line_feed() ? " [line-feed]": " -") << endl;
cerr << ind << "Selector_Placeholder [" << selector->name() << "] " << selector << (selector->has_line_break() ? " [line-break]": " -") << (selector->has_line_feed() ? " [line-feed]": " -") << endl;
} else if (dynamic_cast<Selector_Reference*>(node)) {
Selector_Reference* selector = dynamic_cast<Selector_Reference*>(node);
cerr << ind << "Selector_Reference " << selector << " @ref " << selector->selector() << endl;
Expand Down Expand Up @@ -161,7 +161,7 @@ inline void debug_ast(AST_Node* node, string ind = "", Env* env = 0)
debug_ast(block->value(), ind + " value: ", env);
} else if (dynamic_cast<At_Rule*>(node)) {
At_Rule* block = dynamic_cast<At_Rule*>(node);
cerr << ind << "At_Rule " << block << " " << block->tabs() << endl;
cerr << ind << "At_Rule " << block << " [" << block->keyword() << "] " << block->tabs() << endl;
debug_ast(block->value(), ind + "+", env);
debug_ast(block->selector(), ind + "~", env);
if (block->block()) for(auto i : block->block()->elements()) { debug_ast(i, ind + " ", env); }
Expand Down
1 change: 1 addition & 0 deletions emitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ namespace Sass {
scheduled_linefeed(0),
scheduled_delimiter(false),
in_comment(false),
in_at_rule(false),
in_media_block(false),
in_declaration(false),
in_declaration_list(false)
Expand Down
1 change: 1 addition & 0 deletions emitter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ namespace Sass {

public:
bool in_comment;
bool in_at_rule;
bool in_media_block;
bool in_declaration;
bool in_declaration_list;
Expand Down
4 changes: 3 additions & 1 deletion inspect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,9 @@ namespace Sass {
append_token(at_rule->keyword(), at_rule);
if (at_rule->selector()) {
append_mandatory_space();
in_at_rule = true;
at_rule->selector()->perform(this);
in_at_rule = false;
}
if (at_rule->block()) {
at_rule->block()->perform(this);
Expand Down Expand Up @@ -836,7 +838,7 @@ namespace Sass {
{
if (g->empty()) return;
for (size_t i = 0, L = g->length(); i < L; ++i) {
if (i == 0) append_indentation();
if (!in_at_rule && i == 0) append_indentation();
(*g)[i]->perform(this);
if (i < L - 1) {
append_comma_separator();
Expand Down
2 changes: 2 additions & 0 deletions output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,9 @@ namespace Sass {
append_token(kwd, a);
if (s) {
append_mandatory_space();
in_at_rule = true;
s->perform(this);
in_at_rule = false;
}
else if (v) {
append_mandatory_space();
Expand Down
4 changes: 3 additions & 1 deletion prelexer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ namespace Sass {

// Match any single character.
const char* any_char(const char* src) { return *src ? src+1 : src; }
// Match word boundary (look ahead)
const char* word_boundary(const char* src) { return !*src || isspace(*src) || ispunct(*src) || !Sass::Util::isAscii(*src) ? src : 0 ; }

// Match a single character satisfying the ctype predicates.
const char* space(const char* src) { return std::isspace(*src) ? src+1 : 0; }
Expand Down Expand Up @@ -288,7 +290,7 @@ namespace Sass {
}

const char* extend(const char* src) {
return exactly<extend_kwd>(src);
return sequence < exactly<extend_kwd>, word_boundary >(src);
}


Expand Down
2 changes: 2 additions & 0 deletions prelexer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ namespace Sass {
const char* any_char_except(const char* src) {
return (*src && *src != c) ? src+1 : 0;
}
// Match word boundary (look ahead)
const char* word_boundary(const char* src);

// Matches zero characters (always succeeds without consuming input).
// const char* epsilon(const char*);
Expand Down

0 comments on commit 8c98da8

Please sign in to comment.