Skip to content

Commit

Permalink
Fix custom at rules value handling
Browse files Browse the repository at this point in the history
  • Loading branch information
mgreter committed Jun 12, 2015
1 parent 9f63ad3 commit 5a2ab75
Show file tree
Hide file tree
Showing 10 changed files with 98 additions and 34 deletions.
5 changes: 3 additions & 2 deletions ast.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ namespace Sass {
const T& operator[](size_t i) const { return elements_[i]; }
Vectorized& operator<<(T element)
{
if (!element) return *this;
reset_hash();
elements_.push_back(element);
adjust_after_pushing(element);
Expand Down Expand Up @@ -415,8 +416,8 @@ namespace Sass {
ADD_PROPERTY(Selector*, selector);
ADD_PROPERTY(Expression*, value);
public:
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
At_Rule(ParserState pstate, string kwd, Selector* sel = 0, Block* b = 0, Expression* val = 0)
: Has_Block(pstate, b), keyword_(kwd), selector_(sel), value_(val) // set value manually if needed
{ statement_type(DIRECTIVE); }
bool bubbles() { return is_keyframes() || is_media(); }
bool is_media() {
Expand Down
7 changes: 7 additions & 0 deletions bind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ namespace Sass {
Listize listize(ctx);
map<string, Parameter*> param_map;

for (size_t i = 0, L = as->length(); i < L; ++i) {
if (auto str = dynamic_cast<String_Quoted*>((*as)[i]->value())) {
// force optional quotes (only if needed)
if (str->quote_mark()) str->quote_mark('*');
}
}

// Set up a map to ensure named arguments refer to actual parameters. Also
// eval each default value left-to-right, wrt env, populating env as we go.
for (size_t i = 0, L = ps->length(); i < L; ++i) {
Expand Down
2 changes: 1 addition & 1 deletion debugger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -315,8 +315,8 @@ inline void debug_ast(AST_Node* node, string ind = "", Env* env = 0)
cerr << ind << "At_Rule " << block;
cerr << " (" << pstate_source_position(node) << ")";
cerr << " [" << block->keyword() << "] " << block->tabs() << endl;
debug_ast(block->value(), ind + "+", env);
debug_ast(block->selector(), ind + "~", env);
debug_ast(block->value(), ind + "+", env);
if (block->block()) for(auto i : block->block()->elements()) { debug_ast(i, ind + " ", env); }
} else if (dynamic_cast<Each*>(node)) {
Each* block = dynamic_cast<Each*>(node);
Expand Down
8 changes: 4 additions & 4 deletions expand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,15 +190,15 @@ namespace Sass {
Selector* as = a->selector();
Expression* av = a->value();
selector_stack.push_back(0);
if (as) as = static_cast<Selector_List*>(as->perform(&eval));
else if (av) av = av->perform(&eval);
if (av) av = av->perform(&eval);
if (as) as = dynamic_cast<Selector*>(as->perform(&eval));
selector_stack.pop_back();
Block* bb = ab ? ab->perform(this)->block() : 0;
At_Rule* aa = new (ctx.mem) At_Rule(a->pstate(),
a->keyword(),
as,
bb);
if (av) aa->value(av);
bb,
av);
return aa;
}

Expand Down
4 changes: 4 additions & 0 deletions inspect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ namespace Sass {
at_rule->selector()->perform(this);
in_wrapped = was_wrapped;
}
if (at_rule->value()) {
append_mandatory_space();
at_rule->value()->perform(this);
}
if (at_rule->block()) {
at_rule->block()->perform(this);
}
Expand Down
2 changes: 1 addition & 1 deletion output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ namespace Sass {
s->perform(this);
in_wrapped = false;
}
else if (v) {
if (v) {
append_mandatory_space();
v->perform(this);
}
Expand Down
54 changes: 28 additions & 26 deletions parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,6 @@ namespace Sass {
(*block) << ps;
}
else {
// cerr << "NO BLOCK\n";
// finish and let the semicolon get munched
}
}
Expand All @@ -264,10 +263,7 @@ namespace Sass {
css_error("Invalid CSS", " after ", ": expected selector or at-rule, was ");
}
// nothing matched
else {

// cerr << "parse decl\n";
return false; }
else { return false; }
// something matched
return true;
}
Expand Down Expand Up @@ -675,7 +671,6 @@ namespace Sass {
if (!peek_css< class_char < selector_combinator_ops > >()) {
// parse the left hand side
lhs = parse_compound_selector();
lhs->has_line_break(peek_newline());
}

// check for end of file condition
Expand All @@ -688,6 +683,8 @@ namespace Sass {
else if (lex< exactly<'>'> >()) combinator = Complex_Selector::PARENT_OF;
else /* if (lex< zero >()) */ combinator = Complex_Selector::ANCESTOR_OF;

if (!lhs && combinator == Complex_Selector::ANCESTOR_OF) return 0;

// lex < block_comment >();
// source position of a complex selector points to the combinator
// ToDo: make sure we update pstate for ancestor of (lex < zero >());
Expand Down Expand Up @@ -761,13 +758,19 @@ namespace Sass {
}
// peek for abort conditions
else if (peek< spaces >()) break;
else if (peek< exactly <0> >()) { cerr << "EO\n"; break; }
else if (peek< end_of_file >()) { break; }
else if (peek_css < class_char < selector_combinator_ops > >()) break;
else if (peek_css < class_char < complex_selector_delims > >()) break;
// otherwise parse another simple selector
else (*seq) << parse_simple_selector();
else {
Simple_Selector* sel = parse_simple_selector();
if (!sel) return 0;
(*seq) << sel;
}
}

if (seq) seq->has_line_break(peek_newline());

// EO while true
return seq;

Expand Down Expand Up @@ -1423,6 +1426,7 @@ namespace Sass {
}
++ i;
}

return schema;
}

Expand All @@ -1448,8 +1452,7 @@ namespace Sass {

String* Parser::parse_string()
{
Token token(lexed);
return parse_interpolated_chunk(token);
return parse_interpolated_chunk(Token(lexed));
}

String* Parser::parse_ie_property()
Expand Down Expand Up @@ -1949,8 +1952,6 @@ namespace Sass {
Ruleset* r = parse_ruleset(lookahead_result);
body = new (ctx.mem) Block(r->pstate(), 1, true);
*body << r;
} else {
cerr << "NO BLOCK\n";
}
At_Root_Block* at_root = new (ctx.mem) At_Root_Block(at_source_position, body);
if (expr) at_root->expression(expr);
Expand Down Expand Up @@ -1983,31 +1984,32 @@ namespace Sass {
At_Rule* Parser::parse_at_rule()
{
string kwd(lexed);
ParserState at_source_position = pstate;
Selector* sel = 0;
Expression* val = 0;
At_Rule* at_rule = new (ctx.mem) At_Rule(pstate, kwd);
Lookahead lookahead = lookahead_for_include(position);
if (lookahead.found) {
if (lookahead.has_interpolants) {
sel = parse_selector_schema(lookahead.found);
at_rule->selector(parse_selector_schema(lookahead.found));
}
else {
sel = parse_selector_list();
at_rule->selector(parse_selector_list());
}
}
else if (!(peek < alternatives < exactly<'{'>, exactly<'}'>, exactly<';'> > >())) {
val = parse_list();

lex < css_comments >();

if (lex < static_property >()) {
at_rule->value(parse_interpolated_chunk(Token(lexed)));
} else if (!(peek < alternatives < exactly<'{'>, exactly<'}'>, exactly<';'> > >())) {
at_rule->value(parse_list());
}
Block* body = 0;

lex < css_comments >();

if (peek< exactly<'{'> >()) {
body = parse_block();
at_rule->block(parse_block());
}
// ToDo: is the block really optional
// else cerr << "NO AT RULE BLOCK\n";

At_Rule* rule = new (ctx.mem) At_Rule(at_source_position, kwd, sel, body);
if (!sel) rule->value(val);
return rule;
return at_rule;
}

Warning* Parser::parse_warning()
Expand Down
1 change: 1 addition & 0 deletions parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ namespace Sass {
String* parse_interpolated_chunk(Token, bool constant = false);
String* parse_string();
String_Constant* parse_static_expression();
// String_Constant* parse_static_property();
String_Constant* parse_static_value();
String* parse_ie_property();
String* parse_ie_keyword_arg();
Expand Down
48 changes: 48 additions & 0 deletions prelexer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -751,6 +751,54 @@ namespace Sass {
>(src);
}

const char* static_property(const char* src) {
return
sequence <
zero_plus<
sequence <
zero_plus <
alternatives <
spaces,
line_comment,
block_comment
>
>,
alternatives <
exactly<','>,
exactly<'('>,
exactly<')'>,
kwd_optional,
quoted_string,
interpolant,
identifier,
percentage,
dimension,
variable,
alnum,
sequence <
exactly <'\\'>,
any_char
>
>
>
>,
lookahead <
sequence <
zero_plus <
alternatives <
spaces
>
>,
alternatives <
exactly <';'>,
exactly <'}'>,
exactly <'\0'>
>
>
>
>(src);
}

const char* static_value(const char* src) {
return sequence< sequence<
static_component,
Expand Down
1 change: 1 addition & 0 deletions prelexer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ namespace Sass {

const char* static_string(const char* src);
const char* static_component(const char* src);
const char* static_property(const char* src);
const char* static_value(const char* src);

// Utility functions for finding and counting characters in a string.
Expand Down

0 comments on commit 5a2ab75

Please sign in to comment.