Blame src/inspect.cpp

Packit Service 7770af
#include "sass.hpp"
Packit Service 7770af
#include <cmath>
Packit Service 7770af
#include <string>
Packit Service 7770af
#include <iostream>
Packit Service 7770af
#include <iomanip>
Packit Service 7770af
#include <stdint.h>
Packit Service 7770af
#include <stdint.h>
Packit Service 7770af
Packit Service 7770af
#include "ast.hpp"
Packit Service 7770af
#include "inspect.hpp"
Packit Service 7770af
#include "context.hpp"
Packit Service 7770af
#include "listize.hpp"
Packit Service 7770af
#include "color_maps.hpp"
Packit Service 7770af
#include "utf8/checked.h"
Packit Service 7770af
Packit Service 7770af
namespace Sass {
Packit Service 7770af
Packit Service 7770af
  Inspect::Inspect(const Emitter& emi)
Packit Service 7770af
  : Emitter(emi)
Packit Service 7770af
  { }
Packit Service 7770af
  Inspect::~Inspect() { }
Packit Service 7770af
Packit Service 7770af
  // statements
Packit Service 7770af
  void Inspect::operator()(Block_Ptr block)
Packit Service 7770af
  {
Packit Service 7770af
    if (!block->is_root()) {
Packit Service 7770af
      add_open_mapping(block);
Packit Service 7770af
      append_scope_opener();
Packit Service 7770af
    }
Packit Service 7770af
    if (output_style() == NESTED) indentation += block->tabs();
Packit Service 7770af
    for (size_t i = 0, L = block->length(); i < L; ++i) {
Packit Service 7770af
      (*block)[i]->perform(this);
Packit Service 7770af
    }
Packit Service 7770af
    if (output_style() == NESTED) indentation -= block->tabs();
Packit Service 7770af
    if (!block->is_root()) {
Packit Service 7770af
      append_scope_closer();
Packit Service 7770af
      add_close_mapping(block);
Packit Service 7770af
    }
Packit Service 7770af
Packit Service 7770af
  }
Packit Service 7770af
Packit Service 7770af
  void Inspect::operator()(Ruleset_Ptr ruleset)
Packit Service 7770af
  {
Packit Service 7770af
    if (ruleset->selector()) {
Packit Service 7770af
      ruleset->selector()->perform(this);
Packit Service 7770af
    }
Packit Service 7770af
    if (ruleset->block()) {
Packit Service 7770af
      ruleset->block()->perform(this);
Packit Service 7770af
    }
Packit Service 7770af
  }
Packit Service 7770af
Packit Service 7770af
  void Inspect::operator()(Keyframe_Rule_Ptr rule)
Packit Service 7770af
  {
Packit Service 7770af
    if (rule->name()) rule->name()->perform(this);
Packit Service 7770af
    if (rule->block()) rule->block()->perform(this);
Packit Service 7770af
  }
Packit Service 7770af
Packit Service 7770af
  void Inspect::operator()(Bubble_Ptr bubble)
Packit Service 7770af
  {
Packit Service 7770af
    append_indentation();
Packit Service 7770af
    append_token("::BUBBLE", bubble);
Packit Service 7770af
    append_scope_opener();
Packit Service 7770af
    bubble->node()->perform(this);
Packit Service 7770af
    append_scope_closer();
Packit Service 7770af
  }
Packit Service 7770af
Packit Service 7770af
  void Inspect::operator()(Media_Block_Ptr media_block)
Packit Service 7770af
  {
Packit Service 7770af
    append_indentation();
Packit Service 7770af
    append_token("@media", media_block);
Packit Service 7770af
    append_mandatory_space();
Packit Service 7770af
    in_media_block = true;
Packit Service 7770af
    media_block->media_queries()->perform(this);
Packit Service 7770af
    in_media_block = false;
Packit Service 7770af
    media_block->block()->perform(this);
Packit Service 7770af
  }
Packit Service 7770af
Packit Service 7770af
  void Inspect::operator()(Supports_Block_Ptr feature_block)
Packit Service 7770af
  {
Packit Service 7770af
    append_indentation();
Packit Service 7770af
    append_token("@supports", feature_block);
Packit Service 7770af
    append_mandatory_space();
Packit Service 7770af
    feature_block->condition()->perform(this);
Packit Service 7770af
    feature_block->block()->perform(this);
Packit Service 7770af
  }
Packit Service 7770af
Packit Service 7770af
  void Inspect::operator()(At_Root_Block_Ptr at_root_block)
Packit Service 7770af
  {
Packit Service 7770af
    append_indentation();
Packit Service 7770af
    append_token("@at-root ", at_root_block);
Packit Service 7770af
    append_mandatory_space();
Packit Service 7770af
    if(at_root_block->expression()) at_root_block->expression()->perform(this);
Packit Service 7770af
    at_root_block->block()->perform(this);
Packit Service 7770af
  }
Packit Service 7770af
Packit Service 7770af
  void Inspect::operator()(Directive_Ptr at_rule)
Packit Service 7770af
  {
Packit Service 7770af
    append_indentation();
Packit Service 7770af
    append_token(at_rule->keyword(), at_rule);
Packit Service 7770af
    if (at_rule->selector()) {
Packit Service 7770af
      append_mandatory_space();
Packit Service 7770af
      bool was_wrapped = in_wrapped;
Packit Service 7770af
      in_wrapped = true;
Packit Service 7770af
      at_rule->selector()->perform(this);
Packit Service 7770af
      in_wrapped = was_wrapped;
Packit Service 7770af
    }
Packit Service 7770af
    if (at_rule->value()) {
Packit Service 7770af
      append_mandatory_space();
Packit Service 7770af
      at_rule->value()->perform(this);
Packit Service 7770af
    }
Packit Service 7770af
    if (at_rule->block()) {
Packit Service 7770af
      at_rule->block()->perform(this);
Packit Service 7770af
    }
Packit Service 7770af
    else {
Packit Service 7770af
      append_delimiter();
Packit Service 7770af
    }
Packit Service 7770af
  }
Packit Service 7770af
Packit Service 7770af
  void Inspect::operator()(Declaration_Ptr dec)
Packit Service 7770af
  {
Packit Service 7770af
    if (dec->value()->concrete_type() == Expression::NULL_VAL) return;
Packit Service 7770af
    bool was_decl = in_declaration;
Packit Service 7770af
    in_declaration = true;
Packit Service 7770af
    if (output_style() == NESTED)
Packit Service 7770af
      indentation += dec->tabs();
Packit Service 7770af
    append_indentation();
Packit Service 7770af
    if (dec->property())
Packit Service 7770af
      dec->property()->perform(this);
Packit Service 7770af
    append_colon_separator();
Packit Service 7770af
Packit Service 7770af
    if (dec->value()->concrete_type() == Expression::SELECTOR) {
Packit Service 7770af
      Listize listize;
Packit Service 7770af
      Expression_Obj ls = dec->value()->perform(&listize);
Packit Service 7770af
      ls->perform(this);
Packit Service 7770af
    } else {
Packit Service 7770af
      dec->value()->perform(this);
Packit Service 7770af
    }
Packit Service 7770af
Packit Service 7770af
    if (dec->is_important()) {
Packit Service 7770af
      append_optional_space();
Packit Service 7770af
      append_string("!important");
Packit Service 7770af
    }
Packit Service 7770af
    append_delimiter();
Packit Service 7770af
    if (output_style() == NESTED)
Packit Service 7770af
      indentation -= dec->tabs();
Packit Service 7770af
    in_declaration = was_decl;
Packit Service 7770af
  }
Packit Service 7770af
Packit Service 7770af
  void Inspect::operator()(Assignment_Ptr assn)
Packit Service 7770af
  {
Packit Service 7770af
    append_token(assn->variable(), assn);
Packit Service 7770af
    append_colon_separator();
Packit Service 7770af
    assn->value()->perform(this);
Packit Service 7770af
    if (assn->is_default()) {
Packit Service 7770af
      append_optional_space();
Packit Service 7770af
      append_string("!default");
Packit Service 7770af
    }
Packit Service 7770af
    append_delimiter();
Packit Service 7770af
  }
Packit Service 7770af
Packit Service 7770af
  void Inspect::operator()(Import_Ptr import)
Packit Service 7770af
  {
Packit Service 7770af
    if (!import->urls().empty()) {
Packit Service 7770af
      append_token("@import", import);
Packit Service 7770af
      append_mandatory_space();
Packit Service 7770af
Packit Service 7770af
      import->urls().front()->perform(this);
Packit Service 7770af
      if (import->urls().size() == 1) {
Packit Service 7770af
        if (import->import_queries()) {
Packit Service 7770af
          append_mandatory_space();
Packit Service 7770af
          import->import_queries()->perform(this);
Packit Service 7770af
        }
Packit Service 7770af
      }
Packit Service 7770af
      append_delimiter();
Packit Service 7770af
      for (size_t i = 1, S = import->urls().size(); i < S; ++i) {
Packit Service 7770af
        append_mandatory_linefeed();
Packit Service 7770af
        append_token("@import", import);
Packit Service 7770af
        append_mandatory_space();
Packit Service 7770af
Packit Service 7770af
        import->urls()[i]->perform(this);
Packit Service 7770af
        if (import->urls().size() - 1 == i) {
Packit Service 7770af
          if (import->import_queries()) {
Packit Service 7770af
            append_mandatory_space();
Packit Service 7770af
            import->import_queries()->perform(this);
Packit Service 7770af
          }
Packit Service 7770af
        }
Packit Service 7770af
        append_delimiter();
Packit Service 7770af
      }
Packit Service 7770af
    }
Packit Service 7770af
  }
Packit Service 7770af
Packit Service 7770af
  void Inspect::operator()(Import_Stub_Ptr import)
Packit Service 7770af
  {
Packit Service 7770af
    append_indentation();
Packit Service 7770af
    append_token("@import", import);
Packit Service 7770af
    append_mandatory_space();
Packit Service 7770af
    append_string(import->imp_path());
Packit Service 7770af
    append_delimiter();
Packit Service 7770af
  }
Packit Service 7770af
Packit Service 7770af
  void Inspect::operator()(Warning_Ptr warning)
Packit Service 7770af
  {
Packit Service 7770af
    append_indentation();
Packit Service 7770af
    append_token("@warn", warning);
Packit Service 7770af
    append_mandatory_space();
Packit Service 7770af
    warning->message()->perform(this);
Packit Service 7770af
    append_delimiter();
Packit Service 7770af
  }
Packit Service 7770af
Packit Service 7770af
  void Inspect::operator()(Error_Ptr error)
Packit Service 7770af
  {
Packit Service 7770af
    append_indentation();
Packit Service 7770af
    append_token("@error", error);
Packit Service 7770af
    append_mandatory_space();
Packit Service 7770af
    error->message()->perform(this);
Packit Service 7770af
    append_delimiter();
Packit Service 7770af
  }
Packit Service 7770af
Packit Service 7770af
  void Inspect::operator()(Debug_Ptr debug)
Packit Service 7770af
  {
Packit Service 7770af
    append_indentation();
Packit Service 7770af
    append_token("@debug", debug);
Packit Service 7770af
    append_mandatory_space();
Packit Service 7770af
    debug->value()->perform(this);
Packit Service 7770af
    append_delimiter();
Packit Service 7770af
  }
Packit Service 7770af
Packit Service 7770af
  void Inspect::operator()(Comment_Ptr comment)
Packit Service 7770af
  {
Packit Service 7770af
    in_comment = true;
Packit Service 7770af
    comment->text()->perform(this);
Packit Service 7770af
    in_comment = false;
Packit Service 7770af
  }
Packit Service 7770af
Packit Service 7770af
  void Inspect::operator()(If_Ptr cond)
Packit Service 7770af
  {
Packit Service 7770af
    append_indentation();
Packit Service 7770af
    append_token("@if", cond);
Packit Service 7770af
    append_mandatory_space();
Packit Service 7770af
    cond->predicate()->perform(this);
Packit Service 7770af
    cond->block()->perform(this);
Packit Service 7770af
    if (cond->alternative()) {
Packit Service 7770af
      append_optional_linefeed();
Packit Service 7770af
      append_indentation();
Packit Service 7770af
      append_string("else");
Packit Service 7770af
      cond->alternative()->perform(this);
Packit Service 7770af
    }
Packit Service 7770af
  }
Packit Service 7770af
Packit Service 7770af
  void Inspect::operator()(For_Ptr loop)
Packit Service 7770af
  {
Packit Service 7770af
    append_indentation();
Packit Service 7770af
    append_token("@for", loop);
Packit Service 7770af
    append_mandatory_space();
Packit Service 7770af
    append_string(loop->variable());
Packit Service 7770af
    append_string(" from ");
Packit Service 7770af
    loop->lower_bound()->perform(this);
Packit Service 7770af
    append_string(loop->is_inclusive() ? " through " : " to ");
Packit Service 7770af
    loop->upper_bound()->perform(this);
Packit Service 7770af
    loop->block()->perform(this);
Packit Service 7770af
  }
Packit Service 7770af
Packit Service 7770af
  void Inspect::operator()(Each_Ptr loop)
Packit Service 7770af
  {
Packit Service 7770af
    append_indentation();
Packit Service 7770af
    append_token("@each", loop);
Packit Service 7770af
    append_mandatory_space();
Packit Service 7770af
    append_string(loop->variables()[0]);
Packit Service 7770af
    for (size_t i = 1, L = loop->variables().size(); i < L; ++i) {
Packit Service 7770af
      append_comma_separator();
Packit Service 7770af
      append_string(loop->variables()[i]);
Packit Service 7770af
    }
Packit Service 7770af
    append_string(" in ");
Packit Service 7770af
    loop->list()->perform(this);
Packit Service 7770af
    loop->block()->perform(this);
Packit Service 7770af
  }
Packit Service 7770af
Packit Service 7770af
  void Inspect::operator()(While_Ptr loop)
Packit Service 7770af
  {
Packit Service 7770af
    append_indentation();
Packit Service 7770af
    append_token("@while", loop);
Packit Service 7770af
    append_mandatory_space();
Packit Service 7770af
    loop->predicate()->perform(this);
Packit Service 7770af
    loop->block()->perform(this);
Packit Service 7770af
  }
Packit Service 7770af
Packit Service 7770af
  void Inspect::operator()(Return_Ptr ret)
Packit Service 7770af
  {
Packit Service 7770af
    append_indentation();
Packit Service 7770af
    append_token("@return", ret);
Packit Service 7770af
    append_mandatory_space();
Packit Service 7770af
    ret->value()->perform(this);
Packit Service 7770af
    append_delimiter();
Packit Service 7770af
  }
Packit Service 7770af
Packit Service 7770af
  void Inspect::operator()(Extension_Ptr extend)
Packit Service 7770af
  {
Packit Service 7770af
    append_indentation();
Packit Service 7770af
    append_token("@extend", extend);
Packit Service 7770af
    append_mandatory_space();
Packit Service 7770af
    extend->selector()->perform(this);
Packit Service 7770af
    append_delimiter();
Packit Service 7770af
  }
Packit Service 7770af
Packit Service 7770af
  void Inspect::operator()(Definition_Ptr def)
Packit Service 7770af
  {
Packit Service 7770af
    append_indentation();
Packit Service 7770af
    if (def->type() == Definition::MIXIN) {
Packit Service 7770af
      append_token("@mixin", def);
Packit Service 7770af
      append_mandatory_space();
Packit Service 7770af
    } else {
Packit Service 7770af
      append_token("@function", def);
Packit Service 7770af
      append_mandatory_space();
Packit Service 7770af
    }
Packit Service 7770af
    append_string(def->name());
Packit Service 7770af
    def->parameters()->perform(this);
Packit Service 7770af
    def->block()->perform(this);
Packit Service 7770af
  }
Packit Service 7770af
Packit Service 7770af
  void Inspect::operator()(Mixin_Call_Ptr call)
Packit Service 7770af
  {
Packit Service 7770af
    append_indentation();
Packit Service 7770af
    append_token("@include", call);
Packit Service 7770af
    append_mandatory_space();
Packit Service 7770af
    append_string(call->name());
Packit Service 7770af
    if (call->arguments()) {
Packit Service 7770af
      call->arguments()->perform(this);
Packit Service 7770af
    }
Packit Service 7770af
    if (call->block()) {
Packit Service 7770af
      append_optional_space();
Packit Service 7770af
      call->block()->perform(this);
Packit Service 7770af
    }
Packit Service 7770af
    if (!call->block()) append_delimiter();
Packit Service 7770af
  }
Packit Service 7770af
Packit Service 7770af
  void Inspect::operator()(Content_Ptr content)
Packit Service 7770af
  {
Packit Service 7770af
    append_indentation();
Packit Service 7770af
    append_token("@content", content);
Packit Service 7770af
    append_delimiter();
Packit Service 7770af
  }
Packit Service 7770af
Packit Service 7770af
  void Inspect::operator()(Map_Ptr map)
Packit Service 7770af
  {
Packit Service 7770af
    if (output_style() == TO_SASS && map->empty()) {
Packit Service 7770af
      append_string("()");
Packit Service 7770af
      return;
Packit Service 7770af
    }
Packit Service 7770af
    if (map->empty()) return;
Packit Service 7770af
    if (map->is_invisible()) return;
Packit Service 7770af
    bool items_output = false;
Packit Service 7770af
    append_string("(");
Packit Service 7770af
    for (auto key : map->keys()) {
Packit Service 7770af
      if (items_output) append_comma_separator();
Packit Service 7770af
      key->perform(this);
Packit Service 7770af
      append_colon_separator();
Packit Service 7770af
      LOCAL_FLAG(in_space_array, true);
Packit Service 7770af
      LOCAL_FLAG(in_comma_array, true);
Packit Service 7770af
      map->at(key)->perform(this);
Packit Service 7770af
      items_output = true;
Packit Service 7770af
    }
Packit Service 7770af
    append_string(")");
Packit Service 7770af
  }
Packit Service 7770af
Packit Service 7770af
  void Inspect::operator()(List_Ptr list)
Packit Service 7770af
  {
Packit Service 7770af
    if (output_style() == TO_SASS && list->empty()) {
Packit Service 7770af
      append_string("()");
Packit Service 7770af
      return;
Packit Service 7770af
    }
Packit Service 7770af
    std::string sep(list->separator() == SASS_SPACE ? " " : ",");
Packit Service 7770af
    if ((output_style() != COMPRESSED) && sep == ",") sep += " ";
Packit Service 7770af
    else if (in_media_block && sep != " ") sep += " "; // verified
Packit Service 7770af
    if (list->empty()) return;
Packit Service 7770af
    bool items_output = false;
Packit Service 7770af
Packit Service 7770af
    bool was_space_array = in_space_array;
Packit Service 7770af
    bool was_comma_array = in_comma_array;
Packit Service 7770af
    // probably ruby sass eqivalent of element_needs_parens
Packit Service 7770af
    if (output_style() == TO_SASS &&
Packit Service 7770af
        list->length() == 1 &&
Packit Service 7770af
        !list->from_selector() &&
Packit Service 7770af
        !Cast<List>(list->at(0)) &&
Packit Service 7770af
        !Cast<Selector_List>(list->at(0))
Packit Service 7770af
    ) {
Packit Service 7770af
      append_string("(");
Packit Service 7770af
    }
Packit Service 7770af
    else if (!in_declaration && (list->separator() == SASS_HASH ||
Packit Service 7770af
        (list->separator() == SASS_SPACE && in_space_array) ||
Packit Service 7770af
        (list->separator() == SASS_COMMA && in_comma_array)
Packit Service 7770af
    )) {
Packit Service 7770af
      append_string("(");
Packit Service 7770af
    }
Packit Service 7770af
Packit Service 7770af
    if (list->separator() == SASS_SPACE) in_space_array = true;
Packit Service 7770af
    else if (list->separator() == SASS_COMMA) in_comma_array = true;
Packit Service 7770af
Packit Service 7770af
    for (size_t i = 0, L = list->size(); i < L; ++i) {
Packit Service 7770af
      if (list->separator() == SASS_HASH)
Packit Service 7770af
      { sep[0] = i % 2 ? ':' : ','; }
Packit Service 7770af
      Expression_Obj list_item = list->at(i);
Packit Service 7770af
      if (output_style() != TO_SASS) {
Packit Service 7770af
        if (list_item->is_invisible()) {
Packit Service 7770af
          // this fixes an issue with "" in a list
Packit Service 7770af
          if (!Cast<String_Constant>(list_item)) {
Packit Service 7770af
            continue;
Packit Service 7770af
          }
Packit Service 7770af
        }
Packit Service 7770af
      }
Packit Service 7770af
      if (items_output) {
Packit Service 7770af
        append_string(sep);
Packit Service 7770af
      }
Packit Service 7770af
      if (items_output && sep != " ")
Packit Service 7770af
        append_optional_space();
Packit Service 7770af
      list_item->perform(this);
Packit Service 7770af
      items_output = true;
Packit Service 7770af
    }
Packit Service 7770af
Packit Service 7770af
    in_comma_array = was_comma_array;
Packit Service 7770af
    in_space_array = was_space_array;
Packit Service 7770af
    // probably ruby sass eqivalent of element_needs_parens
Packit Service 7770af
    if (output_style() == TO_SASS &&
Packit Service 7770af
        list->length() == 1 &&
Packit Service 7770af
        !list->from_selector() &&
Packit Service 7770af
        !Cast<List>(list->at(0)) &&
Packit Service 7770af
        !Cast<Selector_List>(list->at(0))
Packit Service 7770af
    ) {
Packit Service 7770af
      append_string(",)");
Packit Service 7770af
    }
Packit Service 7770af
    else if (!in_declaration && (list->separator() == SASS_HASH ||
Packit Service 7770af
        (list->separator() == SASS_SPACE && in_space_array) ||
Packit Service 7770af
        (list->separator() == SASS_COMMA && in_comma_array)
Packit Service 7770af
    )) {
Packit Service 7770af
      append_string(")");
Packit Service 7770af
    }
Packit Service 7770af
Packit Service 7770af
  }
Packit Service 7770af
Packit Service 7770af
  void Inspect::operator()(Binary_Expression_Ptr expr)
Packit Service 7770af
  {
Packit Service 7770af
    expr->left()->perform(this);
Packit Service 7770af
    if ( in_media_block ||
Packit Service 7770af
         (output_style() == INSPECT) || (
Packit Service 7770af
          expr->op().ws_before
Packit Service 7770af
          && (!expr->is_interpolant())
Packit Service 7770af
          && (expr->is_left_interpolant() ||
Packit Service 7770af
              expr->is_right_interpolant())
Packit Service 7770af
Packit Service 7770af
    )) append_string(" ");
Packit Service 7770af
    switch (expr->optype()) {
Packit Service 7770af
      case Sass_OP::AND: append_string("&&";; break;
Packit Service 7770af
      case Sass_OP::OR:  append_string("||");  break;
Packit Service 7770af
      case Sass_OP::EQ:  append_string("==");  break;
Packit Service 7770af
      case Sass_OP::NEQ: append_string("!=");  break;
Packit Service 7770af
      case Sass_OP::GT:  append_string(">");   break;
Packit Service 7770af
      case Sass_OP::GTE: append_string(">=");  break;
Packit Service 7770af
      case Sass_OP::LT:  append_string("<");   break;
Packit Service 7770af
      case Sass_OP::LTE: append_string("<=");  break;
Packit Service 7770af
      case Sass_OP::ADD: append_string("+");   break;
Packit Service 7770af
      case Sass_OP::SUB: append_string("-");   break;
Packit Service 7770af
      case Sass_OP::MUL: append_string("*");   break;
Packit Service 7770af
      case Sass_OP::DIV: append_string("/"); break;
Packit Service 7770af
      case Sass_OP::MOD: append_string("%");   break;
Packit Service 7770af
      default: break; // shouldn't get here
Packit Service 7770af
    }
Packit Service 7770af
    if ( in_media_block ||
Packit Service 7770af
         (output_style() == INSPECT) || (
Packit Service 7770af
          expr->op().ws_after
Packit Service 7770af
          && (!expr->is_interpolant())
Packit Service 7770af
          && (expr->is_left_interpolant() ||
Packit Service 7770af
              expr->is_right_interpolant())
Packit Service 7770af
    )) append_string(" ");
Packit Service 7770af
    expr->right()->perform(this);
Packit Service 7770af
  }
Packit Service 7770af
Packit Service 7770af
  void Inspect::operator()(Unary_Expression_Ptr expr)
Packit Service 7770af
  {
Packit Service 7770af
    if (expr->optype() == Unary_Expression::PLUS)       append_string("+");
Packit Service 7770af
    else if (expr->optype() == Unary_Expression::SLASH) append_string("/");
Packit Service 7770af
    else                                                append_string("-");
Packit Service 7770af
    expr->operand()->perform(this);
Packit Service 7770af
  }
Packit Service 7770af
Packit Service 7770af
  void Inspect::operator()(Function_Call_Ptr call)
Packit Service 7770af
  {
Packit Service 7770af
    append_token(call->name(), call);
Packit Service 7770af
    call->arguments()->perform(this);
Packit Service 7770af
  }
Packit Service 7770af
Packit Service 7770af
  void Inspect::operator()(Function_Call_Schema_Ptr call)
Packit Service 7770af
  {
Packit Service 7770af
    call->name()->perform(this);
Packit Service 7770af
    call->arguments()->perform(this);
Packit Service 7770af
  }
Packit Service 7770af
Packit Service 7770af
  void Inspect::operator()(Variable_Ptr var)
Packit Service 7770af
  {
Packit Service 7770af
    append_token(var->name(), var);
Packit Service 7770af
  }
Packit Service 7770af
Packit Service 7770af
  void Inspect::operator()(Number_Ptr n)
Packit Service 7770af
  {
Packit Service 7770af
Packit Service 7770af
    std::string res;
Packit Service 7770af
Packit Service 7770af
    // check if the fractional part of the value equals to zero
Packit Service 7770af
    // neat trick from http://stackoverflow.com/a/1521682/1550314
Packit Service 7770af
    // double int_part; bool is_int = modf(value, &int_part) == 0.0;
Packit Service 7770af
Packit Service 7770af
    // this all cannot be done with one run only, since fixed
Packit Service 7770af
    // output differs from normal output and regular output
Packit Service 7770af
    // can contain scientific notation which we do not want!
Packit Service 7770af
Packit Service 7770af
    // first sample
Packit Service 7770af
    std::stringstream ss;
Packit Service 7770af
    ss.precision(12);
Packit Service 7770af
    ss << n->value();
Packit Service 7770af
Packit Service 7770af
    // check if we got scientific notation in result
Packit Service 7770af
    if (ss.str().find_first_of("e") != std::string::npos) {
Packit Service 7770af
      ss.clear(); ss.str(std::string());
Packit Service 7770af
      ss.precision(std::max(12, opt.precision));
Packit Service 7770af
      ss << std::fixed << n->value();
Packit Service 7770af
    }
Packit Service 7770af
Packit Service 7770af
    std::string tmp = ss.str();
Packit Service 7770af
    size_t pos_point = tmp.find_first_of(".,");
Packit Service 7770af
    size_t pos_fract = tmp.find_last_not_of("0");
Packit Service 7770af
    bool is_int = pos_point == pos_fract ||
Packit Service 7770af
                  pos_point == std::string::npos;
Packit Service 7770af
Packit Service 7770af
    // reset stream for another run
Packit Service 7770af
    ss.clear(); ss.str(std::string());
Packit Service 7770af
Packit Service 7770af
    // take a shortcut for integers
Packit Service 7770af
    if (is_int)
Packit Service 7770af
    {
Packit Service 7770af
      ss.precision(0);
Packit Service 7770af
      ss << std::fixed << n->value();
Packit Service 7770af
      res = std::string(ss.str());
Packit Service 7770af
    }
Packit Service 7770af
    // process floats
Packit Service 7770af
    else
Packit Service 7770af
    {
Packit Service 7770af
      // do we have have too much precision?
Packit Service 7770af
      if (pos_fract < opt.precision + pos_point)
Packit Service 7770af
      { ss.precision((int)(pos_fract - pos_point)); }
Packit Service 7770af
      else { ss.precision(opt.precision); }
Packit Service 7770af
      // round value again
Packit Service 7770af
      ss << std::fixed << n->value();
Packit Service 7770af
      res = std::string(ss.str());
Packit Service 7770af
      // maybe we truncated up to decimal point
Packit Service 7770af
      size_t pos = res.find_last_not_of("0");
Packit Service 7770af
      // handle case where we have a "0"
Packit Service 7770af
      if (pos == std::string::npos) {
Packit Service 7770af
        res = "0.0";
Packit Service 7770af
      } else {
Packit Service 7770af
        bool at_dec_point = res[pos] == '.' ||
Packit Service 7770af
                            res[pos] == ',';
Packit Service 7770af
        // don't leave a blank point
Packit Service 7770af
        if (at_dec_point) ++ pos;
Packit Service 7770af
        res.resize (pos + 1);
Packit Service 7770af
      }
Packit Service 7770af
    }
Packit Service 7770af
Packit Service 7770af
    // some final cosmetics
Packit Service 7770af
    if (res == "0.0") res = "0";
Packit Service 7770af
    else if (res == "") res = "0";
Packit Service 7770af
    else if (res == "-0") res = "0";
Packit Service 7770af
    else if (res == "-0.0") res = "0";
Packit Service 7770af
    else if (opt.output_style == COMPRESSED)
Packit Service 7770af
    {
Packit Service 7770af
      // check if handling negative nr
Packit Service 7770af
      size_t off = res[0] == '-' ? 1 : 0;
Packit Service 7770af
      // remove leading zero from floating point in compressed mode
Packit Service 7770af
      if (n->zero() && res[off] == '0' && res[off+1] == '.') res.erase(off, 1);
Packit Service 7770af
    }
Packit Service 7770af
Packit Service 7770af
    // add unit now
Packit Service 7770af
    res += n->unit();
Packit Service 7770af
Packit Service 7770af
    // output the final token
Packit Service 7770af
    append_token(res, n);
Packit Service 7770af
  }
Packit Service 7770af
Packit Service 7770af
  // helper function for serializing colors
Packit Service 7770af
  template <size_t range>
Packit Service 7770af
  static double cap_channel(double c) {
Packit Service 7770af
    if      (c > range) return range;
Packit Service 7770af
    else if (c < 0)     return 0;
Packit Service 7770af
    else                return c;
Packit Service 7770af
  }
Packit Service 7770af
Packit Service 7770af
  void Inspect::operator()(Color_Ptr c)
Packit Service 7770af
  {
Packit Service 7770af
    // output the final token
Packit Service 7770af
    std::stringstream ss;
Packit Service 7770af
Packit Service 7770af
    // original color name
Packit Service 7770af
    // maybe an unknown token
Packit Service 7770af
    std::string name = c->disp();
Packit Service 7770af
Packit Service 7770af
    // resolved color
Packit Service 7770af
    std::string res_name = name;
Packit Service 7770af
Packit Service 7770af
    double r = Sass::round(cap_channel<0xff>(c->r()), opt.precision);
Packit Service 7770af
    double g = Sass::round(cap_channel<0xff>(c->g()), opt.precision);
Packit Service 7770af
    double b = Sass::round(cap_channel<0xff>(c->b()), opt.precision);
Packit Service 7770af
    double a = cap_channel<1>   (c->a());
Packit Service 7770af
Packit Service 7770af
    // get color from given name (if one was given at all)
Packit Service 7770af
    if (name != "" && name_to_color(name)) {
Packit Service 7770af
      Color_Ptr_Const n = name_to_color(name);
Packit Service 7770af
      r = Sass::round(cap_channel<0xff>(n->r()), opt.precision);
Packit Service 7770af
      g = Sass::round(cap_channel<0xff>(n->g()), opt.precision);
Packit Service 7770af
      b = Sass::round(cap_channel<0xff>(n->b()), opt.precision);
Packit Service 7770af
      a = cap_channel<1>   (n->a());
Packit Service 7770af
    }
Packit Service 7770af
    // otherwise get the possible resolved color name
Packit Service 7770af
    else {
Packit Service 7770af
      double numval = r * 0x10000 + g * 0x100 + b;
Packit Service 7770af
      if (color_to_name(numval))
Packit Service 7770af
        res_name = color_to_name(numval);
Packit Service 7770af
    }
Packit Service 7770af
Packit Service 7770af
    std::stringstream hexlet;
Packit Service 7770af
    bool compressed = opt.output_style == COMPRESSED;
Packit Service 7770af
    hexlet << '#' << std::setw(1) << std::setfill('0');
Packit Service 7770af
    // create a short color hexlet if there is any need for it
Packit Service 7770af
    if (compressed && is_color_doublet(r, g, b) && a == 1) {
Packit Service 7770af
      hexlet << std::hex << std::setw(1) << (static_cast<unsigned long>(r) >> 4);
Packit Service 7770af
      hexlet << std::hex << std::setw(1) << (static_cast<unsigned long>(g) >> 4);
Packit Service 7770af
      hexlet << std::hex << std::setw(1) << (static_cast<unsigned long>(b) >> 4);
Packit Service 7770af
    } else {
Packit Service 7770af
      hexlet << std::hex << std::setw(2) << static_cast<unsigned long>(r);
Packit Service 7770af
      hexlet << std::hex << std::setw(2) << static_cast<unsigned long>(g);
Packit Service 7770af
      hexlet << std::hex << std::setw(2) << static_cast<unsigned long>(b);
Packit Service 7770af
    }
Packit Service 7770af
Packit Service 7770af
    if (compressed && !c->is_delayed()) name = "";
Packit Service 7770af
    if (opt.output_style == INSPECT && a >= 1) {
Packit Service 7770af
      append_token(hexlet.str(), c);
Packit Service 7770af
      return;
Packit Service 7770af
    }
Packit Service 7770af
Packit Service 7770af
    // retain the originally specified color definition if unchanged
Packit Service 7770af
    if (name != "") {
Packit Service 7770af
      ss << name;
Packit Service 7770af
    }
Packit Service 7770af
    else if (r == 0 && g == 0 && b == 0 && a == 0) {
Packit Service 7770af
        ss << "transparent";
Packit Service 7770af
    }
Packit Service 7770af
    else if (a >= 1) {
Packit Service 7770af
      if (res_name != "") {
Packit Service 7770af
        if (compressed && hexlet.str().size() < res_name.size()) {
Packit Service 7770af
          ss << hexlet.str();
Packit Service 7770af
        } else {
Packit Service 7770af
          ss << res_name;
Packit Service 7770af
        }
Packit Service 7770af
      }
Packit Service 7770af
      else {
Packit Service 7770af
        ss << hexlet.str();
Packit Service 7770af
      }
Packit Service 7770af
    }
Packit Service 7770af
    else {
Packit Service 7770af
      ss << "rgba(";
Packit Service 7770af
      ss << static_cast<unsigned long>(r) << ",";
Packit Service 7770af
      if (!compressed) ss << " ";
Packit Service 7770af
      ss << static_cast<unsigned long>(g) << ",";
Packit Service 7770af
      if (!compressed) ss << " ";
Packit Service 7770af
      ss << static_cast<unsigned long>(b) << ",";
Packit Service 7770af
      if (!compressed) ss << " ";
Packit Service 7770af
      ss << a << ')';
Packit Service 7770af
    }
Packit Service 7770af
Packit Service 7770af
    append_token(ss.str(), c);
Packit Service 7770af
Packit Service 7770af
  }
Packit Service 7770af
Packit Service 7770af
  void Inspect::operator()(Boolean_Ptr b)
Packit Service 7770af
  {
Packit Service 7770af
    // output the final token
Packit Service 7770af
    append_token(b->value() ? "true" : "false", b);
Packit Service 7770af
  }
Packit Service 7770af
Packit Service 7770af
  void Inspect::operator()(String_Schema_Ptr ss)
Packit Service 7770af
  {
Packit Service 7770af
    // Evaluation should turn these into String_Constants,
Packit Service 7770af
    // so this method is only for inspection purposes.
Packit Service 7770af
    for (size_t i = 0, L = ss->length(); i < L; ++i) {
Packit Service 7770af
      if ((*ss)[i]->is_interpolant()) append_string("#{");
Packit Service 7770af
      (*ss)[i]->perform(this);
Packit Service 7770af
      if ((*ss)[i]->is_interpolant()) append_string("}");
Packit Service 7770af
    }
Packit Service 7770af
  }
Packit Service 7770af
Packit Service 7770af
  void Inspect::operator()(String_Constant_Ptr s)
Packit Service 7770af
  {
Packit Service 7770af
    append_token(s->value(), s);
Packit Service 7770af
  }
Packit Service 7770af
Packit Service 7770af
  void Inspect::operator()(String_Quoted_Ptr s)
Packit Service 7770af
  {
Packit Service 7770af
    if (const char q = s->quote_mark()) {
Packit Service 7770af
      append_token(quote(s->value(), q), s);
Packit Service 7770af
    } else {
Packit Service 7770af
      append_token(s->value(), s);
Packit Service 7770af
    }
Packit Service 7770af
  }
Packit Service 7770af
Packit Service 7770af
  void Inspect::operator()(Custom_Error_Ptr e)
Packit Service 7770af
  {
Packit Service 7770af
    append_token(e->message(), e);
Packit Service 7770af
  }
Packit Service 7770af
Packit Service 7770af
  void Inspect::operator()(Custom_Warning_Ptr w)
Packit Service 7770af
  {
Packit Service 7770af
    append_token(w->message(), w);
Packit Service 7770af
  }
Packit Service 7770af
Packit Service 7770af
  void Inspect::operator()(Supports_Operator_Ptr so)
Packit Service 7770af
  {
Packit Service 7770af
Packit Service 7770af
    if (so->needs_parens(so->left())) append_string("(");
Packit Service 7770af
    so->left()->perform(this);
Packit Service 7770af
    if (so->needs_parens(so->left())) append_string(")");
Packit Service 7770af
Packit Service 7770af
    if (so->operand() == Supports_Operator::AND) {
Packit Service 7770af
      append_mandatory_space();
Packit Service 7770af
      append_token("and", so);
Packit Service 7770af
      append_mandatory_space();
Packit Service 7770af
    } else if (so->operand() == Supports_Operator::OR) {
Packit Service 7770af
      append_mandatory_space();
Packit Service 7770af
      append_token("or", so);
Packit Service 7770af
      append_mandatory_space();
Packit Service 7770af
    }
Packit Service 7770af
Packit Service 7770af
    if (so->needs_parens(so->right())) append_string("(");
Packit Service 7770af
    so->right()->perform(this);
Packit Service 7770af
    if (so->needs_parens(so->right())) append_string(")");
Packit Service 7770af
  }
Packit Service 7770af
Packit Service 7770af
  void Inspect::operator()(Supports_Negation_Ptr sn)
Packit Service 7770af
  {
Packit Service 7770af
    append_token("not", sn);
Packit Service 7770af
    append_mandatory_space();
Packit Service 7770af
    if (sn->needs_parens(sn->condition())) append_string("(");
Packit Service 7770af
    sn->condition()->perform(this);
Packit Service 7770af
    if (sn->needs_parens(sn->condition())) append_string(")");
Packit Service 7770af
  }
Packit Service 7770af
Packit Service 7770af
  void Inspect::operator()(Supports_Declaration_Ptr sd)
Packit Service 7770af
  {
Packit Service 7770af
    append_string("(");
Packit Service 7770af
    sd->feature()->perform(this);
Packit Service 7770af
    append_string(": ");
Packit Service 7770af
    sd->value()->perform(this);
Packit Service 7770af
    append_string(")");
Packit Service 7770af
  }
Packit Service 7770af
Packit Service 7770af
  void Inspect::operator()(Supports_Interpolation_Ptr sd)
Packit Service 7770af
  {
Packit Service 7770af
    sd->value()->perform(this);
Packit Service 7770af
  }
Packit Service 7770af
Packit Service 7770af
  void Inspect::operator()(Media_Query_Ptr mq)
Packit Service 7770af
  {
Packit Service 7770af
    size_t i = 0;
Packit Service 7770af
    if (mq->media_type()) {
Packit Service 7770af
      if      (mq->is_negated())    append_string("not ");
Packit Service 7770af
      else if (mq->is_restricted()) append_string("only ");
Packit Service 7770af
      mq->media_type()->perform(this);
Packit Service 7770af
    }
Packit Service 7770af
    else {
Packit Service 7770af
      (*mq)[i++]->perform(this);
Packit Service 7770af
    }
Packit Service 7770af
    for (size_t L = mq->length(); i < L; ++i) {
Packit Service 7770af
      append_string(" and ");
Packit Service 7770af
      (*mq)[i]->perform(this);
Packit Service 7770af
    }
Packit Service 7770af
  }
Packit Service 7770af
Packit Service 7770af
  void Inspect::operator()(Media_Query_Expression_Ptr mqe)
Packit Service 7770af
  {
Packit Service 7770af
    if (mqe->is_interpolated()) {
Packit Service 7770af
      mqe->feature()->perform(this);
Packit Service 7770af
    }
Packit Service 7770af
    else {
Packit Service 7770af
      append_string("(");
Packit Service 7770af
      mqe->feature()->perform(this);
Packit Service 7770af
      if (mqe->value()) {
Packit Service 7770af
        append_string(": "); // verified
Packit Service 7770af
        mqe->value()->perform(this);
Packit Service 7770af
      }
Packit Service 7770af
      append_string(")");
Packit Service 7770af
    }
Packit Service 7770af
  }
Packit Service 7770af
Packit Service 7770af
  void Inspect::operator()(At_Root_Query_Ptr ae)
Packit Service 7770af
  {
Packit Service 7770af
    append_string("(");
Packit Service 7770af
    ae->feature()->perform(this);
Packit Service 7770af
    if (ae->value()) {
Packit Service 7770af
      append_colon_separator();
Packit Service 7770af
      ae->value()->perform(this);
Packit Service 7770af
    }
Packit Service 7770af
    append_string(")");
Packit Service 7770af
  }
Packit Service 7770af
Packit Service 7770af
  void Inspect::operator()(Null_Ptr n)
Packit Service 7770af
  {
Packit Service 7770af
    // output the final token
Packit Service 7770af
    append_token("null", n);
Packit Service 7770af
  }
Packit Service 7770af
Packit Service 7770af
  // parameters and arguments
Packit Service 7770af
  void Inspect::operator()(Parameter_Ptr p)
Packit Service 7770af
  {
Packit Service 7770af
    append_token(p->name(), p);
Packit Service 7770af
    if (p->default_value()) {
Packit Service 7770af
      append_colon_separator();
Packit Service 7770af
      p->default_value()->perform(this);
Packit Service 7770af
    }
Packit Service 7770af
    else if (p->is_rest_parameter()) {
Packit Service 7770af
      append_string("...");
Packit Service 7770af
    }
Packit Service 7770af
  }
Packit Service 7770af
Packit Service 7770af
  void Inspect::operator()(Parameters_Ptr p)
Packit Service 7770af
  {
Packit Service 7770af
    append_string("(");
Packit Service 7770af
    if (!p->empty()) {
Packit Service 7770af
      (*p)[0]->perform(this);
Packit Service 7770af
      for (size_t i = 1, L = p->length(); i < L; ++i) {
Packit Service 7770af
        append_comma_separator();
Packit Service 7770af
        (*p)[i]->perform(this);
Packit Service 7770af
      }
Packit Service 7770af
    }
Packit Service 7770af
    append_string(")");
Packit Service 7770af
  }
Packit Service 7770af
Packit Service 7770af
  void Inspect::operator()(Argument_Ptr a)
Packit Service 7770af
  {
Packit Service 7770af
    if (!a->name().empty()) {
Packit Service 7770af
      append_token(a->name(), a);
Packit Service 7770af
      append_colon_separator();
Packit Service 7770af
    }
Packit Service 7770af
    if (!a->value()) return;
Packit Service 7770af
    // Special case: argument nulls can be ignored
Packit Service 7770af
    if (a->value()->concrete_type() == Expression::NULL_VAL) {
Packit Service 7770af
      return;
Packit Service 7770af
    }
Packit Service 7770af
    if (a->value()->concrete_type() == Expression::STRING) {
Packit Service 7770af
      String_Constant_Ptr s = Cast<String_Constant>(a->value());
Packit Service 7770af
      if (s) s->perform(this);
Packit Service 7770af
    } else {
Packit Service 7770af
      a->value()->perform(this);
Packit Service 7770af
    }
Packit Service 7770af
    if (a->is_rest_argument()) {
Packit Service 7770af
      append_string("...");
Packit Service 7770af
    }
Packit Service 7770af
  }
Packit Service 7770af
Packit Service 7770af
  void Inspect::operator()(Arguments_Ptr a)
Packit Service 7770af
  {
Packit Service 7770af
    append_string("(");
Packit Service 7770af
    if (!a->empty()) {
Packit Service 7770af
      (*a)[0]->perform(this);
Packit Service 7770af
      for (size_t i = 1, L = a->length(); i < L; ++i) {
Packit Service 7770af
        append_string(", "); // verified
Packit Service 7770af
        // Sass Bug? append_comma_separator();
Packit Service 7770af
        (*a)[i]->perform(this);
Packit Service 7770af
      }
Packit Service 7770af
    }
Packit Service 7770af
    append_string(")");
Packit Service 7770af
  }
Packit Service 7770af
Packit Service 7770af
  void Inspect::operator()(Selector_Schema_Ptr s)
Packit Service 7770af
  {
Packit Service 7770af
    s->contents()->perform(this);
Packit Service 7770af
  }
Packit Service 7770af
Packit Service 7770af
  void Inspect::operator()(Parent_Selector_Ptr p)
Packit Service 7770af
  {
Packit Service 7770af
    if (p->is_real_parent_ref()) append_string("&";;
Packit Service 7770af
  }
Packit Service 7770af
Packit Service 7770af
  void Inspect::operator()(Placeholder_Selector_Ptr s)
Packit Service 7770af
  {
Packit Service 7770af
    append_token(s->name(), s);
Packit Service 7770af
    if (s->has_line_break()) append_optional_linefeed();
Packit Service 7770af
    if (s->has_line_break()) append_indentation();
Packit Service 7770af
Packit Service 7770af
  }
Packit Service 7770af
Packit Service 7770af
  void Inspect::operator()(Element_Selector_Ptr s)
Packit Service 7770af
  {
Packit Service 7770af
    append_token(s->ns_name(), s);
Packit Service 7770af
  }
Packit Service 7770af
Packit Service 7770af
  void Inspect::operator()(Class_Selector_Ptr s)
Packit Service 7770af
  {
Packit Service 7770af
    append_token(s->ns_name(), s);
Packit Service 7770af
    if (s->has_line_break()) append_optional_linefeed();
Packit Service 7770af
    if (s->has_line_break()) append_indentation();
Packit Service 7770af
  }
Packit Service 7770af
Packit Service 7770af
  void Inspect::operator()(Id_Selector_Ptr s)
Packit Service 7770af
  {
Packit Service 7770af
    append_token(s->ns_name(), s);
Packit Service 7770af
    if (s->has_line_break()) append_optional_linefeed();
Packit Service 7770af
    if (s->has_line_break()) append_indentation();
Packit Service 7770af
  }
Packit Service 7770af
Packit Service 7770af
  void Inspect::operator()(Attribute_Selector_Ptr s)
Packit Service 7770af
  {
Packit Service 7770af
    append_string("[");
Packit Service 7770af
    add_open_mapping(s);
Packit Service 7770af
    append_token(s->ns_name(), s);
Packit Service 7770af
    if (!s->matcher().empty()) {
Packit Service 7770af
      append_string(s->matcher());
Packit Service 7770af
      if (s->value() && *s->value()) {
Packit Service 7770af
        s->value()->perform(this);
Packit Service 7770af
      }
Packit Service 7770af
    }
Packit Service 7770af
    add_close_mapping(s);
Packit Service 7770af
    append_string("]");
Packit Service 7770af
  }
Packit Service 7770af
Packit Service 7770af
  void Inspect::operator()(Pseudo_Selector_Ptr s)
Packit Service 7770af
  {
Packit Service 7770af
    append_token(s->ns_name(), s);
Packit Service 7770af
    if (s->expression()) {
Packit Service 7770af
      append_string("(");
Packit Service 7770af
      s->expression()->perform(this);
Packit Service 7770af
      append_string(")");
Packit Service 7770af
    }
Packit Service 7770af
  }
Packit Service 7770af
Packit Service 7770af
  // hotfix to avoid invalid nested `:not` selectors
Packit Service 7770af
  // probably the wrong place, but this should ultimatively
Packit Service 7770af
  // be fixed by implement superselector correctly for `:not`
Packit Service 7770af
  // first use of "find" (ATM only implemented for selectors)
Packit Service 7770af
  bool hasNotSelector(AST_Node_Obj obj) {
Packit Service 7770af
    if (Wrapped_Selector_Ptr w = Cast<Wrapped_Selector>(obj)) {
Packit Service 7770af
      return w->name() == ":not";
Packit Service 7770af
    }
Packit Service 7770af
    return false;
Packit Service 7770af
  }
Packit Service 7770af
Packit Service 7770af
  void Inspect::operator()(Wrapped_Selector_Ptr s)
Packit Service 7770af
  {
Packit Service 7770af
    if (!s->selector()->find(hasNotSelector)) {
Packit Service 7770af
      bool was = in_wrapped;
Packit Service 7770af
      in_wrapped = true;
Packit Service 7770af
      append_token(s->name(), s);
Packit Service 7770af
      append_string("(");
Packit Service 7770af
      bool was_comma_array = in_comma_array;
Packit Service 7770af
      in_comma_array = false;
Packit Service 7770af
      s->selector()->perform(this);
Packit Service 7770af
      in_comma_array = was_comma_array;
Packit Service 7770af
      append_string(")");
Packit Service 7770af
      in_wrapped = was;
Packit Service 7770af
    }
Packit Service 7770af
  }
Packit Service 7770af
Packit Service 7770af
  void Inspect::operator()(Compound_Selector_Ptr s)
Packit Service 7770af
  {
Packit Service 7770af
    for (size_t i = 0, L = s->length(); i < L; ++i) {
Packit Service 7770af
      (*s)[i]->perform(this);
Packit Service 7770af
    }
Packit Service 7770af
    if (s->has_line_break()) {
Packit Service 7770af
      if (output_style() != COMPACT) {
Packit Service 7770af
        append_optional_linefeed();
Packit Service 7770af
      }
Packit Service 7770af
    }
Packit Service 7770af
  }
Packit Service 7770af
Packit Service 7770af
  void Inspect::operator()(Complex_Selector_Ptr c)
Packit Service 7770af
  {
Packit Service 7770af
    Compound_Selector_Obj      head = c->head();
Packit Service 7770af
    Complex_Selector_Obj            tail = c->tail();
Packit Service 7770af
    Complex_Selector::Combinator comb = c->combinator();
Packit Service 7770af
Packit Service 7770af
    if (comb == Complex_Selector::ANCESTOR_OF && (!head || head->empty())) {
Packit Service 7770af
      if (tail) tail->perform(this);
Packit Service 7770af
      return;
Packit Service 7770af
    }
Packit Service 7770af
Packit Service 7770af
    if (c->has_line_feed()) {
Packit Service 7770af
      if (!(c->has_parent_ref())) {
Packit Service 7770af
        append_optional_linefeed();
Packit Service 7770af
        append_indentation();
Packit Service 7770af
      }
Packit Service 7770af
    }
Packit Service 7770af
Packit Service 7770af
    if (head && head->length() != 0) head->perform(this);
Packit Service 7770af
    bool is_empty = !head || head->length() == 0 || head->is_empty_reference();
Packit Service 7770af
    bool is_tail = head && !head->is_empty_reference() && tail;
Packit Service 7770af
    if (output_style() == COMPRESSED && comb != Complex_Selector::ANCESTOR_OF) scheduled_space = 0;
Packit Service 7770af
Packit Service 7770af
    switch (comb) {
Packit Service 7770af
      case Complex_Selector::ANCESTOR_OF:
Packit Service 7770af
        if (is_tail) append_mandatory_space();
Packit Service 7770af
      break;
Packit Service 7770af
      case Complex_Selector::PARENT_OF:
Packit Service 7770af
        append_optional_space();
Packit Service 7770af
        append_string(">");
Packit Service 7770af
        append_optional_space();
Packit Service 7770af
      break;
Packit Service 7770af
      case Complex_Selector::ADJACENT_TO:
Packit Service 7770af
        append_optional_space();
Packit Service 7770af
        append_string("+");
Packit Service 7770af
        append_optional_space();
Packit Service 7770af
      break;
Packit Service 7770af
      case Complex_Selector::REFERENCE:
Packit Service 7770af
        append_mandatory_space();
Packit Service 7770af
        append_string("/");
Packit Service 7770af
        c->reference()->perform(this);
Packit Service 7770af
        append_string("/");
Packit Service 7770af
        append_mandatory_space();
Packit Service 7770af
      break;
Packit Service 7770af
      case Complex_Selector::PRECEDES:
Packit Service 7770af
        if (is_empty) append_optional_space();
Packit Service 7770af
        else append_mandatory_space();
Packit Service 7770af
        append_string("~");
Packit Service 7770af
        if (tail) append_mandatory_space();
Packit Service 7770af
        else append_optional_space();
Packit Service 7770af
      break;
Packit Service 7770af
      default: break;
Packit Service 7770af
    }
Packit Service 7770af
    if (tail && comb != Complex_Selector::ANCESTOR_OF) {
Packit Service 7770af
      if (c->has_line_break()) append_optional_linefeed();
Packit Service 7770af
    }
Packit Service 7770af
    if (tail) tail->perform(this);
Packit Service 7770af
    if (!tail && c->has_line_break()) {
Packit Service 7770af
      if (output_style() == COMPACT) {
Packit Service 7770af
        append_mandatory_space();
Packit Service 7770af
      }
Packit Service 7770af
    }
Packit Service 7770af
  }
Packit Service 7770af
Packit Service 7770af
  void Inspect::operator()(Selector_List_Ptr g)
Packit Service 7770af
  {
Packit Service 7770af
Packit Service 7770af
    if (g->empty()) {
Packit Service 7770af
      if (output_style() == TO_SASS) {
Packit Service 7770af
        append_token("()", g);
Packit Service 7770af
      }
Packit Service 7770af
      return;
Packit Service 7770af
    }
Packit Service 7770af
Packit Service 7770af
Packit Service 7770af
    bool was_comma_array = in_comma_array;
Packit Service 7770af
    // probably ruby sass eqivalent of element_needs_parens
Packit Service 7770af
    if (output_style() == TO_SASS && g->length() == 1 &&
Packit Service 7770af
      (!Cast<List>((*g)[0]) &&
Packit Service 7770af
       !Cast<Selector_List>((*g)[0]))) {
Packit Service 7770af
      append_string("(");
Packit Service 7770af
    }
Packit Service 7770af
    else if (!in_declaration && in_comma_array) {
Packit Service 7770af
      append_string("(");
Packit Service 7770af
    }
Packit Service 7770af
Packit Service 7770af
    if (in_declaration) in_comma_array = true;
Packit Service 7770af
Packit Service 7770af
    for (size_t i = 0, L = g->length(); i < L; ++i) {
Packit Service 7770af
      if (!in_wrapped && i == 0) append_indentation();
Packit Service 7770af
      if ((*g)[i] == 0) continue;
Packit Service 7770af
      schedule_mapping(g->at(i)->last());
Packit Service 7770af
      // add_open_mapping((*g)[i]->last());
Packit Service 7770af
      (*g)[i]->perform(this);
Packit Service 7770af
      // add_close_mapping((*g)[i]->last());
Packit Service 7770af
      if (i < L - 1) {
Packit Service 7770af
        scheduled_space = 0;
Packit Service 7770af
        append_comma_separator();
Packit Service 7770af
      }
Packit Service 7770af
    }
Packit Service 7770af
Packit Service 7770af
    in_comma_array = was_comma_array;
Packit Service 7770af
    // probably ruby sass eqivalent of element_needs_parens
Packit Service 7770af
    if (output_style() == TO_SASS && g->length() == 1 &&
Packit Service 7770af
      (!Cast<List>((*g)[0]) &&
Packit Service 7770af
       !Cast<Selector_List>((*g)[0]))) {
Packit Service 7770af
      append_string(",)");
Packit Service 7770af
    }
Packit Service 7770af
    else if (!in_declaration && in_comma_array) {
Packit Service 7770af
      append_string(")");
Packit Service 7770af
    }
Packit Service 7770af
Packit Service 7770af
  }
Packit Service 7770af
Packit Service 7770af
  void Inspect::fallback_impl(AST_Node_Ptr n)
Packit Service 7770af
  {
Packit Service 7770af
  }
Packit Service 7770af
Packit Service 7770af
}