8 #include "color_maps.hpp"
9 #include "ast_fwd_decl.hpp"
20 static Null sass_null(ParserState("null"));
22 bool Supports_Operator::needs_parens(Supports_Condition_Obj cond) const {
23 if (Supports_Operator_Obj op = Cast<Supports_Operator>(cond)) {
24 return op->operand() != operand();
26 return Cast<Supports_Negation>(cond) != NULL;
29 bool Supports_Negation::needs_parens(Supports_Condition_Obj cond) const {
30 return Cast<Supports_Negation>(cond) ||
31 Cast<Supports_Operator>(cond);
34 void str_rtrim(std::string& str, const std::string& delimiters = " \f\n\r\t\v")
36 str.erase( str.find_last_not_of( delimiters ) + 1 );
39 void String_Constant::rtrim()
44 void String_Schema::rtrim()
47 if (String_Ptr str = Cast<String>(last())) str->rtrim();
51 void Argument::set_delayed(bool delayed)
53 if (value_) value_->set_delayed(delayed);
57 void Arguments::set_delayed(bool delayed)
59 for (Argument_Obj arg : elements()) {
60 if (arg) arg->set_delayed(delayed);
66 bool At_Root_Query::exclude(std::string str)
68 bool with = feature() && unquote(feature()->to_string()).compare("with") == 0;
69 List_Ptr l = static_cast<List_Ptr>(value().ptr());
74 if (!l || l->length() == 0) return str.compare("rule") != 0;
75 for (size_t i = 0, L = l->length(); i < L; ++i)
77 v = unquote((*l)[i]->to_string());
78 if (v.compare("all") == 0 || v == str) return false;
84 if (!l || !l->length()) return str.compare("rule") == 0;
85 for (size_t i = 0, L = l->length(); i < L; ++i)
87 v = unquote((*l)[i]->to_string());
88 if (v.compare("all") == 0 || v == str) return true;
94 void AST_Node::update_pstate(const ParserState& pstate)
96 pstate_.offset += pstate - pstate_ + pstate.offset;
99 bool Simple_Selector::is_ns_eq(const Simple_Selector& r) const
101 // https://github.com/sass/sass/issues/2229
102 if ((has_ns_ == r.has_ns_) ||
103 (has_ns_ && ns_.empty()) ||
104 (r.has_ns_ && r.ns_.empty())
106 if (ns_.empty() && r.ns() == "*") return false;
107 else if (r.ns().empty() && ns() == "*") return false;
108 else return ns() == r.ns();
113 bool Compound_Selector::operator< (const Compound_Selector& rhs) const
115 size_t L = std::min(length(), rhs.length());
116 for (size_t i = 0; i < L; ++i)
118 Simple_Selector_Obj l = (*this)[i];
119 Simple_Selector_Obj r = rhs[i];
120 if (!l && !r) return false;
121 else if (!r) return false;
122 else if (!l) return true;
126 // just compare the length now
127 return length() < rhs.length();
130 bool Compound_Selector::has_parent_ref() const
132 for (Simple_Selector_Obj s : *this) {
133 if (s && s->has_parent_ref()) return true;
138 bool Compound_Selector::has_real_parent_ref() const
140 for (Simple_Selector_Obj s : *this) {
141 if (s && s->has_real_parent_ref()) return true;
146 bool Complex_Selector::has_parent_ref() const
148 return (head() && head()->has_parent_ref()) ||
149 (tail() && tail()->has_parent_ref());
152 bool Complex_Selector::has_real_parent_ref() const
154 return (head() && head()->has_real_parent_ref()) ||
155 (tail() && tail()->has_real_parent_ref());
158 bool Complex_Selector::operator< (const Complex_Selector& rhs) const
160 // const iterators for tails
161 Complex_Selector_Ptr_Const l = this;
162 Complex_Selector_Ptr_Const r = &rhs;
163 Compound_Selector_Ptr l_h = NULL;
164 Compound_Selector_Ptr r_h = NULL;
165 if (l) l_h = l->head();
166 if (r) r_h = r->head();
171 // skip empty ancestor first
172 if (l && l->is_empty_ancestor())
176 if(l) l_h = l->head();
179 // skip empty ancestor first
180 if (r && r->is_empty_ancestor())
184 if (r) r_h = r->head();
188 // check for valid selectors
190 if (!r) return false;
192 else if (!l_h && !r_h)
194 // check combinator after heads
195 if (l->combinator() != r->combinator())
196 { return l->combinator() < r->combinator(); }
197 // advance to next tails
200 // fetch the next headers
201 l_h = NULL; r_h = NULL;
202 if (l) l_h = l->head();
203 if (r) r_h = r->head();
206 else if (!r_h) return true;
207 else if (!l_h) return false;
208 // heads ok and equal
209 else if (*l_h == *r_h)
211 // check combinator after heads
212 if (l->combinator() != r->combinator())
213 { return l->combinator() < r->combinator(); }
214 // advance to next tails
217 // fetch the next headers
218 l_h = NULL; r_h = NULL;
219 if (l) l_h = l->head();
220 if (r) r_h = r->head();
222 // heads are not equal
223 else return *l_h < *r_h;
228 bool Complex_Selector::operator== (const Complex_Selector& rhs) const
230 // const iterators for tails
231 Complex_Selector_Ptr_Const l = this;
232 Complex_Selector_Ptr_Const r = &rhs;
233 Compound_Selector_Ptr l_h = NULL;
234 Compound_Selector_Ptr r_h = NULL;
235 if (l) l_h = l->head();
236 if (r) r_h = r->head();
241 // skip empty ancestor first
242 if (l && l->is_empty_ancestor())
246 if (l) l_h = l->head();
249 // skip empty ancestor first
250 if (r && r->is_empty_ancestor())
254 if (r) r_h = r->head();
258 // check the pointers
264 // check combinator after heads
265 if (l->combinator() != r->combinator())
266 { return l->combinator() < r->combinator(); }
267 // advance to next tails
270 // fetch the next heads
271 l_h = NULL; r_h = NULL;
272 if (l) l_h = l->head();
273 if (r) r_h = r->head();
275 // equals if other head is empty
276 else if ((!l_h && !r_h) ||
277 (!l_h && r_h->empty()) ||
278 (!r_h && l_h->empty()) ||
281 // check combinator after heads
282 if (l->combinator() != r->combinator())
283 { return l->combinator() == r->combinator(); }
284 // advance to next tails
287 // fetch the next heads
288 l_h = NULL; r_h = NULL;
289 if (l) l_h = l->head();
290 if (r) r_h = r->head();
299 Compound_Selector_Ptr Compound_Selector::unify_with(Compound_Selector_Ptr rhs, Context& ctx)
301 if (empty()) return rhs;
302 Compound_Selector_Obj unified = SASS_MEMORY_COPY(rhs);
303 for (size_t i = 0, L = length(); i < L; ++i)
305 if (unified.isNull()) break;
306 unified = at(i)->unify_with(unified, ctx);
308 return unified.detach();
311 bool Complex_Selector::operator== (const Selector& rhs) const
313 if (const Selector_List* sl = Cast<Selector_List>(&rhs)) return *this == *sl;
314 if (const Simple_Selector* sp = Cast<Simple_Selector>(&rhs)) return *this == *sp;
315 if (const Complex_Selector* cs = Cast<Complex_Selector>(&rhs)) return *this == *cs;
316 if (const Compound_Selector* ch = Cast<Compound_Selector>(&rhs)) return *this == *ch;
317 throw std::runtime_error("invalid selector base classes to compare");
322 bool Complex_Selector::operator< (const Selector& rhs) const
324 if (const Selector_List* sl = Cast<Selector_List>(&rhs)) return *this < *sl;
325 if (const Simple_Selector* sp = Cast<Simple_Selector>(&rhs)) return *this < *sp;
326 if (const Complex_Selector* cs = Cast<Complex_Selector>(&rhs)) return *this < *cs;
327 if (const Compound_Selector* ch = Cast<Compound_Selector>(&rhs)) return *this < *ch;
328 throw std::runtime_error("invalid selector base classes to compare");
332 bool Compound_Selector::operator== (const Selector& rhs) const
334 if (const Selector_List* sl = Cast<Selector_List>(&rhs)) return *this == *sl;
335 if (const Simple_Selector* sp = Cast<Simple_Selector>(&rhs)) return *this == *sp;
336 if (const Complex_Selector* cs = Cast<Complex_Selector>(&rhs)) return *this == *cs;
337 if (const Compound_Selector* ch = Cast<Compound_Selector>(&rhs)) return *this == *ch;
338 throw std::runtime_error("invalid selector base classes to compare");
342 bool Compound_Selector::operator< (const Selector& rhs) const
344 if (const Selector_List* sl = Cast<Selector_List>(&rhs)) return *this < *sl;
345 if (const Simple_Selector* sp = Cast<Simple_Selector>(&rhs)) return *this < *sp;
346 if (const Complex_Selector* cs = Cast<Complex_Selector>(&rhs)) return *this < *cs;
347 if (const Compound_Selector* ch = Cast<Compound_Selector>(&rhs)) return *this < *ch;
348 throw std::runtime_error("invalid selector base classes to compare");
352 bool Selector_Schema::operator== (const Selector& rhs) const
354 if (const Selector_List* sl = Cast<Selector_List>(&rhs)) return *this == *sl;
355 if (const Simple_Selector* sp = Cast<Simple_Selector>(&rhs)) return *this == *sp;
356 if (const Complex_Selector* cs = Cast<Complex_Selector>(&rhs)) return *this == *cs;
357 if (const Compound_Selector* ch = Cast<Compound_Selector>(&rhs)) return *this == *ch;
358 throw std::runtime_error("invalid selector base classes to compare");
362 bool Selector_Schema::operator< (const Selector& rhs) const
364 if (const Selector_List* sl = Cast<Selector_List>(&rhs)) return *this < *sl;
365 if (const Simple_Selector* sp = Cast<Simple_Selector>(&rhs)) return *this < *sp;
366 if (const Complex_Selector* cs = Cast<Complex_Selector>(&rhs)) return *this < *cs;
367 if (const Compound_Selector* ch = Cast<Compound_Selector>(&rhs)) return *this < *ch;
368 throw std::runtime_error("invalid selector base classes to compare");
372 bool Simple_Selector::operator== (const Selector& rhs) const
374 if (Simple_Selector_Ptr_Const sp = Cast<Simple_Selector>(&rhs)) return *this == *sp;
378 bool Simple_Selector::operator< (const Selector& rhs) const
380 if (Simple_Selector_Ptr_Const sp = Cast<Simple_Selector>(&rhs)) return *this < *sp;
384 bool Simple_Selector::operator== (const Simple_Selector& rhs) const
386 // solve the double dispatch problem by using RTTI information via dynamic cast
387 if (const Pseudo_Selector* lhs = Cast<Pseudo_Selector>(this)) {return *lhs == rhs; }
388 else if (const Wrapped_Selector* lhs = Cast<Wrapped_Selector>(this)) {return *lhs == rhs; }
389 else if (const Attribute_Selector* lhs = Cast<Attribute_Selector>(this)) {return *lhs == rhs; }
390 else if (name_ == rhs.name_)
391 { return is_ns_eq(rhs); }
395 bool Simple_Selector::operator< (const Simple_Selector& rhs) const
397 // solve the double dispatch problem by using RTTI information via dynamic cast
398 if (const Pseudo_Selector* lhs = Cast<Pseudo_Selector>(this)) {return *lhs < rhs; }
399 else if (const Wrapped_Selector* lhs = Cast<Wrapped_Selector>(this)) {return *lhs < rhs; }
400 else if (const Attribute_Selector* lhs = Cast<Attribute_Selector>(this)) {return *lhs < rhs; }
402 { return name_ < rhs.name_; }
403 return ns_ < rhs.ns_;
406 bool Selector_List::operator== (const Selector& rhs) const
408 // solve the double dispatch problem by using RTTI information via dynamic cast
409 if (Selector_List_Ptr_Const ls = Cast<Selector_List>(&rhs)) { return *this == *ls; }
410 else if (Complex_Selector_Ptr_Const ls = Cast<Complex_Selector>(&rhs)) { return *this == *ls; }
411 else if (Compound_Selector_Ptr_Const ls = Cast<Compound_Selector>(&rhs)) { return *this == *ls; }
416 // Selector lists can be compared to comma lists
417 bool Selector_List::operator==(const Expression& rhs) const
419 // solve the double dispatch problem by using RTTI information via dynamic cast
420 if (List_Ptr_Const ls = Cast<List>(&rhs)) { return *this == *ls; }
421 if (Selector_Ptr_Const ls = Cast<Selector>(&rhs)) { return *this == *ls; }
422 // compare invalid (maybe we should error?)
426 bool Selector_List::operator== (const Selector_List& rhs) const
430 size_t iL = length();
431 size_t nL = rhs.length();
432 // create temporary vectors and sort them
433 std::vector<Complex_Selector_Obj> l_lst = this->elements();
434 std::vector<Complex_Selector_Obj> r_lst = rhs.elements();
435 std::sort(l_lst.begin(), l_lst.end(), OrderNodes());
436 std::sort(r_lst.begin(), r_lst.end(), OrderNodes());
440 // first check for valid index
441 if (i == iL) return iL == nL;
442 else if (n == nL) return iL == nL;
443 // the access the vector items
444 Complex_Selector_Obj l = l_lst[i];
445 Complex_Selector_Obj r = r_lst[n];
459 bool Selector_List::operator< (const Selector& rhs) const
461 if (Selector_List_Ptr_Const sp = Cast<Selector_List>(&rhs)) return *this < *sp;
465 bool Selector_List::operator< (const Selector_List& rhs) const
467 size_t l = rhs.length();
468 if (length() < l) l = length();
469 for (size_t i = 0; i < l; i ++) {
470 if (*at(i) < *rhs.at(i)) return true;
475 Compound_Selector_Ptr Simple_Selector::unify_with(Compound_Selector_Ptr rhs, Context& ctx)
477 for (size_t i = 0, L = rhs->length(); i < L; ++i)
478 { if (to_string(ctx.c_options) == rhs->at(i)->to_string(ctx.c_options)) return rhs; }
480 // check for pseudo elements because they are always last
483 if (typeid(*this) == typeid(Pseudo_Selector) || typeid(*this) == typeid(Wrapped_Selector))
485 for (i = 0, L = rhs->length(); i < L; ++i)
487 if ((Cast<Pseudo_Selector>((*rhs)[i]) || Cast<Wrapped_Selector>((*rhs)[i])) && (*rhs)[L-1]->is_pseudo_element())
488 { found = true; break; }
493 for (i = 0, L = rhs->length(); i < L; ++i)
495 if (Cast<Pseudo_Selector>((*rhs)[i]) || Cast<Wrapped_Selector>((*rhs)[i]))
496 { found = true; break; }
504 rhs->elements().insert(rhs->elements().begin() + i, this);
508 Simple_Selector_Ptr Element_Selector::unify_with(Simple_Selector_Ptr rhs, Context& ctx)
510 // check if ns can be extended
511 // true for no ns or universal
512 if (has_universal_ns())
514 // but dont extend with universal
515 // true for valid ns and universal
516 if (!rhs->is_universal_ns())
518 // overwrite the name if star is given as name
519 if (this->name() == "*") { this->name(rhs->name()); }
520 // now overwrite the namespace name and flag
521 this->ns(rhs->ns()); this->has_ns(rhs->has_ns());
526 // namespace may changed, check the name now
527 // overwrite star (but not with another star)
528 if (name() == "*" && rhs->name() != "*")
530 // simply set the new name
531 this->name(rhs->name());
539 Compound_Selector_Ptr Element_Selector::unify_with(Compound_Selector_Ptr rhs, Context& ctx)
541 // TODO: handle namespaces
543 // if the rhs is empty, just return a copy of this
544 if (rhs->length() == 0) {
549 Simple_Selector_Ptr rhs_0 = rhs->at(0);
550 // otherwise, this is a tag name
553 if (typeid(*rhs_0) == typeid(Element_Selector))
555 // if rhs is universal, just return this tagname + rhs's qualifiers
556 Element_Selector_Ptr ts = Cast<Element_Selector>(rhs_0);
557 rhs->at(0) = this->unify_with(ts, ctx);
560 else if (Cast<Class_Selector>(rhs_0) || Cast<Id_Selector>(rhs_0)) {
561 // qualifier is `.class`, so we can prefix with `ns|*.class`
562 if (has_ns() && !rhs_0->has_ns()) {
563 if (ns() != "*") rhs->elements().insert(rhs->begin(), this);
572 if (typeid(*rhs_0) == typeid(Element_Selector))
574 // if rhs is universal, just return this tagname + rhs's qualifiers
575 if (rhs_0->name() != "*" && rhs_0->ns() != "*" && rhs_0->name() != name()) return 0;
576 // otherwise create new compound and unify first simple selector
577 rhs->at(0) = this->unify_with(rhs_0, ctx);
581 // else it's a tag name and a bunch of qualifiers -- just append them
582 if (name() != "*") rhs->elements().insert(rhs->begin(), this);
586 Compound_Selector_Ptr Class_Selector::unify_with(Compound_Selector_Ptr rhs, Context& ctx)
588 rhs->has_line_break(has_line_break());
589 return Simple_Selector::unify_with(rhs, ctx);
592 Compound_Selector_Ptr Id_Selector::unify_with(Compound_Selector_Ptr rhs, Context& ctx)
594 for (size_t i = 0, L = rhs->length(); i < L; ++i)
596 if (Id_Selector_Ptr sel = Cast<Id_Selector>(rhs->at(i))) {
597 if (sel->name() != name()) return 0;
600 rhs->has_line_break(has_line_break());
601 return Simple_Selector::unify_with(rhs, ctx);
604 Compound_Selector_Ptr Pseudo_Selector::unify_with(Compound_Selector_Ptr rhs, Context& ctx)
606 if (is_pseudo_element())
608 for (size_t i = 0, L = rhs->length(); i < L; ++i)
610 if (Pseudo_Selector_Ptr sel = Cast<Pseudo_Selector>(rhs->at(i))) {
611 if (sel->is_pseudo_element() && sel->name() != name()) return 0;
615 return Simple_Selector::unify_with(rhs, ctx);
618 bool Attribute_Selector::operator< (const Attribute_Selector& rhs) const
621 if (name() == rhs.name()) {
622 if (matcher() == rhs.matcher()) {
623 bool no_lhs_val = value().isNull();
624 bool no_rhs_val = rhs.value().isNull();
625 if (no_lhs_val && no_rhs_val) return false; // equal
626 else if (no_lhs_val) return true; // lhs is null
627 else if (no_rhs_val) return false; // rhs is null
628 return *value() < *rhs.value(); // both are given
629 } else { return matcher() < rhs.matcher(); }
630 } else { return name() < rhs.name(); }
631 } else { return ns() < rhs.ns(); }
634 bool Attribute_Selector::operator< (const Simple_Selector& rhs) const
636 if (Attribute_Selector_Ptr_Const w = Cast<Attribute_Selector>(&rhs))
641 { return name() < rhs.name(); }
642 return ns() < rhs.ns();
645 bool Attribute_Selector::operator== (const Attribute_Selector& rhs) const
647 // get optional value state
648 bool no_lhs_val = value().isNull();
649 bool no_rhs_val = rhs.value().isNull();
650 // both are null, therefore equal
651 if (no_lhs_val && no_rhs_val) {
652 return (name() == rhs.name())
653 && (matcher() == rhs.matcher())
656 // both are defined, evaluate
657 if (no_lhs_val == no_rhs_val) {
658 return (name() == rhs.name())
659 && (matcher() == rhs.matcher())
661 && (*value() == *rhs.value());
668 bool Attribute_Selector::operator== (const Simple_Selector& rhs) const
670 if (Attribute_Selector_Ptr_Const w = Cast<Attribute_Selector>(&rhs))
674 return is_ns_eq(rhs) &&
675 name() == rhs.name();
678 bool Pseudo_Selector::operator== (const Pseudo_Selector& rhs) const
680 if (is_ns_eq(rhs) && name() == rhs.name())
682 String_Obj lhs_ex = expression();
683 String_Obj rhs_ex = rhs.expression();
684 if (rhs_ex && lhs_ex) return *lhs_ex == *rhs_ex;
685 else return lhs_ex.ptr() == rhs_ex.ptr();
690 bool Pseudo_Selector::operator== (const Simple_Selector& rhs) const
692 if (Pseudo_Selector_Ptr_Const w = Cast<Pseudo_Selector>(&rhs))
696 return is_ns_eq(rhs) &&
697 name() == rhs.name();
700 bool Pseudo_Selector::operator< (const Pseudo_Selector& rhs) const
702 if (is_ns_eq(rhs) && name() == rhs.name())
704 String_Obj lhs_ex = expression();
705 String_Obj rhs_ex = rhs.expression();
706 if (rhs_ex && lhs_ex) return *lhs_ex < *rhs_ex;
707 else return lhs_ex.ptr() < rhs_ex.ptr();
710 { return name() < rhs.name(); }
711 return ns() < rhs.ns();
714 bool Pseudo_Selector::operator< (const Simple_Selector& rhs) const
716 if (Pseudo_Selector_Ptr_Const w = Cast<Pseudo_Selector>(&rhs))
721 { return name() < rhs.name(); }
722 return ns() < rhs.ns();
725 bool Wrapped_Selector::operator== (const Wrapped_Selector& rhs) const
727 if (is_ns_eq(rhs) && name() == rhs.name())
728 { return *(selector()) == *(rhs.selector()); }
732 bool Wrapped_Selector::operator== (const Simple_Selector& rhs) const
734 if (Wrapped_Selector_Ptr_Const w = Cast<Wrapped_Selector>(&rhs))
738 return is_ns_eq(rhs) &&
739 name() == rhs.name();
742 bool Wrapped_Selector::operator< (const Wrapped_Selector& rhs) const
744 if (is_ns_eq(rhs) && name() == rhs.name())
745 { return *(selector()) < *(rhs.selector()); }
747 { return name() < rhs.name(); }
748 return ns() < rhs.ns();
751 bool Wrapped_Selector::operator< (const Simple_Selector& rhs) const
753 if (Wrapped_Selector_Ptr_Const w = Cast<Wrapped_Selector>(&rhs))
758 { return name() < rhs.name(); }
759 return ns() < rhs.ns();
762 bool Wrapped_Selector::is_superselector_of(Wrapped_Selector_Obj sub)
764 if (this->name() != sub->name()) return false;
765 if (this->name() == ":current") return false;
766 if (Selector_List_Obj rhs_list = Cast<Selector_List>(sub->selector())) {
767 if (Selector_List_Obj lhs_list = Cast<Selector_List>(selector())) {
768 return lhs_list->is_superselector_of(rhs_list);
771 error("is_superselector expected a Selector_List", sub->pstate());
775 bool Compound_Selector::is_superselector_of(Selector_List_Obj rhs, std::string wrapped)
777 for (Complex_Selector_Obj item : rhs->elements()) {
778 if (is_superselector_of(item, wrapped)) return true;
783 bool Compound_Selector::is_superselector_of(Complex_Selector_Obj rhs, std::string wrapped)
785 if (rhs->head()) return is_superselector_of(rhs->head(), wrapped);
789 bool Compound_Selector::is_superselector_of(Compound_Selector_Obj rhs, std::string wrapping)
791 Compound_Selector_Ptr lhs = this;
792 Simple_Selector_Ptr lbase = lhs->base();
793 Simple_Selector_Ptr rbase = rhs->base();
795 // Check if pseudo-elements are the same between the selectors
797 std::set<std::string> lpsuedoset, rpsuedoset;
798 for (size_t i = 0, L = length(); i < L; ++i)
800 if ((*this)[i]->is_pseudo_element()) {
801 std::string pseudo((*this)[i]->to_string());
802 pseudo = pseudo.substr(pseudo.find_first_not_of(":")); // strip off colons to ensure :after matches ::after since ruby sass is forgiving
803 lpsuedoset.insert(pseudo);
806 for (size_t i = 0, L = rhs->length(); i < L; ++i)
808 if ((*rhs)[i]->is_pseudo_element()) {
809 std::string pseudo((*rhs)[i]->to_string());
810 pseudo = pseudo.substr(pseudo.find_first_not_of(":")); // strip off colons to ensure :after matches ::after since ruby sass is forgiving
811 rpsuedoset.insert(pseudo);
814 if (lpsuedoset != rpsuedoset) {
818 // would like to replace this without stringification
819 // https://github.com/sass/sass/issues/2229
820 // SimpleSelectorSet lset, rset;
821 std::set<std::string> lset, rset;
825 if (lbase->to_string() == rbase->to_string()) {
826 for (size_t i = 1, L = length(); i < L; ++i)
827 { lset.insert((*this)[i]->to_string()); }
828 for (size_t i = 1, L = rhs->length(); i < L; ++i)
829 { rset.insert((*rhs)[i]->to_string()); }
830 return includes(rset.begin(), rset.end(), lset.begin(), lset.end());
835 for (size_t i = 0, iL = length(); i < iL; ++i)
837 Selector_Obj lhs = (*this)[i];
838 // very special case for wrapped matches selector
839 if (Wrapped_Selector_Obj wrapped = Cast<Wrapped_Selector>(lhs)) {
840 if (wrapped->name() == ":not") {
841 if (Selector_List_Obj not_list = Cast<Selector_List>(wrapped->selector())) {
842 if (not_list->is_superselector_of(rhs, wrapped->name())) return false;
844 throw std::runtime_error("wrapped not selector is not a list");
847 if (wrapped->name() == ":matches" || wrapped->name() == ":-moz-any") {
848 lhs = wrapped->selector();
849 if (Selector_List_Obj list = Cast<Selector_List>(wrapped->selector())) {
850 if (Compound_Selector_Obj comp = Cast<Compound_Selector>(rhs)) {
851 if (!wrapping.empty() && wrapping != wrapped->name()) return false;
852 if (wrapping.empty() || wrapping != wrapped->name()) {;
853 if (list->is_superselector_of(comp, wrapped->name())) return true;
858 Simple_Selector_Ptr rhs_sel = NULL;
859 if (rhs->elements().size() > i) rhs_sel = (*rhs)[i];
860 if (Wrapped_Selector_Ptr wrapped_r = Cast<Wrapped_Selector>(rhs_sel)) {
861 if (wrapped->name() == wrapped_r->name()) {
862 if (wrapped->is_superselector_of(wrapped_r)) {
864 rset.insert(lhs->to_string());
869 // match from here on as strings
870 lset.insert(lhs->to_string());
873 for (size_t n = 0, nL = rhs->length(); n < nL; ++n)
875 Selector_Obj r = (*rhs)[n];
876 if (Wrapped_Selector_Obj wrapped = Cast<Wrapped_Selector>(r)) {
877 if (wrapped->name() == ":not") {
878 if (Selector_List_Obj ls = Cast<Selector_List>(wrapped->selector())) {
879 ls->remove_parent_selectors();
880 if (is_superselector_of(ls, wrapped->name())) return false;
883 if (wrapped->name() == ":matches" || wrapped->name() == ":-moz-any") {
884 if (!wrapping.empty()) {
885 if (wrapping != wrapped->name()) return false;
887 if (Selector_List_Obj ls = Cast<Selector_List>(wrapped->selector())) {
888 ls->remove_parent_selectors();
889 return (is_superselector_of(ls, wrapped->name()));
893 rset.insert(r->to_string());
896 //for (auto l : lset) { cerr << "l: " << l << endl; }
897 //for (auto r : rset) { cerr << "r: " << r << endl; }
899 if (lset.empty()) return true;
900 // return true if rset contains all the elements of lset
901 return includes(rset.begin(), rset.end(), lset.begin(), lset.end());
905 // create complex selector (ancestor of) from compound selector
906 Complex_Selector_Obj Compound_Selector::to_complex()
908 // create an intermediate complex selector
909 return SASS_MEMORY_NEW(Complex_Selector,
911 Complex_Selector::ANCESTOR_OF,
916 Selector_List_Ptr Complex_Selector::unify_with(Complex_Selector_Ptr other, Context& ctx)
919 // get last tails (on the right side)
920 Complex_Selector_Obj l_last = this->last();
921 Complex_Selector_Obj r_last = other->last();
923 // check valid pointers (assertion)
924 SASS_ASSERT(l_last, "lhs is null");
925 SASS_ASSERT(r_last, "rhs is null");
927 // Not sure about this check, but closest way I could check
928 // was to see if this is a ruby 'SimpleSequence' equivalent.
929 // It seems to do the job correctly as some specs react to this
930 if (l_last->combinator() != Combinator::ANCESTOR_OF) return 0;
931 if (r_last->combinator() != Combinator::ANCESTOR_OF ) return 0;
933 // get the headers for the last tails
934 Compound_Selector_Obj l_last_head = l_last->head();
935 Compound_Selector_Obj r_last_head = r_last->head();
937 // check valid head pointers (assertion)
938 SASS_ASSERT(l_last_head, "lhs head is null");
939 SASS_ASSERT(r_last_head, "rhs head is null");
941 // get the unification of the last compound selectors
942 Compound_Selector_Obj unified = r_last_head->unify_with(l_last_head, ctx);
944 // abort if we could not unify heads
945 if (unified == 0) return 0;
947 // check for universal (star: `*`) selector
948 bool is_universal = l_last_head->is_universal() ||
949 r_last_head->is_universal();
955 r_last->head(unified);
958 // create nodes from both selectors
959 Node lhsNode = complexSelectorToNode(this, ctx);
960 Node rhsNode = complexSelectorToNode(other, ctx);
962 // overwrite universal base
965 // create some temporaries to convert to node
966 Complex_Selector_Obj fake = unified->to_complex();
967 Node unified_node = complexSelectorToNode(fake, ctx);
968 // add to permutate the list?
969 rhsNode.plus(unified_node);
972 // do some magic we inherit from node and extend
973 Node node = Extend::subweave(lhsNode, rhsNode, ctx);
974 Selector_List_Ptr result = SASS_MEMORY_NEW(Selector_List, pstate());
975 NodeDequePtr col = node.collection(); // move from collection to list
976 for (NodeDeque::iterator it = col->begin(), end = col->end(); it != end; it++)
977 { result->append(nodeToComplexSelector(Node::naiveTrim(*it, ctx), ctx)); }
979 // only return if list has some entries
980 return result->length() ? result : 0;
984 bool Compound_Selector::operator== (const Compound_Selector& rhs) const
988 size_t iL = length();
989 size_t nL = rhs.length();
990 // create temporary vectors and sort them
991 std::vector<Simple_Selector_Obj> l_lst = this->elements();
992 std::vector<Simple_Selector_Obj> r_lst = rhs.elements();
993 std::sort(l_lst.begin(), l_lst.end(), OrderNodes());
994 std::sort(r_lst.begin(), r_lst.end(), OrderNodes());
998 // first check for valid index
999 if (i == iL) return iL == nL;
1000 else if (n == nL) return iL == nL;
1001 // the access the vector items
1002 Simple_Selector_Obj l = l_lst[i];
1003 Simple_Selector_Obj r = r_lst[n];
1017 bool Complex_Selector::is_superselector_of(Compound_Selector_Obj rhs, std::string wrapping)
1019 return last()->head() && last()->head()->is_superselector_of(rhs, wrapping);
1022 bool Complex_Selector::is_superselector_of(Complex_Selector_Obj rhs, std::string wrapping)
1024 Complex_Selector_Ptr lhs = this;
1025 // check for selectors with leading or trailing combinators
1026 if (!lhs->head() || !rhs->head())
1028 Complex_Selector_Obj l_innermost = lhs->innermost();
1029 if (l_innermost->combinator() != Complex_Selector::ANCESTOR_OF)
1031 Complex_Selector_Obj r_innermost = rhs->innermost();
1032 if (r_innermost->combinator() != Complex_Selector::ANCESTOR_OF)
1034 // more complex (i.e., longer) selectors are always more specific
1035 size_t l_len = lhs->length(), r_len = rhs->length();
1040 { return lhs->head()->is_superselector_of(rhs->last()->head(), wrapping); }
1042 // we have to look one tail deeper, since we cary the
1043 // combinator around for it (which is important here)
1044 if (rhs->tail() && lhs->tail() && combinator() != Complex_Selector::ANCESTOR_OF) {
1045 Complex_Selector_Obj lhs_tail = lhs->tail();
1046 Complex_Selector_Obj rhs_tail = rhs->tail();
1047 if (lhs_tail->combinator() != rhs_tail->combinator()) return false;
1048 if (lhs_tail->head() && !rhs_tail->head()) return false;
1049 if (!lhs_tail->head() && rhs_tail->head()) return false;
1050 if (lhs_tail->head() && rhs_tail->head()) {
1051 if (!lhs_tail->head()->is_superselector_of(rhs_tail->head())) return false;
1056 Complex_Selector_Obj marker = rhs;
1057 for (size_t i = 0, L = rhs->length(); i < L; ++i) {
1060 if (lhs->head() && marker->head() && lhs->head()->is_superselector_of(marker->head(), wrapping))
1061 { found = true; break; }
1062 marker = marker->tail();
1068 Hmm, I hope I have the logic right:
1070 if lhs has a combinator:
1071 if !(marker has a combinator) return false
1072 if !(lhs.combinator == '~' ? marker.combinator != '>' : lhs.combinator == marker.combinator) return false
1073 return lhs.tail-without-innermost.is_superselector_of(marker.tail-without-innermost)
1074 else if marker has a combinator:
1075 if !(marker.combinator == ">") return false
1076 return lhs.tail.is_superselector_of(marker.tail)
1078 return lhs.tail.is_superselector_of(marker.tail)
1080 if (lhs->combinator() != Complex_Selector::ANCESTOR_OF)
1082 if (marker->combinator() == Complex_Selector::ANCESTOR_OF)
1084 if (!(lhs->combinator() == Complex_Selector::PRECEDES ? marker->combinator() != Complex_Selector::PARENT_OF : lhs->combinator() == marker->combinator()))
1086 return lhs->tail()->is_superselector_of(marker->tail());
1088 else if (marker->combinator() != Complex_Selector::ANCESTOR_OF)
1090 if (marker->combinator() != Complex_Selector::PARENT_OF)
1092 return lhs->tail()->is_superselector_of(marker->tail());
1096 return lhs->tail()->is_superselector_of(marker->tail());
1102 size_t Complex_Selector::length() const
1104 // TODO: make this iterative
1105 if (!tail()) return 1;
1106 return 1 + tail()->length();
1109 // append another complex selector at the end
1110 // check if we need to append some headers
1111 // then we need to check for the combinator
1112 // only then we can safely set the new tail
1113 void Complex_Selector::append(Context& ctx, Complex_Selector_Obj ss)
1116 Complex_Selector_Obj t = ss->tail();
1117 Combinator c = ss->combinator();
1118 String_Obj r = ss->reference();
1119 Compound_Selector_Obj h = ss->head();
1121 if (ss->has_line_feed()) has_line_feed(true);
1122 if (ss->has_line_break()) has_line_break(true);
1124 // append old headers
1125 if (h && h->length()) {
1126 if (last()->combinator() != ANCESTOR_OF && c != ANCESTOR_OF) {
1127 error("Invalid parent selector", pstate_);
1128 } else if (last()->head_ && last()->head_->length()) {
1129 Compound_Selector_Obj rh = last()->head();
1130 size_t i = 0, L = h->length();
1131 if (Cast<Element_Selector>(h->first())) {
1132 if (Class_Selector_Ptr sq = Cast<Class_Selector>(rh->last())) {
1133 Class_Selector_Ptr sqs = SASS_MEMORY_COPY(sq);
1134 sqs->name(sqs->name() + (*h)[0]->name());
1135 sqs->pstate((*h)[0]->pstate());
1136 (*rh)[rh->length()-1] = sqs;
1137 rh->pstate(h->pstate());
1138 for (i = 1; i < L; ++i) rh->append((*h)[i]);
1139 } else if (Id_Selector_Ptr sq = Cast<Id_Selector>(rh->last())) {
1140 Id_Selector_Ptr sqs = SASS_MEMORY_COPY(sq);
1141 sqs->name(sqs->name() + (*h)[0]->name());
1142 sqs->pstate((*h)[0]->pstate());
1143 (*rh)[rh->length()-1] = sqs;
1144 rh->pstate(h->pstate());
1145 for (i = 1; i < L; ++i) rh->append((*h)[i]);
1146 } else if (Element_Selector_Ptr ts = Cast<Element_Selector>(rh->last())) {
1147 Element_Selector_Ptr tss = SASS_MEMORY_COPY(ts);
1148 tss->name(tss->name() + (*h)[0]->name());
1149 tss->pstate((*h)[0]->pstate());
1150 (*rh)[rh->length()-1] = tss;
1151 rh->pstate(h->pstate());
1152 for (i = 1; i < L; ++i) rh->append((*h)[i]);
1153 } else if (Placeholder_Selector_Ptr ps = Cast<Placeholder_Selector>(rh->last())) {
1154 Placeholder_Selector_Ptr pss = SASS_MEMORY_COPY(ps);
1155 pss->name(pss->name() + (*h)[0]->name());
1156 pss->pstate((*h)[0]->pstate());
1157 (*rh)[rh->length()-1] = pss;
1158 rh->pstate(h->pstate());
1159 for (i = 1; i < L; ++i) rh->append((*h)[i]);
1161 last()->head_->concat(h);
1164 last()->head_->concat(h);
1167 last()->head_->concat(h);
1170 // std::cerr << "has no or empty head\n";
1174 if (last()->combinator() != ANCESTOR_OF && c != ANCESTOR_OF) {
1175 Complex_Selector_Ptr inter = SASS_MEMORY_NEW(Complex_Selector, pstate());
1176 inter->reference(r);
1177 inter->combinator(c);
1179 last()->tail(inter);
1181 if (last()->combinator() == ANCESTOR_OF) {
1182 last()->combinator(c);
1183 last()->reference(r);
1191 Selector_List_Obj Selector_List::eval(Eval& eval)
1193 Selector_List_Obj list = schema() ?
1194 eval(schema()) : eval(this);
1195 list->schema(schema());
1199 Selector_List_Ptr Selector_List::resolve_parent_refs(Context& ctx, std::vector<Selector_List_Obj>& pstack, bool implicit_parent)
1201 if (!this->has_parent_ref()) return this;
1202 Selector_List_Ptr ss = SASS_MEMORY_NEW(Selector_List, pstate());
1203 Selector_List_Ptr ps = pstack.back();
1204 for (size_t pi = 0, pL = ps->length(); pi < pL; ++pi) {
1205 for (size_t si = 0, sL = this->length(); si < sL; ++si) {
1206 Selector_List_Obj rv = at(si)->resolve_parent_refs(ctx, pstack, implicit_parent);
1213 Selector_List_Ptr Complex_Selector::resolve_parent_refs(Context& ctx, std::vector<Selector_List_Obj>& pstack, bool implicit_parent)
1215 Complex_Selector_Obj tail = this->tail();
1216 Compound_Selector_Obj head = this->head();
1217 Selector_List_Ptr parents = pstack.back();
1219 if (!this->has_real_parent_ref() && !implicit_parent) {
1220 Selector_List_Ptr retval = SASS_MEMORY_NEW(Selector_List, pstate());
1221 retval->append(this);
1225 // first resolve_parent_refs the tail (which may return an expanded list)
1226 Selector_List_Obj tails = tail ? tail->resolve_parent_refs(ctx, pstack, implicit_parent) : 0;
1228 if (head && head->length() > 0) {
1230 Selector_List_Obj retval;
1231 // we have a parent selector in a simple compound list
1232 // mix parent complex selector into the compound list
1233 if (Cast<Parent_Selector>((*head)[0])) {
1234 retval = SASS_MEMORY_NEW(Selector_List, pstate());
1236 // it turns out that real parent references reach
1237 // across @at-root rules, which comes unexpected
1238 if (parents == NULL && head->has_real_parent_ref()) {
1239 int i = pstack.size() - 1;
1240 while (!parents && i > -1) {
1241 parents = pstack.at(i--);
1245 if (parents && parents->length()) {
1246 if (tails && tails->length() > 0) {
1247 for (size_t n = 0, nL = tails->length(); n < nL; ++n) {
1248 for (size_t i = 0, iL = parents->length(); i < iL; ++i) {
1249 Complex_Selector_Obj t = (*tails)[n];
1250 Complex_Selector_Obj parent = (*parents)[i];
1251 Complex_Selector_Obj s = SASS_MEMORY_CLONE(parent);
1252 Complex_Selector_Obj ss = SASS_MEMORY_CLONE(this);
1253 ss->tail(t ? SASS_MEMORY_CLONE(t) : NULL);
1254 Compound_Selector_Obj h = SASS_MEMORY_COPY(head_);
1255 // remove parent selector from sequence
1257 h->erase(h->begin());
1262 // adjust for parent selector (1 char)
1264 ParserState state(h->at(0)->pstate());
1265 state.offset.column += 1;
1267 (*h)[0]->pstate(state);
1269 // keep old parser state
1270 s->pstate(pstate());
1277 // have no tails but parents
1278 // loop above is inside out
1280 for (size_t i = 0, iL = parents->length(); i < iL; ++i) {
1281 Complex_Selector_Obj parent = (*parents)[i];
1282 Complex_Selector_Obj s = SASS_MEMORY_CLONE(parent);
1283 Complex_Selector_Obj ss = SASS_MEMORY_CLONE(this);
1284 // this is only if valid if the parent has no trailing op
1285 // otherwise we cannot append more simple selectors to head
1286 if (parent->last()->combinator() != ANCESTOR_OF) {
1287 throw Exception::InvalidParent(parent, ss);
1289 ss->tail(tail ? SASS_MEMORY_CLONE(tail) : NULL);
1290 Compound_Selector_Obj h = SASS_MEMORY_COPY(head_);
1291 // remove parent selector from sequence
1293 h->erase(h->begin());
1298 // \/ IMO ruby sass bug \/
1299 ss->has_line_feed(false);
1300 // adjust for parent selector (1 char)
1302 ParserState state(h->at(0)->pstate());
1303 state.offset.column += 1;
1305 (*h)[0]->pstate(state);
1307 // keep old parser state
1308 s->pstate(pstate());
1315 // have no parent but some tails
1317 if (tails && tails->length() > 0) {
1318 for (size_t n = 0, nL = tails->length(); n < nL; ++n) {
1319 Complex_Selector_Obj cpy = SASS_MEMORY_CLONE(this);
1320 cpy->tail(SASS_MEMORY_CLONE(tails->at(n)));
1321 cpy->head(SASS_MEMORY_NEW(Compound_Selector, head->pstate()));
1322 for (size_t i = 1, L = this->head()->length(); i < L; ++i)
1323 cpy->head()->append((*this->head())[i]);
1324 if (!cpy->head()->length()) cpy->head(0);
1325 retval->append(cpy->skip_empty_reference());
1328 // have no parent nor tails
1330 Complex_Selector_Obj cpy = SASS_MEMORY_CLONE(this);
1331 cpy->head(SASS_MEMORY_NEW(Compound_Selector, head->pstate()));
1332 for (size_t i = 1, L = this->head()->length(); i < L; ++i)
1333 cpy->head()->append((*this->head())[i]);
1334 if (!cpy->head()->length()) cpy->head(0);
1335 retval->append(cpy->skip_empty_reference());
1339 // no parent selector in head
1341 retval = this->tails(ctx, tails);
1344 for (Simple_Selector_Obj ss : head->elements()) {
1345 if (Wrapped_Selector_Ptr ws = Cast<Wrapped_Selector>(ss)) {
1346 if (Selector_List_Ptr sl = Cast<Selector_List>(ws->selector())) {
1347 if (parents) ws->selector(sl->resolve_parent_refs(ctx, pstack, implicit_parent));
1352 return retval.detach();
1357 return this->tails(ctx, tails);
1364 Selector_List_Ptr Complex_Selector::tails(Context& ctx, Selector_List_Ptr tails)
1366 Selector_List_Ptr rv = SASS_MEMORY_NEW(Selector_List, pstate_);
1367 if (tails && tails->length()) {
1368 for (size_t i = 0, iL = tails->length(); i < iL; ++i) {
1369 Complex_Selector_Obj pr = SASS_MEMORY_CLONE(this);
1370 pr->tail(tails->at(i));
1380 // return the last tail that is defined
1381 Complex_Selector_Obj Complex_Selector::first()
1383 // declare variables used in loop
1384 Complex_Selector_Obj cur = this;
1385 Compound_Selector_Obj head;
1391 // abort (and return) if it is not a parent selector
1392 if (!head || head->length() != 1 || !Cast<Parent_Selector>((*head)[0])) {
1402 // return the last tail that is defined
1403 Complex_Selector_Obj Complex_Selector::last()
1405 Complex_Selector_Ptr cur = this;
1406 Complex_Selector_Ptr nxt = cur;
1415 Complex_Selector::Combinator Complex_Selector::clear_innermost()
1418 if (!tail() || tail()->tail() == 0)
1419 { c = combinator(); combinator(ANCESTOR_OF); tail(0); }
1421 { c = tail()->clear_innermost(); }
1425 void Complex_Selector::set_innermost(Complex_Selector_Obj val, Combinator c)
1428 { tail(val); combinator(c); }
1430 { tail()->set_innermost(val, c); }
1433 void Complex_Selector::cloneChildren()
1435 if (head()) head(SASS_MEMORY_CLONE(head()));
1436 if (tail()) tail(SASS_MEMORY_CLONE(tail()));
1439 void Compound_Selector::cloneChildren()
1441 for (size_t i = 0, l = length(); i < l; i++) {
1442 at(i) = SASS_MEMORY_CLONE(at(i));
1446 void Selector_List::cloneChildren()
1448 for (size_t i = 0, l = length(); i < l; i++) {
1449 at(i) = SASS_MEMORY_CLONE(at(i));
1453 void Wrapped_Selector::cloneChildren()
1455 selector(SASS_MEMORY_CLONE(selector()));
1458 // remove parent selector references
1459 // basically unwraps parsed selectors
1460 void Selector_List::remove_parent_selectors()
1462 // Check every rhs selector against left hand list
1463 for(size_t i = 0, L = length(); i < L; ++i) {
1464 if (!(*this)[i]->head()) continue;
1465 if ((*this)[i]->head()->is_empty_reference()) {
1466 // simply move to the next tail if we have "no" combinator
1467 if ((*this)[i]->combinator() == Complex_Selector::ANCESTOR_OF) {
1468 if ((*this)[i]->tail()) {
1469 if ((*this)[i]->has_line_feed()) {
1470 (*this)[i]->tail()->has_line_feed(true);
1472 (*this)[i] = (*this)[i]->tail();
1475 // otherwise remove the first item from head
1477 (*this)[i]->head()->erase((*this)[i]->head()->begin());
1483 size_t Wrapped_Selector::hash()
1486 hash_combine(hash_, Simple_Selector::hash());
1487 if (selector_) hash_combine(hash_, selector_->hash());
1491 bool Wrapped_Selector::has_parent_ref() const {
1492 // if (has_reference()) return true;
1493 if (!selector()) return false;
1494 return selector()->has_parent_ref();
1496 bool Wrapped_Selector::has_real_parent_ref() const {
1497 // if (has_reference()) return true;
1498 if (!selector()) return false;
1499 return selector()->has_real_parent_ref();
1501 unsigned long Wrapped_Selector::specificity() const
1503 return selector_ ? selector_->specificity() : 0;
1507 bool Selector_List::has_parent_ref() const
1509 for (Complex_Selector_Obj s : elements()) {
1510 if (s && s->has_parent_ref()) return true;
1515 bool Selector_List::has_real_parent_ref() const
1517 for (Complex_Selector_Obj s : elements()) {
1518 if (s && s->has_real_parent_ref()) return true;
1523 bool Selector_Schema::has_parent_ref() const
1525 if (String_Schema_Obj schema = Cast<String_Schema>(contents())) {
1526 return schema->length() > 0 && Cast<Parent_Selector>(schema->at(0)) != NULL;
1531 bool Selector_Schema::has_real_parent_ref() const
1533 if (String_Schema_Obj schema = Cast<String_Schema>(contents())) {
1534 Parent_Selector_Obj p = Cast<Parent_Selector>(schema->at(0));
1535 return schema->length() > 0 && p && p->is_real_parent_ref();
1540 void Selector_List::adjust_after_pushing(Complex_Selector_Obj c)
1542 // if (c->has_reference()) has_reference(true);
1545 // it's a superselector if every selector of the right side
1546 // list is a superselector of the given left side selector
1547 bool Complex_Selector::is_superselector_of(Selector_List_Obj sub, std::string wrapping)
1549 // Check every rhs selector against left hand list
1550 for(size_t i = 0, L = sub->length(); i < L; ++i) {
1551 if (!is_superselector_of((*sub)[i], wrapping)) return false;
1556 // it's a superselector if every selector of the right side
1557 // list is a superselector of the given left side selector
1558 bool Selector_List::is_superselector_of(Selector_List_Obj sub, std::string wrapping)
1560 // Check every rhs selector against left hand list
1561 for(size_t i = 0, L = sub->length(); i < L; ++i) {
1562 if (!is_superselector_of((*sub)[i], wrapping)) return false;
1567 // it's a superselector if every selector on the right side
1568 // is a superselector of any one of the left side selectors
1569 bool Selector_List::is_superselector_of(Compound_Selector_Obj sub, std::string wrapping)
1571 // Check every lhs selector against right hand
1572 for(size_t i = 0, L = length(); i < L; ++i) {
1573 if ((*this)[i]->is_superselector_of(sub, wrapping)) return true;
1578 // it's a superselector if every selector on the right side
1579 // is a superselector of any one of the left side selectors
1580 bool Selector_List::is_superselector_of(Complex_Selector_Obj sub, std::string wrapping)
1582 // Check every lhs selector against right hand
1583 for(size_t i = 0, L = length(); i < L; ++i) {
1584 if ((*this)[i]->is_superselector_of(sub)) return true;
1589 Selector_List_Ptr Selector_List::unify_with(Selector_List_Ptr rhs, Context& ctx) {
1590 std::vector<Complex_Selector_Obj> unified_complex_selectors;
1591 // Unify all of children with RHS's children, storing the results in `unified_complex_selectors`
1592 for (size_t lhs_i = 0, lhs_L = length(); lhs_i < lhs_L; ++lhs_i) {
1593 Complex_Selector_Obj seq1 = (*this)[lhs_i];
1594 for(size_t rhs_i = 0, rhs_L = rhs->length(); rhs_i < rhs_L; ++rhs_i) {
1595 Complex_Selector_Ptr seq2 = rhs->at(rhs_i);
1597 Selector_List_Obj result = seq1->unify_with(seq2, ctx);
1599 for(size_t i = 0, L = result->length(); i < L; ++i) {
1600 unified_complex_selectors.push_back( (*result)[i] );
1606 // Creates the final Selector_List by combining all the complex selectors
1607 Selector_List_Ptr final_result = SASS_MEMORY_NEW(Selector_List, pstate());
1608 for (auto itr = unified_complex_selectors.begin(); itr != unified_complex_selectors.end(); ++itr) {
1609 final_result->append(*itr);
1611 return final_result;
1614 void Selector_List::populate_extends(Selector_List_Obj extendee, Context& ctx, Subset_Map& extends)
1617 Selector_List_Ptr extender = this;
1618 for (auto complex_sel : extendee->elements()) {
1619 Complex_Selector_Obj c = complex_sel;
1622 // Ignore any parent selectors, until we find the first non Selectorerence head
1623 Compound_Selector_Obj compound_sel = c->head();
1624 Complex_Selector_Obj pIter = complex_sel;
1626 Compound_Selector_Obj pHead = pIter->head();
1627 if (pHead && Cast<Parent_Selector>(pHead->elements()[0]) == NULL) {
1628 compound_sel = pHead;
1632 pIter = pIter->tail();
1635 if (!pIter->head() || pIter->tail()) {
1636 error("nested selectors may not be extended", c->pstate());
1639 compound_sel->is_optional(extendee->is_optional());
1641 for (size_t i = 0, L = extender->length(); i < L; ++i) {
1642 extends.put(compound_sel, std::make_pair((*extender)[i], compound_sel));
1647 void Compound_Selector::append(Simple_Selector_Ptr element)
1649 Vectorized<Simple_Selector_Obj>::append(element);
1650 pstate_.offset += element->pstate().offset;
1653 Compound_Selector_Ptr Compound_Selector::minus(Compound_Selector_Ptr rhs, Context& ctx)
1655 Compound_Selector_Ptr result = SASS_MEMORY_NEW(Compound_Selector, pstate());
1656 // result->has_parent_reference(has_parent_reference());
1658 // not very efficient because it needs to preserve order
1659 for (size_t i = 0, L = length(); i < L; ++i)
1662 std::string thisSelector((*this)[i]->to_string(ctx.c_options));
1663 for (size_t j = 0, M = rhs->length(); j < M; ++j)
1665 if (thisSelector == (*rhs)[j]->to_string(ctx.c_options))
1671 if (!found) result->append((*this)[i]);
1677 void Compound_Selector::mergeSources(ComplexSelectorSet& sources, Context& ctx)
1679 for (ComplexSelectorSet::iterator iterator = sources.begin(), endIterator = sources.end(); iterator != endIterator; ++iterator) {
1680 this->sources_.insert(SASS_MEMORY_CLONE(*iterator));
1684 Argument_Obj Arguments::get_rest_argument()
1686 if (this->has_rest_argument()) {
1687 for (Argument_Obj arg : this->elements()) {
1688 if (arg->is_rest_argument()) {
1696 Argument_Obj Arguments::get_keyword_argument()
1698 if (this->has_keyword_argument()) {
1699 for (Argument_Obj arg : this->elements()) {
1700 if (arg->is_keyword_argument()) {
1708 void Arguments::adjust_after_pushing(Argument_Obj a)
1710 if (!a->name().empty()) {
1711 if (/* has_rest_argument_ || */ has_keyword_argument_) {
1712 error("named arguments must precede variable-length argument", a->pstate());
1714 has_named_arguments_ = true;
1716 else if (a->is_rest_argument()) {
1717 if (has_rest_argument_) {
1718 error("functions and mixins may only be called with one variable-length argument", a->pstate());
1720 if (has_keyword_argument_) {
1721 error("only keyword arguments may follow variable arguments", a->pstate());
1723 has_rest_argument_ = true;
1725 else if (a->is_keyword_argument()) {
1726 if (has_keyword_argument_) {
1727 error("functions and mixins may only be called with one keyword argument", a->pstate());
1729 has_keyword_argument_ = true;
1732 if (has_rest_argument_) {
1733 error("ordinal arguments must precede variable-length arguments", a->pstate());
1735 if (has_named_arguments_) {
1736 error("ordinal arguments must precede named arguments", a->pstate());
1741 bool Ruleset::is_invisible() const {
1742 if (Selector_List_Ptr sl = Cast<Selector_List>(selector())) {
1743 for (size_t i = 0, L = sl->length(); i < L; ++i)
1744 if (!(*sl)[i]->has_placeholder()) return false;
1749 bool Media_Block::is_invisible() const {
1750 for (size_t i = 0, L = block()->length(); i < L; ++i) {
1751 Statement_Obj stm = block()->at(i);
1752 if (!stm->is_invisible()) return false;
1757 Number::Number(ParserState pstate, double val, std::string u, bool zero)
1761 numerator_units_(std::vector<std::string>()),
1762 denominator_units_(std::vector<std::string>()),
1765 size_t l = 0, r = 0;
1767 bool nominator = true;
1769 r = u.find_first_of("*/", l);
1770 std::string unit(u.substr(l, r == std::string::npos ? r : r - l));
1771 if (!unit.empty()) {
1772 if (nominator) numerator_units_.push_back(unit);
1773 else denominator_units_.push_back(unit);
1775 if (r == std::string::npos) break;
1776 // ToDo: should error for multiple slashes
1777 // if (!nominator && u[r] == '/') error(...)
1783 concrete_type(NUMBER);
1786 std::string Number::unit() const
1789 for (size_t i = 0, S = numerator_units_.size(); i < S; ++i) {
1791 u += numerator_units_[i];
1793 if (!denominator_units_.empty()) u += '/';
1794 for (size_t i = 0, S = denominator_units_.size(); i < S; ++i) {
1796 u += denominator_units_[i];
1801 bool Number::is_valid_css_unit() const
1803 return numerator_units().size() <= 1 &&
1804 denominator_units().size() == 0;
1807 bool Number::is_unitless() const
1808 { return numerator_units_.empty() && denominator_units_.empty(); }
1810 void Number::normalize(const std::string& prefered, bool strict)
1813 // first make sure same units cancel each other out
1814 // it seems that a map table will fit nicely to do this
1815 // we basically construct exponents for each unit
1816 // has the advantage that they will be pre-sorted
1817 std::map<std::string, int> exponents;
1819 // initialize by summing up occurences in unit vectors
1820 for (size_t i = 0, S = numerator_units_.size(); i < S; ++i) ++ exponents[numerator_units_[i]];
1821 for (size_t i = 0, S = denominator_units_.size(); i < S; ++i) -- exponents[denominator_units_[i]];
1823 // the final conversion factor
1826 // get the first entry of numerators
1827 // forward it when entry is converted
1828 std::vector<std::string>::iterator nom_it = numerator_units_.begin();
1829 std::vector<std::string>::iterator nom_end = numerator_units_.end();
1830 std::vector<std::string>::iterator denom_it = denominator_units_.begin();
1831 std::vector<std::string>::iterator denom_end = denominator_units_.end();
1833 // main normalization loop
1834 // should be close to optimal
1835 while (denom_it != denom_end)
1837 // get and increment afterwards
1838 const std::string denom = *(denom_it ++);
1839 // skip already canceled out unit
1840 if (exponents[denom] >= 0) continue;
1841 // skip all units we don't know how to convert
1842 if (string_to_unit(denom) == UNKNOWN) continue;
1843 // now search for nominator
1844 while (nom_it != nom_end)
1846 // get and increment afterwards
1847 const std::string nom = *(nom_it ++);
1848 // skip already canceled out unit
1849 if (exponents[nom] <= 0) continue;
1850 // skip all units we don't know how to convert
1851 if (string_to_unit(nom) == UNKNOWN) continue;
1852 // we now have two convertable units
1853 // add factor for current conversion
1854 factor *= conversion_factor(nom, denom, strict);
1855 // update nominator/denominator exponent
1856 -- exponents[nom]; ++ exponents[denom];
1862 // now we can build up the new unit arrays
1863 numerator_units_.clear();
1864 denominator_units_.clear();
1866 // build them by iterating over the exponents
1867 for (auto exp : exponents)
1869 // maybe there is more effecient way to push
1870 // the same item multiple times to a vector?
1871 for(size_t i = 0, S = abs(exp.second); i < S; ++i)
1873 // opted to have these switches in the inner loop
1874 // makes it more readable and should not cost much
1875 if (!exp.first.empty()) {
1876 if (exp.second < 0) denominator_units_.push_back(exp.first);
1877 else if (exp.second > 0) numerator_units_.push_back(exp.first);
1882 // apply factor to value_
1883 // best precision this way
1886 // maybe convert to other unit
1887 // easier implemented on its own
1888 try { convert(prefered, strict); }
1889 catch (incompatibleUnits& err)
1890 { error(err.what(), pstate()); }
1891 catch (...) { throw; }
1895 // this does not cover all cases (multiple prefered units)
1896 double Number::convert_factor(const Number& n) const
1899 // first make sure same units cancel each other out
1900 // it seems that a map table will fit nicely to do this
1901 // we basically construct exponents for each unit class
1902 // std::map<std::string, int> exponents;
1903 // initialize by summing up occurences in unit vectors
1904 // for (size_t i = 0, S = numerator_units_.size(); i < S; ++i) ++ exponents[unit_to_class(numerator_units_[i])];
1905 // for (size_t i = 0, S = denominator_units_.size(); i < S; ++i) -- exponents[unit_to_class(denominator_units_[i])];
1907 std::vector<std::string> l_miss_nums(0);
1908 std::vector<std::string> l_miss_dens(0);
1909 // create copy since we need these for state keeping
1910 std::vector<std::string> r_nums(n.numerator_units_);
1911 std::vector<std::string> r_dens(n.denominator_units_);
1913 std::vector<std::string>::const_iterator l_num_it = numerator_units_.begin();
1914 std::vector<std::string>::const_iterator l_num_end = numerator_units_.end();
1916 bool l_unitless = is_unitless();
1917 bool r_unitless = n.is_unitless();
1919 // overall conversion
1922 // process all left numerators
1923 while (l_num_it != l_num_end)
1925 // get and increment afterwards
1926 const std::string l_num = *(l_num_it ++);
1928 std::vector<std::string>::iterator r_num_it = r_nums.begin();
1929 std::vector<std::string>::iterator r_num_end = r_nums.end();
1932 // search for compatible numerator
1933 while (r_num_it != r_num_end)
1935 // get and increment afterwards
1936 const std::string r_num = *(r_num_it);
1937 // get possible converstion factor for units
1938 double conversion = conversion_factor(l_num, r_num, false);
1939 // skip incompatible numerator
1940 if (conversion == 0) {
1944 // apply to global factor
1945 factor *= conversion;
1946 // remove item from vector
1947 r_nums.erase(r_num_it);
1952 // maybe we did not find any
1953 // left numerator is leftover
1954 if (!found) l_miss_nums.push_back(l_num);
1957 std::vector<std::string>::const_iterator l_den_it = denominator_units_.begin();
1958 std::vector<std::string>::const_iterator l_den_end = denominator_units_.end();
1960 // process all left denominators
1961 while (l_den_it != l_den_end)
1963 // get and increment afterwards
1964 const std::string l_den = *(l_den_it ++);
1966 std::vector<std::string>::iterator r_den_it = r_dens.begin();
1967 std::vector<std::string>::iterator r_den_end = r_dens.end();
1970 // search for compatible denominator
1971 while (r_den_it != r_den_end)
1973 // get and increment afterwards
1974 const std::string r_den = *(r_den_it);
1975 // get possible converstion factor for units
1976 double conversion = conversion_factor(l_den, r_den, false);
1977 // skip incompatible denominator
1978 if (conversion == 0) {
1982 // apply to global factor
1983 factor *= conversion;
1984 // remove item from vector
1985 r_dens.erase(r_den_it);
1986 // found denominator
1990 // maybe we did not find any
1991 // left denominator is leftover
1992 if (!found) l_miss_dens.push_back(l_den);
1995 // check left-overs (ToDo: might cancel out)
1996 if (l_miss_nums.size() > 0 && !r_unitless) {
1997 throw Exception::IncompatibleUnits(n, *this);
1999 if (l_miss_dens.size() > 0 && !r_unitless) {
2000 throw Exception::IncompatibleUnits(n, *this);
2002 if (r_nums.size() > 0 && !l_unitless) {
2003 throw Exception::IncompatibleUnits(n, *this);
2005 if (r_dens.size() > 0 && !l_unitless) {
2006 throw Exception::IncompatibleUnits(n, *this);
2012 // this does not cover all cases (multiple prefered units)
2013 bool Number::convert(const std::string& prefered, bool strict)
2015 // no conversion if unit is empty
2016 if (prefered.empty()) return true;
2018 // first make sure same units cancel each other out
2019 // it seems that a map table will fit nicely to do this
2020 // we basically construct exponents for each unit
2021 // has the advantage that they will be pre-sorted
2022 std::map<std::string, int> exponents;
2024 // initialize by summing up occurences in unit vectors
2025 for (size_t i = 0, S = numerator_units_.size(); i < S; ++i) ++ exponents[numerator_units_[i]];
2026 for (size_t i = 0, S = denominator_units_.size(); i < S; ++i) -- exponents[denominator_units_[i]];
2028 // the final conversion factor
2031 std::vector<std::string>::iterator denom_it = denominator_units_.begin();
2032 std::vector<std::string>::iterator denom_end = denominator_units_.end();
2034 // main normalization loop
2035 // should be close to optimal
2036 while (denom_it != denom_end)
2038 // get and increment afterwards
2039 const std::string denom = *(denom_it ++);
2040 // check if conversion is needed
2041 if (denom == prefered) continue;
2042 // skip already canceled out unit
2043 if (exponents[denom] >= 0) continue;
2044 // skip all units we don't know how to convert
2045 if (string_to_unit(denom) == UNKNOWN) continue;
2046 // we now have two convertable units
2047 // add factor for current conversion
2048 factor *= conversion_factor(denom, prefered, strict);
2049 // update nominator/denominator exponent
2050 ++ exponents[denom]; -- exponents[prefered];
2053 std::vector<std::string>::iterator nom_it = numerator_units_.begin();
2054 std::vector<std::string>::iterator nom_end = numerator_units_.end();
2056 // now search for nominator
2057 while (nom_it != nom_end)
2059 // get and increment afterwards
2060 const std::string nom = *(nom_it ++);
2061 // check if conversion is needed
2062 if (nom == prefered) continue;
2063 // skip already canceled out unit
2064 if (exponents[nom] <= 0) continue;
2065 // skip all units we don't know how to convert
2066 if (string_to_unit(nom) == UNKNOWN) continue;
2067 // we now have two convertable units
2068 // add factor for current conversion
2069 factor *= conversion_factor(nom, prefered, strict);
2070 // update nominator/denominator exponent
2071 -- exponents[nom]; ++ exponents[prefered];
2074 // now we can build up the new unit arrays
2075 numerator_units_.clear();
2076 denominator_units_.clear();
2078 // build them by iterating over the exponents
2079 for (auto exp : exponents)
2081 // maybe there is more effecient way to push
2082 // the same item multiple times to a vector?
2083 for(size_t i = 0, S = abs(exp.second); i < S; ++i)
2085 // opted to have these switches in the inner loop
2086 // makes it more readable and should not cost much
2087 if (!exp.first.empty()) {
2088 if (exp.second < 0) denominator_units_.push_back(exp.first);
2089 else if (exp.second > 0) numerator_units_.push_back(exp.first);
2094 // apply factor to value_
2095 // best precision this way
2103 // useful for making one number compatible with another
2104 std::string Number::find_convertible_unit() const
2106 for (size_t i = 0, S = numerator_units_.size(); i < S; ++i) {
2107 std::string u(numerator_units_[i]);
2108 if (string_to_unit(u) != UNKNOWN) return u;
2110 for (size_t i = 0, S = denominator_units_.size(); i < S; ++i) {
2111 std::string u(denominator_units_[i]);
2112 if (string_to_unit(u) != UNKNOWN) return u;
2114 return std::string();
2117 bool Custom_Warning::operator== (const Expression& rhs) const
2119 if (Custom_Warning_Ptr_Const r = Cast<Custom_Warning>(&rhs)) {
2120 return message() == r->message();
2125 bool Custom_Error::operator== (const Expression& rhs) const
2127 if (Custom_Error_Ptr_Const r = Cast<Custom_Error>(&rhs)) {
2128 return message() == r->message();
2133 bool Number::operator== (const Expression& rhs) const
2135 if (Number_Ptr_Const r = Cast<Number>(&rhs)) {
2136 size_t lhs_units = numerator_units_.size() + denominator_units_.size();
2137 size_t rhs_units = r->numerator_units_.size() + r->denominator_units_.size();
2138 // unitless and only having one unit seems equivalent (will change in future)
2139 if (!lhs_units || !rhs_units) {
2140 return std::fabs(value() - r->value()) < NUMBER_EPSILON;
2142 return (numerator_units_ == r->numerator_units_) &&
2143 (denominator_units_ == r->denominator_units_) &&
2144 std::fabs(value() - r->value()) < NUMBER_EPSILON;
2149 bool Number::operator< (const Number& rhs) const
2151 size_t lhs_units = numerator_units_.size() + denominator_units_.size();
2152 size_t rhs_units = rhs.numerator_units_.size() + rhs.denominator_units_.size();
2153 // unitless and only having one unit seems equivalent (will change in future)
2154 if (!lhs_units || !rhs_units) {
2155 return value() < rhs.value();
2158 Number tmp_r(&rhs); // copy
2159 tmp_r.normalize(find_convertible_unit());
2160 std::string l_unit(unit());
2161 std::string r_unit(tmp_r.unit());
2162 if (unit() != tmp_r.unit()) {
2163 error("cannot compare numbers with incompatible units", pstate());
2165 return value() < tmp_r.value();
2168 bool String_Quoted::operator== (const Expression& rhs) const
2170 if (String_Quoted_Ptr_Const qstr = Cast<String_Quoted>(&rhs)) {
2171 return (value() == qstr->value());
2172 } else if (String_Constant_Ptr_Const cstr = Cast<String_Constant>(&rhs)) {
2173 return (value() == cstr->value());
2178 bool String_Constant::is_invisible() const {
2179 return value_.empty() && quote_mark_ == 0;
2182 bool String_Constant::operator== (const Expression& rhs) const
2184 if (String_Quoted_Ptr_Const qstr = Cast<String_Quoted>(&rhs)) {
2185 return (value() == qstr->value());
2186 } else if (String_Constant_Ptr_Const cstr = Cast<String_Constant>(&rhs)) {
2187 return (value() == cstr->value());
2192 bool String_Schema::is_left_interpolant(void) const
2194 return length() && first()->is_left_interpolant();
2196 bool String_Schema::is_right_interpolant(void) const
2198 return length() && last()->is_right_interpolant();
2201 bool String_Schema::operator== (const Expression& rhs) const
2203 if (String_Schema_Ptr_Const r = Cast<String_Schema>(&rhs)) {
2204 if (length() != r->length()) return false;
2205 for (size_t i = 0, L = length(); i < L; ++i) {
2206 Expression_Obj rv = (*r)[i];
2207 Expression_Obj lv = (*this)[i];
2208 if (!lv || !rv) return false;
2209 if (!(*lv == *rv)) return false;
2216 bool Boolean::operator== (const Expression& rhs) const
2218 if (Boolean_Ptr_Const r = Cast<Boolean>(&rhs)) {
2219 return (value() == r->value());
2224 bool Color::operator== (const Expression& rhs) const
2226 if (Color_Ptr_Const r = Cast<Color>(&rhs)) {
2227 return r_ == r->r() &&
2235 bool List::operator== (const Expression& rhs) const
2237 if (List_Ptr_Const r = Cast<List>(&rhs)) {
2238 if (length() != r->length()) return false;
2239 if (separator() != r->separator()) return false;
2240 if (is_bracketed() != r->is_bracketed()) return false;
2241 for (size_t i = 0, L = length(); i < L; ++i) {
2242 Expression_Obj rv = r->at(i);
2243 Expression_Obj lv = this->at(i);
2244 if (!lv || !rv) return false;
2245 if (!(*lv == *rv)) return false;
2252 bool Map::operator== (const Expression& rhs) const
2254 if (Map_Ptr_Const r = Cast<Map>(&rhs)) {
2255 if (length() != r->length()) return false;
2256 for (auto key : keys()) {
2257 Expression_Obj lv = at(key);
2258 Expression_Obj rv = r->at(key);
2259 if (!rv || !lv) return false;
2260 if (!(*lv == *rv)) return false;
2267 bool Null::operator== (const Expression& rhs) const
2269 return rhs.concrete_type() == NULL_VAL;
2272 size_t List::size() const {
2273 if (!is_arglist_) return length();
2274 // arglist expects a list of arguments
2275 // so we need to break before keywords
2276 for (size_t i = 0, L = length(); i < L; ++i) {
2277 Expression_Obj obj = this->at(i);
2278 if (Argument_Ptr arg = Cast<Argument>(obj)) {
2279 if (!arg->name().empty()) return i;
2285 Expression_Obj Hashed::at(Expression_Obj k) const
2287 if (elements_.count(k))
2288 { return elements_.at(k); }
2289 else { return NULL; }
2292 bool Binary_Expression::is_left_interpolant(void) const
2294 return is_interpolant() || (left() && left()->is_left_interpolant());
2296 bool Binary_Expression::is_right_interpolant(void) const
2298 return is_interpolant() || (right() && right()->is_right_interpolant());
2301 const std::string AST_Node::to_string(Sass_Inspect_Options opt) const
2303 Sass_Output_Options out(opt);
2304 Emitter emitter(out);
2306 i.in_declaration = true;
2307 // ToDo: inspect should be const
2308 const_cast<AST_Node_Ptr>(this)->perform(&i);
2309 return i.get_buffer();
2312 const std::string AST_Node::to_string() const
2314 return to_string({ NESTED, 5 });
2317 std::string String_Quoted::inspect() const
2319 return quote(value_, '*');
2322 std::string String_Constant::inspect() const
2324 return quote(value_, '*');
2327 //////////////////////////////////////////////////////////////////////////////////////////
2328 // Additional method on Lists to retrieve values directly or from an encompassed Argument.
2329 //////////////////////////////////////////////////////////////////////////////////////////
2330 Expression_Obj List::value_at_index(size_t i) {
2331 Expression_Obj obj = this->at(i);
2333 if (Argument_Ptr arg = Cast<Argument>(obj)) {
2334 return arg->value();
2343 //////////////////////////////////////////////////////////////////////////////////////////
2344 // Convert map to (key, value) list.
2345 //////////////////////////////////////////////////////////////////////////////////////////
2346 List_Obj Map::to_list(Context& ctx, ParserState& pstate) {
2347 List_Obj ret = SASS_MEMORY_NEW(List, pstate, length(), SASS_COMMA);
2349 for (auto key : keys()) {
2350 List_Obj l = SASS_MEMORY_NEW(List, pstate, 2);
2359 //////////////////////////////////////////////////////////////////////////////////////////
2360 // Copy implementations
2361 //////////////////////////////////////////////////////////////////////////////////////////
2363 #ifdef DEBUG_SHARED_PTR
2365 #define IMPLEMENT_AST_OPERATORS(klass) \
2366 klass##_Ptr klass::copy(std::string file, size_t line) const { \
2367 klass##_Ptr cpy = new klass(this); \
2368 cpy->trace(file, line); \
2371 klass##_Ptr klass::clone(std::string file, size_t line) const { \
2372 klass##_Ptr cpy = copy(file, line); \
2373 cpy->cloneChildren(); \
2379 #define IMPLEMENT_AST_OPERATORS(klass) \
2380 klass##_Ptr klass::copy() const { \
2381 return new klass(this); \
2383 klass##_Ptr klass::clone() const { \
2384 klass##_Ptr cpy = copy(); \
2385 cpy->cloneChildren(); \
2391 IMPLEMENT_AST_OPERATORS(Supports_Operator);
2392 IMPLEMENT_AST_OPERATORS(Supports_Negation);
2393 IMPLEMENT_AST_OPERATORS(Compound_Selector);
2394 IMPLEMENT_AST_OPERATORS(Complex_Selector);
2395 IMPLEMENT_AST_OPERATORS(Element_Selector);
2396 IMPLEMENT_AST_OPERATORS(Class_Selector);
2397 IMPLEMENT_AST_OPERATORS(Id_Selector);
2398 IMPLEMENT_AST_OPERATORS(Pseudo_Selector);
2399 IMPLEMENT_AST_OPERATORS(Wrapped_Selector);
2400 IMPLEMENT_AST_OPERATORS(Selector_List);
2401 IMPLEMENT_AST_OPERATORS(Ruleset);
2402 IMPLEMENT_AST_OPERATORS(Media_Block);
2403 IMPLEMENT_AST_OPERATORS(Custom_Warning);
2404 IMPLEMENT_AST_OPERATORS(Custom_Error);
2405 IMPLEMENT_AST_OPERATORS(List);
2406 IMPLEMENT_AST_OPERATORS(Map);
2407 IMPLEMENT_AST_OPERATORS(Number);
2408 IMPLEMENT_AST_OPERATORS(Binary_Expression);
2409 IMPLEMENT_AST_OPERATORS(String_Schema);
2410 IMPLEMENT_AST_OPERATORS(String_Constant);
2411 IMPLEMENT_AST_OPERATORS(String_Quoted);
2412 IMPLEMENT_AST_OPERATORS(Boolean);
2413 IMPLEMENT_AST_OPERATORS(Color);
2414 IMPLEMENT_AST_OPERATORS(Null);
2415 IMPLEMENT_AST_OPERATORS(Parent_Selector);
2416 IMPLEMENT_AST_OPERATORS(Import);
2417 IMPLEMENT_AST_OPERATORS(Import_Stub);
2418 IMPLEMENT_AST_OPERATORS(Function_Call);
2419 IMPLEMENT_AST_OPERATORS(Directive);
2420 IMPLEMENT_AST_OPERATORS(At_Root_Block);
2421 IMPLEMENT_AST_OPERATORS(Supports_Block);
2422 IMPLEMENT_AST_OPERATORS(While);
2423 IMPLEMENT_AST_OPERATORS(Each);
2424 IMPLEMENT_AST_OPERATORS(For);
2425 IMPLEMENT_AST_OPERATORS(If);
2426 IMPLEMENT_AST_OPERATORS(Mixin_Call);
2427 IMPLEMENT_AST_OPERATORS(Extension);
2428 IMPLEMENT_AST_OPERATORS(Media_Query);
2429 IMPLEMENT_AST_OPERATORS(Media_Query_Expression);
2430 IMPLEMENT_AST_OPERATORS(Debug);
2431 IMPLEMENT_AST_OPERATORS(Error);
2432 IMPLEMENT_AST_OPERATORS(Warning);
2433 IMPLEMENT_AST_OPERATORS(Assignment);
2434 IMPLEMENT_AST_OPERATORS(Return);
2435 IMPLEMENT_AST_OPERATORS(At_Root_Query);
2436 IMPLEMENT_AST_OPERATORS(Variable);
2437 IMPLEMENT_AST_OPERATORS(Comment);
2438 IMPLEMENT_AST_OPERATORS(Attribute_Selector);
2439 IMPLEMENT_AST_OPERATORS(Supports_Interpolation);
2440 IMPLEMENT_AST_OPERATORS(Supports_Declaration);
2441 IMPLEMENT_AST_OPERATORS(Supports_Condition);
2442 IMPLEMENT_AST_OPERATORS(Parameters);
2443 IMPLEMENT_AST_OPERATORS(Parameter);
2444 IMPLEMENT_AST_OPERATORS(Arguments);
2445 IMPLEMENT_AST_OPERATORS(Argument);
2446 IMPLEMENT_AST_OPERATORS(Unary_Expression);
2447 IMPLEMENT_AST_OPERATORS(Function_Call_Schema);
2448 IMPLEMENT_AST_OPERATORS(Block);
2449 IMPLEMENT_AST_OPERATORS(Content);
2450 IMPLEMENT_AST_OPERATORS(Textual);
2451 IMPLEMENT_AST_OPERATORS(Trace);
2452 IMPLEMENT_AST_OPERATORS(Keyframe_Rule);
2453 IMPLEMENT_AST_OPERATORS(Bubble);
2454 IMPLEMENT_AST_OPERATORS(Selector_Schema);
2455 IMPLEMENT_AST_OPERATORS(Placeholder_Selector);
2456 IMPLEMENT_AST_OPERATORS(Definition);
2457 IMPLEMENT_AST_OPERATORS(Declaration);