示例#1
0
  void Inspect::operator()(Complex_Selector* c)
  {
    Compound_Selector*           head = c->head();
    Complex_Selector*            tail = c->tail();
    Complex_Selector::Combinator comb = c->combinator();

    if (c->has_line_feed()) {
      if (!(c->has_parent_ref())) {
        append_optional_linefeed();
        append_indentation();
      }
    }

    if (head && head->length() != 0) head->perform(this);
    bool is_empty = !head || head->length() == 0 || head->is_empty_reference();
    bool is_tail = head && !head->is_empty_reference() && tail;
    if (output_style() == COMPRESSED && comb != Complex_Selector::ANCESTOR_OF) scheduled_space = 0;

    switch (comb) {
      case Complex_Selector::ANCESTOR_OF:
        if (is_tail) append_mandatory_space();
      break;
      case Complex_Selector::PARENT_OF:
        append_optional_space();
        append_string(">");
        append_optional_space();
      break;
      case Complex_Selector::ADJACENT_TO:
        append_optional_space();
        append_string("+");
        append_optional_space();
      break;
      case Complex_Selector::REFERENCE:
        append_mandatory_space();
        append_string("/");
        c->reference()->perform(this);
        append_string("/");
        append_mandatory_space();
      break;
      case Complex_Selector::PRECEDES:
        if (is_empty) append_optional_space();
        else append_mandatory_space();
        append_string("~");
        if (tail) append_mandatory_space();
        else append_optional_space();
      break;
    }
    if (tail && comb != Complex_Selector::ANCESTOR_OF) {
      if (c->has_line_break()) append_optional_linefeed();
    }
    if (tail) tail->perform(this);
    if (!tail && c->has_line_break()) {
      if (output_style() == COMPACT) {
        append_mandatory_space();
      }
    }
  }
示例#2
0
  void roundtripTest(const char* toTest) {

    // Create the initial selector

    Complex_Selector* pOrigSelector = NULL;
    if (toTest) {
      pOrigSelector = createComplexSelector(toTest);
    }
    
    string expected(pOrigSelector ? pOrigSelector->perform(&to_string) : "NULL");
  
    
    // Roundtrip the selector into a node and back
    
    Node node = complexSelectorToNode(pOrigSelector, ctx);
    
    stringstream nodeStringStream;
    nodeStringStream << node;
    string nodeString = nodeStringStream.str();
    cout << "ASNODE: " << node << endl;
    
    Complex_Selector* pNewSelector = nodeToComplexSelector(node, ctx);
    
    // Show the result

    string result(pNewSelector ? pNewSelector->perform(&to_string) : "NULL");
    
    cout << "SELECTOR: " << expected << endl;
    cout << "NEW SELECTOR:   " << result << endl;

    
    // Test that they are equal using the equality operator
    
    assert( (!pOrigSelector && !pNewSelector ) || (pOrigSelector && pNewSelector) );
    if (pOrigSelector) {
	    assert( *pOrigSelector == *pNewSelector );
    }

    
    // Test that they are equal by comparing the string versions of the selectors

    assert(expected == result);
    
  }
示例#3
0
 void Output_Compressed::operator()(Complex_Selector* c)
 {
   Compound_Selector*        head = c->head();
   Complex_Selector*            tail = c->tail();
   Complex_Selector::Combinator comb = c->combinator();
   if (head) head->perform(this);
   switch (comb) {
     case Complex_Selector::ANCESTOR_OF: append_singleline_part_to_buffer(" "); break;
     case Complex_Selector::PARENT_OF:   append_singleline_part_to_buffer(">"); break;
     case Complex_Selector::PRECEDES:    append_singleline_part_to_buffer("~"); break;
     case Complex_Selector::ADJACENT_TO: append_singleline_part_to_buffer("+"); break;
   }
   if (tail) tail->perform(this);
 }
示例#4
0
 void Inspect::operator()(Complex_Selector* c)
 {
   Compound_Selector*           head = c->head();
   Complex_Selector*            tail = c->tail();
   Complex_Selector::Combinator comb = c->combinator();
   if (head && !head->is_empty_reference()) head->perform(this);
   if (head && !head->is_empty_reference() && tail) append_to_buffer(" ");
   switch (comb) {
     case Complex_Selector::ANCESTOR_OF:                                        break;
     case Complex_Selector::PARENT_OF:   append_to_buffer(">"); break;
     case Complex_Selector::PRECEDES:    append_to_buffer("~"); break;
     case Complex_Selector::ADJACENT_TO: append_to_buffer("+"); break;
   }
   if (tail && comb != Complex_Selector::ANCESTOR_OF) {
     append_to_buffer(" ");
   }
   if (tail) tail->perform(this);
 }
示例#5
0
文件: listize.cpp 项目: pra85/libsass
  Expression* Listize::operator()(Complex_Selector* sel)
  {
    List* l = SASS_MEMORY_NEW(mem, List, sel->pstate(), 2);

    Compound_Selector* head = sel->head();
    if (head && !head->is_empty_reference())
    {
      Expression* hh = head->perform(this);
      if (hh) *l << hh;
    }

    To_String to_string;
    std::string reference = ! sel->reference() ? ""
      : sel->reference()->perform(&to_string);
    switch(sel->combinator())
    {
      case Complex_Selector::PARENT_OF:
        *l << SASS_MEMORY_NEW(mem, String_Quoted, sel->pstate(), ">");
      break;
      case Complex_Selector::ADJACENT_TO:
        *l << SASS_MEMORY_NEW(mem, String_Quoted, sel->pstate(), "+");
      break;
      case Complex_Selector::REFERENCE:
        *l << SASS_MEMORY_NEW(mem, String_Quoted, sel->pstate(), "/" + reference + "/");
      break;
      case Complex_Selector::PRECEDES:
        *l << SASS_MEMORY_NEW(mem, String_Quoted, sel->pstate(), "~");
      break;
      case Complex_Selector::ANCESTOR_OF:
      break;
    }

    Complex_Selector* tail = sel->tail();
    if (tail)
    {
      Expression* tt = tail->perform(this);
      if (tt && tt->concrete_type() == Expression::LIST)
      { *l += static_cast<List*>(tt); }
      else if (tt) *l << static_cast<List*>(tt);
    }
    if (l->length() == 0) return 0;
    return l;
  }